commit 40d9b54

Michael Forney  ·  2014-01-22 03:11:55 +0000 UTC
parent 08ad563
Style
21 files changed,  +74, -68
+13, -10
 1@@ -36,11 +36,22 @@ struct binding
 2     void * data;
 3 };
 4 
 5+static bool handle_key(struct swc_keyboard * keyboard, uint32_t time,
 6+                       uint32_t key, uint32_t state);
 7+
 8+static struct swc_keyboard_handler binding_handler = {
 9+    .key = &handle_key,
10+};
11+
12 static struct
13 {
14     struct wl_array keys;
15 } bindings;
16 
17+const struct swc_bindings swc_bindings = {
18+    .keyboard_handler = &binding_handler
19+};
20+
21 static bool handle_keysym(xkb_keysym_t keysym,
22                           uint32_t modifiers, uint32_t time)
23 {
24@@ -60,8 +71,8 @@ static bool handle_keysym(xkb_keysym_t keysym,
25     return false;
26 }
27 
28-static bool handle_key(struct swc_keyboard * keyboard, uint32_t time,
29-                       uint32_t key, uint32_t state)
30+bool handle_key(struct swc_keyboard * keyboard, uint32_t time,
31+                uint32_t key, uint32_t state)
32 {
33     if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
34     {
35@@ -86,14 +97,6 @@ static bool handle_key(struct swc_keyboard * keyboard, uint32_t time,
36     return false;
37 }
38 
39-static struct swc_keyboard_handler binding_handler = {
40-    .key = &handle_key,
41-};
42-
43-const struct swc_bindings_global bindings_global = {
44-    .keyboard_handler = &binding_handler
45-};
46-
47 bool swc_bindings_initialize()
48 {
49     wl_array_init(&bindings.keys);
+1, -1
1@@ -26,7 +26,7 @@
2 
3 #include <stdbool.h>
4 
5-struct swc_bindings_global
6+struct swc_bindings
7 {
8     struct swc_keyboard_handler * keyboard_handler;
9 };
+6, -4
 1@@ -88,6 +88,11 @@ static void handle_focus(struct swc_pointer * pointer);
 2 static bool handle_motion(struct swc_pointer * pointer, uint32_t time);
 3 static void perform_update(void * data);
 4 
 5+static const struct swc_pointer_handler pointer_handler = {
 6+    .focus = &handle_focus,
 7+    .motion = &handle_motion
 8+};
 9+
10 static struct
11 {
12     struct wl_list views;
13@@ -107,10 +112,7 @@ static struct
14 } compositor;
15 
16 const struct swc_compositor swc_compositor = {
17-    .pointer_handler = {
18-        .focus = &handle_focus,
19-        .motion = &handle_motion
20-    }
21+    .pointer_handler = &pointer_handler
22 };
23 
24 static void buffer_destroy(void * data)
+4, -2
 1@@ -24,11 +24,13 @@
 2 #ifndef SWC_COMPOSITOR_H
 3 #define SWC_COMPOSITOR_H
 4 
 5-#include "pointer.h"
 6+#include <stdbool.h>
 7+
 8+struct swc_surface;
 9 
10 struct swc_compositor
11 {
12-    struct swc_pointer_handler pointer_handler;
13+    const struct swc_pointer_handler * pointer_handler;
14 };
15 
16 bool swc_compositor_initialize();
+1, -1
1@@ -85,7 +85,7 @@ bool swc_data_device_initialize(struct swc_data_device * data_device)
2     return true;
3 }
4 
5-void swc_data_device_finish(struct swc_data_device * data_device)
6+void swc_data_device_finalize(struct swc_data_device * data_device)
7 {
8     struct wl_resource * resource, * tmp;
9 
+1, -1
1@@ -45,7 +45,7 @@ struct swc_data_device
2 };
3 
4 bool swc_data_device_initialize(struct swc_data_device * data_device);
5-void swc_data_device_finish(struct swc_data_device * data_device);
6+void swc_data_device_finalize(struct swc_data_device * data_device);
7 
8 void swc_data_device_bind(struct swc_data_device * data_device,
9                           struct wl_client * client, uint32_t id);
+1, -1
1@@ -43,7 +43,7 @@
2 #include <wayland-server.h>
3 #include "protocol/wayland-drm-server-protocol.h"
4 
5-struct swc_drm drm_global;
6+struct swc_drm swc_drm;
7 
8 static struct
9 {
+1, -1
1@@ -80,7 +80,7 @@ bool swc_input_focus_initialize(struct swc_input_focus * input_focus,
2     return true;
3 }
4 
5-void swc_input_focus_finish(struct swc_input_focus * input_focus)
6+void swc_input_focus_finalize(struct swc_input_focus * input_focus)
7 {
8     /* XXX: Destroy resources? */
9 }
+1, -1
1@@ -62,7 +62,7 @@ struct swc_input_focus
2 bool swc_input_focus_initialize(struct swc_input_focus * input_focus,
3                                 struct swc_input_focus_handler * input_handler);
4 
5-void swc_input_focus_finish(struct swc_input_focus * input_focus);
6+void swc_input_focus_finalize(struct swc_input_focus * input_focus);
7 
8 void swc_input_focus_add_resource(struct swc_input_focus * input_focus,
9                                   struct wl_resource * resource);
+2, -2
 1@@ -35,8 +35,8 @@ struct swc
 2     struct udev * udev;
 3 
 4     struct swc_launch * const launch;
 5-    const struct swc_seat_global * const seat;
 6-    const struct swc_bindings_global * const bindings;
 7+    const struct swc_seat * const seat;
 8+    const struct swc_bindings * const bindings;
 9     struct wl_list screens;
10     const struct swc_compositor * const compositor;
11     struct swc_shm * const shm;
+4, -4
 1@@ -128,16 +128,16 @@ bool swc_keyboard_initialize(struct swc_keyboard * keyboard)
 2     return true;
 3 
 4   error1:
 5-    swc_xkb_finish(&keyboard->xkb);
 6+    swc_xkb_finalize(&keyboard->xkb);
 7   error0:
 8     return false;
 9 }
10 
11-void swc_keyboard_finish(struct swc_keyboard * keyboard)
12+void swc_keyboard_finalize(struct swc_keyboard * keyboard)
13 {
14     wl_array_release(&keyboard->client_handler.keys);
15-    swc_input_focus_finish(&keyboard->focus);
16-    swc_xkb_finish(&keyboard->xkb);
17+    swc_input_focus_finalize(&keyboard->focus);
18+    swc_xkb_finalize(&keyboard->xkb);
19 }
20 
21 /**
+1, -1
1@@ -66,7 +66,7 @@ struct swc_keyboard
2 };
3 
4 bool swc_keyboard_initialize(struct swc_keyboard * keyboard);
5-void swc_keyboard_finish(struct swc_keyboard * keyboard);
6+void swc_keyboard_finalize(struct swc_keyboard * keyboard);
7 void swc_keyboard_set_focus(struct swc_keyboard * keyboard,
8                             struct swc_surface * surface);
9 struct wl_resource * swc_keyboard_bind(struct swc_keyboard * keyboard,
+2, -2
 1@@ -48,8 +48,8 @@ static void bind_output(struct wl_client * client, void * data,
 2         if (swc_mode_equal(&screen->planes.framebuffer.mode, mode))
 3             flags |= WL_OUTPUT_MODE_CURRENT;
 4 
 5-        wl_output_send_mode(resource, flags, mode->width, mode->height,
 6-                            mode->refresh);
 7+        wl_output_send_mode(resource, flags,
 8+                            mode->width, mode->height, mode->refresh);
 9     }
10 
11     if (version >= 2)
+2, -2
 1@@ -180,9 +180,9 @@ bool swc_pointer_initialize(struct swc_pointer * pointer)
 2     return true;
 3 }
 4 
 5-void swc_pointer_finish(struct swc_pointer * pointer)
 6+void swc_pointer_finalize(struct swc_pointer * pointer)
 7 {
 8-    swc_input_focus_finish(&pointer->focus);
 9+    swc_input_focus_finalize(&pointer->focus);
10     pixman_region32_fini(&pointer->region);
11 }
12 
+1, -1
1@@ -47,7 +47,7 @@ struct swc_pointer
2 };
3 
4 bool swc_pointer_initialize(struct swc_pointer * pointer);
5-void swc_pointer_finish(struct swc_pointer * pointer);
6+void swc_pointer_finalize(struct swc_pointer * pointer);
7 void swc_pointer_set_focus(struct swc_pointer * pointer,
8                            struct swc_surface * surface);
9 void swc_pointer_set_region(struct swc_pointer * pointer,
+5, -5
 1@@ -50,7 +50,7 @@ static struct
 2     struct wl_list devices;
 3 } seat;
 4 
 5-const struct swc_seat_global seat_global = {
 6+const struct swc_seat swc_seat = {
 7     .pointer = &seat.pointer,
 8     .keyboard = &seat.keyboard,
 9     .data_device = &seat.data_device
10@@ -298,9 +298,9 @@ bool swc_seat_initialize(const char * seat_name)
11     return true;
12 
13   error4:
14-    swc_keyboard_finish(&seat.keyboard);
15+    swc_keyboard_finalize(&seat.keyboard);
16   error3:
17-    swc_data_device_finish(&seat.data_device);
18+    swc_data_device_finalize(&seat.data_device);
19   error2:
20     wl_global_destroy(seat.global);
21   error1:
22@@ -313,8 +313,8 @@ void swc_seat_finalize()
23 {
24     struct swc_evdev_device * device, * tmp;
25 
26-    swc_pointer_finish(&seat.pointer);
27-    swc_keyboard_finish(&seat.keyboard);
28+    swc_pointer_finalize(&seat.pointer);
29+    swc_keyboard_finalize(&seat.keyboard);
30 
31     wl_list_for_each_safe(device, tmp, &seat.devices, link)
32         swc_evdev_device_destroy(device);
+1, -1
1@@ -26,7 +26,7 @@
2 
3 #include <stdbool.h>
4 
5-struct swc_seat_global
6+struct swc_seat
7 {
8     struct swc_pointer * pointer;
9     struct swc_keyboard * keyboard;
+1, -1
1@@ -28,7 +28,7 @@
2 #include <wld/wld.h>
3 #include <wld/pixman.h>
4 
5-struct swc_shm shm_global;
6+struct swc_shm swc_shm;
7 
8 bool swc_shm_initialize()
9 {
+9, -9
 1@@ -43,19 +43,19 @@
 2 #include <libudev.h>
 3 
 4 extern struct swc_launch swc_launch;
 5-extern const struct swc_seat_global seat_global;
 6-extern const struct swc_bindings_global bindings_global;
 7+extern const struct swc_seat swc_seat;
 8+extern const struct swc_bindings swc_bindings;
 9 extern const struct swc_compositor swc_compositor;
10-extern struct swc_drm drm_global;
11-extern struct swc_shm shm_global;
12+extern struct swc_drm swc_drm;
13+extern struct swc_shm swc_shm;
14 
15 struct swc swc = {
16     .launch = &swc_launch,
17-    .seat = &seat_global,
18-    .bindings = &bindings_global,
19+    .seat = &swc_seat,
20+    .bindings = &swc_bindings,
21     .compositor = &swc_compositor,
22-    .drm = &drm_global,
23-    .shm = &shm_global
24+    .drm = &swc_drm,
25+    .shm = &swc_shm
26 };
27 
28 static void setup_compositor()
29@@ -66,7 +66,7 @@ static void setup_compositor()
30 
31     wl_list_insert(&swc.seat->keyboard->handlers,
32                    &swc.bindings->keyboard_handler->link);
33-    swc.seat->pointer->handler = &swc.compositor->pointer_handler;
34+    swc.seat->pointer->handler = swc.compositor->pointer_handler;
35     wl_signal_add(&swc.seat->pointer->focus.event_signal,
36                   swc_window_enter_listener);
37 
+16, -16
  1@@ -21,7 +21,7 @@ bool swc_xkb_initialize(struct swc_xkb * xkb)
  2     if (!xkb->context)
  3     {
  4         printf("could not create XKB context\n");
  5-        goto error_base;
  6+        goto error0;
  7     }
  8 
  9     xkb->keymap.map = xkb_keymap_new_from_names(xkb->context, &rule_names, 0);
 10@@ -29,7 +29,7 @@ bool swc_xkb_initialize(struct swc_xkb * xkb)
 11     if (!xkb->keymap.map)
 12     {
 13         printf("could not create XKB keymap\n");
 14-        goto error_context;
 15+        goto error1;
 16     }
 17 
 18     xkb->state = xkb_state_new(xkb->keymap.map);
 19@@ -37,28 +37,28 @@ bool swc_xkb_initialize(struct swc_xkb * xkb)
 20     if (!xkb->state)
 21     {
 22         printf("could not create XKB state\n");
 23-        goto error_keymap;
 24+        goto error2;
 25     }
 26 
 27     if (!swc_xkb_update_keymap(xkb))
 28     {
 29         printf("could not update XKB keymap\n");
 30-        goto error_state;
 31+        goto error3;
 32     }
 33 
 34     return true;
 35 
 36-  error_state:
 37+  error3:
 38     xkb_state_unref(xkb->state);
 39-  error_keymap:
 40+  error2:
 41     xkb_keymap_unref(xkb->keymap.map);
 42-  error_context:
 43+  error1:
 44     xkb_context_unref(xkb->context);
 45-  error_base:
 46+  error0:
 47     return false;
 48 }
 49 
 50-void swc_xkb_finish(struct swc_xkb * xkb)
 51+void swc_xkb_finalize(struct swc_xkb * xkb)
 52 {
 53     munmap(xkb->keymap.area, xkb->keymap.size);
 54     close(xkb->keymap.fd);
 55@@ -97,7 +97,7 @@ bool swc_xkb_update_keymap(struct swc_xkb * xkb)
 56         if (!keymap_string)
 57         {
 58             printf("could not get XKB keymap as a string\n");
 59-            goto error_base;
 60+            goto error0;
 61         }
 62 
 63         sprintf(keymap_path, "%s/%s", keymap_directory, keymap_file_template);
 64@@ -108,7 +108,7 @@ bool swc_xkb_update_keymap(struct swc_xkb * xkb)
 65         if (xkb->keymap.fd == -1)
 66         {
 67             printf("could not create XKB keymap file\n");
 68-            goto error_string;
 69+            goto error1;
 70         }
 71 
 72         unlink(keymap_path);
 73@@ -116,7 +116,7 @@ bool swc_xkb_update_keymap(struct swc_xkb * xkb)
 74         if (posix_fallocate(xkb->keymap.fd, 0, xkb->keymap.size) != 0)
 75         {
 76             printf("could not resize XKB keymap file\n");
 77-            goto error_fd;
 78+            goto error2;
 79         }
 80 
 81         xkb->keymap.area = mmap(NULL, xkb->keymap.size, PROT_READ | PROT_WRITE,
 82@@ -125,7 +125,7 @@ bool swc_xkb_update_keymap(struct swc_xkb * xkb)
 83         if (xkb->keymap.area == MAP_FAILED)
 84         {
 85             printf("could not mmap XKB keymap string\n");
 86-            goto error_fd;
 87+            goto error2;
 88         }
 89 
 90         strcpy(xkb->keymap.area, keymap_string);
 91@@ -135,11 +135,11 @@ bool swc_xkb_update_keymap(struct swc_xkb * xkb)
 92 
 93     return true;
 94 
 95-  error_fd:
 96+  error2:
 97     close(xkb->keymap.fd);
 98-  error_string:
 99+  error1:
100     free(keymap_string);
101-  error_base:
102+  error0:
103     return false;
104 }
105 
+1, -2
 1@@ -27,8 +27,7 @@ struct swc_xkb
 2 };
 3 
 4 bool swc_xkb_initialize(struct swc_xkb * xkb);
 5-
 6-void swc_xkb_finish(struct swc_xkb * xkb);
 7+void swc_xkb_finalize(struct swc_xkb * xkb);
 8 
 9 bool swc_xkb_update_keymap(struct swc_xkb * xkb);
10