commit 195c797

Michael Forney  ·  2014-01-30 10:11:29 +0000 UTC
parent 1b3cdbc
window: Reserve swc_ for external API
6 files changed,  +80, -87
+9, -12
 1@@ -33,7 +33,7 @@
 2 
 3 struct swc_shell_surface
 4 {
 5-    struct swc_window_internal window;
 6+    struct window window;
 7 
 8     struct wl_resource * resource;
 9     struct wl_listener surface_destroy_listener;
10@@ -75,8 +75,7 @@ static void set_toplevel(struct wl_client * client,
11         return;
12 
13     shell_surface->type = SHELL_SURFACE_TYPE_TOPLEVEL;
14-    swc_window_set_state(&shell_surface->window.base,
15-                         SWC_WINDOW_STATE_TOPLEVEL);
16+    window_set_state(&shell_surface->window, SWC_WINDOW_STATE_TOPLEVEL);
17 }
18 
19 static void set_transient(struct wl_client * client,
20@@ -132,7 +131,7 @@ static void set_title(struct wl_client * client, struct wl_resource * resource,
21     struct swc_shell_surface * shell_surface
22         = wl_resource_get_user_data(resource);
23 
24-    swc_window_set_title(&shell_surface->window.base, title, -1);
25+    window_set_title(&shell_surface->window, title, -1);
26 }
27 
28 static void set_class(struct wl_client * client, struct wl_resource * resource,
29@@ -141,7 +140,7 @@ static void set_class(struct wl_client * client, struct wl_resource * resource,
30     struct swc_shell_surface * shell_surface
31         = wl_resource_get_user_data(resource);
32 
33-    swc_window_set_class(&shell_surface->window.base, class);
34+    window_set_class(&shell_surface->window, class);
35 }
36 
37 static const struct wl_shell_surface_interface shell_surface_implementation = {
38@@ -157,18 +156,18 @@ static const struct wl_shell_surface_interface shell_surface_implementation = {
39     .set_class = &set_class
40 };
41 
42-static void configure(struct swc_window * window,
43+static void configure(struct window * window,
44                       const struct swc_rectangle * geometry)
45 {
46     struct swc_shell_surface * shell_surface
47-        = CONTAINER_OF(window, typeof(*shell_surface), window.base);
48+        = CONTAINER_OF(window, typeof(*shell_surface), window);
49 
50     wl_shell_surface_send_configure(shell_surface->resource,
51                                     WL_SHELL_SURFACE_RESIZE_NONE,
52                                     geometry->width, geometry->height);
53 }
54 
55-static const struct swc_window_impl shell_window_impl = {
56+static const struct window_impl shell_window_impl = {
57     .configure = &configure
58 };
59 
60@@ -185,7 +184,7 @@ static void destroy_shell_surface(struct wl_resource * resource)
61     struct swc_shell_surface * shell_surface
62         = wl_resource_get_user_data(resource);
63 
64-    swc_window_finalize(&shell_surface->window.base);
65+    window_finalize(&shell_surface->window);
66     free(shell_surface);
67 }
68 
69@@ -199,14 +198,12 @@ struct swc_shell_surface * swc_shell_surface_new
70     if (!shell_surface)
71         goto error0;
72 
73+    window_initialize(&shell_surface->window, &shell_window_impl, surface);
74     shell_surface->type = SHELL_SURFACE_TYPE_UNSPECIFIED;
75     shell_surface->surface_destroy_listener.notify = &handle_surface_destroy;
76     wl_resource_add_destroy_listener(surface->resource,
77                                      &shell_surface->surface_destroy_listener);
78 
79-    swc_window_initialize(&shell_surface->window.base,
80-                          &shell_window_impl, surface);
81-
82     shell_surface->resource = wl_resource_create
83         (client, &wl_shell_surface_interface, 1, id);
84 
+1, -1
1@@ -67,7 +67,7 @@ struct swc_surface
2         int32_t x, y;
3     } pending;
4 
5-    struct swc_window * window;
6+    struct window * window;
7     struct swc_view * view;
8     struct wl_listener view_listener;
9 
+1, -1
1@@ -67,7 +67,7 @@ static void setup_compositor()
2                    &swc.bindings->keyboard_handler->link);
3     swc.seat->pointer->handler = swc.compositor->pointer_handler;
4     wl_signal_add(&swc.seat->pointer->focus.event_signal,
5-                  swc_window_enter_listener);
6+                  &window_enter_listener);
7 
8     /* Calculate pointer region */
9     pixman_region32_init(&pointer_region);
+41, -42
  1@@ -34,13 +34,13 @@
  2 #include <stdlib.h>
  3 #include <string.h>
  4 
  5-#define INTERNAL(window) ((struct swc_window_internal *) (window))
  6+#define INTERNAL(w) ((struct window *) (w))
  7 
  8 static void handle_window_enter(struct wl_listener * listener, void * data)
  9 {
 10     struct swc_event * event = data;
 11     struct swc_input_focus_event_data * event_data = event->data;
 12-    struct swc_window * window;
 13+    struct window * window;
 14 
 15     if (event->type != SWC_INPUT_FOCUS_EVENT_CHANGED)
 16         return;
 17@@ -48,13 +48,12 @@ static void handle_window_enter(struct wl_listener * listener, void * data)
 18     if (!event_data->new || !(window = event_data->new->window))
 19         return;
 20 
 21-    swc_send_event(&window->event_signal, SWC_WINDOW_ENTERED, NULL);
 22+    swc_send_event(&window->base.event_signal, SWC_WINDOW_ENTERED, NULL);
 23 }
 24 
 25-static struct wl_listener window_enter_listener = {
 26+struct wl_listener window_enter_listener = {
 27     .notify = &handle_window_enter
 28 };
 29-struct wl_listener * swc_window_enter_listener = &window_enter_listener;
 30 
 31 EXPORT
 32 void swc_window_show(struct swc_window * window)
 33@@ -69,8 +68,9 @@ void swc_window_hide(struct swc_window * window)
 34 }
 35 
 36 EXPORT
 37-void swc_window_focus(struct swc_window * window)
 38+void swc_window_focus(struct swc_window * base)
 39 {
 40+    struct window * window = INTERNAL(base);
 41     struct swc_surface * new_focus = window ? INTERNAL(window)->surface : NULL,
 42                        * old_focus = swc.seat->keyboard->focus.surface;
 43 
 44@@ -78,27 +78,28 @@ void swc_window_focus(struct swc_window * window)
 45      * focus to either NULL, or a window with a different implementation, set
 46      * the focus of the previous focus window's implementation to NULL. */
 47     if (old_focus && old_focus->window
 48-        && !(window && INTERNAL(window)->impl
 49-                    == INTERNAL(old_focus->window)->impl)
 50+        && !(window && window->impl == INTERNAL(old_focus->window)->impl)
 51         && INTERNAL(old_focus->window)->impl->focus)
 52     {
 53         INTERNAL(old_focus->window)->impl->focus(NULL);
 54     }
 55 
 56-    if (window && INTERNAL(window)->impl->focus)
 57-        INTERNAL(window)->impl->focus(window);
 58+    if (window && window->impl->focus)
 59+        window->impl->focus(window);
 60 
 61     swc_keyboard_set_focus(swc.seat->keyboard, new_focus);
 62 }
 63 
 64 EXPORT
 65-void swc_window_set_geometry(struct swc_window * window,
 66+void swc_window_set_geometry(struct swc_window * base,
 67                              const struct swc_rectangle * geometry)
 68 {
 69-    if (INTERNAL(window)->impl->configure)
 70-        INTERNAL(window)->impl->configure(window, geometry);
 71+    struct window * window = INTERNAL(base);
 72 
 73-    swc_view_move(INTERNAL(window)->surface->view, geometry->x, geometry->y);
 74+    if (window->impl->configure)
 75+        window->impl->configure(window, geometry);
 76+
 77+    swc_view_move(window->surface->view, geometry->x, geometry->y);
 78 }
 79 
 80 EXPORT
 81@@ -111,56 +112,54 @@ void swc_window_set_border(struct swc_window * window,
 82     swc_compositor_surface_set_border_width(surface, border_width);
 83 }
 84 
 85-bool swc_window_initialize(struct swc_window * window,
 86-                           const struct swc_window_impl * impl,
 87-                           struct swc_surface * surface)
 88+bool window_initialize(struct window * window, const struct window_impl * impl,
 89+                       struct swc_surface * surface)
 90 {
 91     DEBUG("Initializing window, %p\n", window);
 92 
 93-    window->title = NULL;
 94-    window->class = NULL;
 95-    window->state = SWC_WINDOW_STATE_WITHDRAWN;
 96-    wl_signal_init(&window->event_signal);
 97-    INTERNAL(window)->surface = surface;
 98-    INTERNAL(window)->impl = impl;
 99+    window->base.title = NULL;
100+    window->base.class = NULL;
101+    window->base.state = SWC_WINDOW_STATE_WITHDRAWN;
102+    wl_signal_init(&window->base.event_signal);
103+    window->surface = surface;
104+    window->impl = impl;
105 
106     surface->window = window;
107     swc_compositor_add_surface(surface);
108 
109-    swc.manager->new_window(window);
110+    swc.manager->new_window(&window->base);
111 
112     return true;
113 }
114 
115-void swc_window_finalize(struct swc_window * window)
116+void window_finalize(struct window * window)
117 {
118     DEBUG("Finalizing window, %p\n", window);
119 
120-    swc_send_event(&window->event_signal, SWC_WINDOW_DESTROYED, NULL);
121-    swc_compositor_remove_surface(INTERNAL(window)->surface);
122-    INTERNAL(window)->surface->window = NULL;
123-    free(window->title);
124-    free(window->class);
125+    swc_send_event(&window->base.event_signal, SWC_WINDOW_DESTROYED, NULL);
126+    swc_compositor_remove_surface(window->surface);
127+    window->surface->window = NULL;
128+    free(window->base.title);
129+    free(window->base.class);
130 }
131 
132-void swc_window_set_title(struct swc_window * window,
133-                          const char * title, size_t length)
134+void window_set_title(struct window * window, const char * title, size_t length)
135 {
136-    free(window->title);
137-    window->title = strndup(title, length);
138-    swc_send_event(&window->event_signal, SWC_WINDOW_TITLE_CHANGED, NULL);
139+    free(window->base.title);
140+    window->base.title = strndup(title, length);
141+    swc_send_event(&window->base.event_signal, SWC_WINDOW_TITLE_CHANGED, NULL);
142 }
143 
144-void swc_window_set_class(struct swc_window * window, const char * class)
145+void window_set_class(struct window * window, const char * class)
146 {
147-    free(window->class);
148-    window->class = strdup(class);
149-    swc_send_event(&window->event_signal, SWC_WINDOW_CLASS_CHANGED, NULL);
150+    free(window->base.class);
151+    window->base.class = strdup(class);
152+    swc_send_event(&window->base.event_signal, SWC_WINDOW_CLASS_CHANGED, NULL);
153 }
154 
155-void swc_window_set_state(struct swc_window * window, uint32_t state)
156+void window_set_state(struct window * window, uint32_t state)
157 {
158-    window->state = state;
159-    swc_send_event(&window->event_signal, SWC_WINDOW_STATE_CHANGED, NULL);
160+    window->base.state = state;
161+    swc_send_event(&window->base.event_signal, SWC_WINDOW_STATE_CHANGED, NULL);
162 }
163 
+17, -18
 1@@ -29,35 +29,34 @@
 2 #include <stdint.h>
 3 #include <wayland-server.h>
 4 
 5-struct swc_window_impl
 6-{
 7-    void (* configure)(struct swc_window * window,
 8-                       const struct swc_rectangle * geometry);
 9-    void (* focus)(struct swc_window * window);
10-};
11-
12-struct swc_window_internal
13+struct window
14 {
15     struct swc_window base;
16 
17     struct swc_surface * surface;
18-    const struct swc_window_impl * impl;
19+    const struct window_impl * impl;
20+};
21+
22+struct window_impl
23+{
24+    void (* configure)(struct window * window,
25+                       const struct swc_rectangle * geometry);
26+    void (* focus)(struct window * window);
27 };
28 
29-extern struct wl_listener * swc_window_enter_listener;
30+extern struct wl_listener window_enter_listener;
31 
32-bool swc_window_initialize(struct swc_window * window,
33-                           const struct swc_window_impl * impl,
34-                           struct swc_surface * surface);
35+bool window_initialize(struct window * window, const struct window_impl * impl,
36+                       struct swc_surface * surface);
37 
38-void swc_window_finalize(struct swc_window * window);
39+void window_finalize(struct window * window);
40 
41-void swc_window_set_title(struct swc_window * window,
42-                          const char * title, size_t length);
43+void window_set_title(struct window * window,
44+                      const char * title, size_t length);
45 
46-void swc_window_set_class(struct swc_window * window, const char * class);
47+void window_set_class(struct window * window, const char * class);
48 
49-void swc_window_set_state(struct swc_window * window, uint32_t state);
50+void window_set_state(struct window * window, uint32_t state);
51 
52 #endif
53 
+11, -13
 1@@ -37,7 +37,7 @@
 2 struct xwl_window
 3 {
 4     xcb_window_t id;
 5-    struct swc_window_internal window;
 6+    struct window window;
 7     struct wl_listener surface_destroy_listener;
 8 };
 9 
10@@ -66,8 +66,8 @@ static void update_name(struct xwl_window * xwl_window)
11     xcb_ewmh_get_wm_name_reply(&xwm.ewmh, wm_name_cookie,
12                                &wm_name_reply, NULL);
13 
14-    swc_window_set_title(&xwl_window->window.base,
15-                         wm_name_reply.strings, wm_name_reply.strings_len);
16+    window_set_title(&xwl_window->window,
17+                     wm_name_reply.strings, wm_name_reply.strings_len);
18 
19     xcb_ewmh_get_utf8_strings_reply_wipe(&wm_name_reply);
20 }
21@@ -265,12 +265,12 @@ void swc_xwm_finalize()
22     xcb_disconnect(xwm.connection);
23 }
24 
25-static void configure(struct swc_window * window,
26+static void configure(struct window * window,
27                       const struct swc_rectangle * geometry)
28 {
29     uint32_t mask, values[4];
30     struct xwl_window * xwl_window
31-        = CONTAINER_OF(window, typeof(*xwl_window), window.base);
32+        = CONTAINER_OF(window, typeof(*xwl_window), window);
33 
34     mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
35          | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
36@@ -283,10 +283,10 @@ static void configure(struct swc_window * window,
37     xcb_flush(xwm.connection);
38 }
39 
40-static void focus(struct swc_window * window)
41+static void focus(struct window * window)
42 {
43     xcb_window_t id = window ? CONTAINER_OF(window, struct xwl_window,
44-                                            window.base)->id
45+                                            window)->id
46                              : XCB_NONE;
47 
48     xcb_set_input_focus(xwm.connection, XCB_INPUT_FOCUS_NONE,
49@@ -294,7 +294,7 @@ static void focus(struct swc_window * window)
50     xcb_flush(xwm.connection);
51 }
52 
53-static const struct swc_window_impl xwl_window_handler = {
54+static const struct window_impl xwl_window_handler = {
55     .configure = &configure,
56     .focus = &focus
57 };
58@@ -305,7 +305,7 @@ static void handle_surface_destroy(struct wl_listener * listener, void * data)
59     struct xwl_window * xwl_window
60         = CONTAINER_OF(listener, typeof(*xwl_window), surface_destroy_listener);
61 
62-    swc_window_finalize(&xwl_window->window.base);
63+    window_finalize(&xwl_window->window);
64     free(xwl_window);
65 
66     wl_array_for_each(entry, &xwm.windows)
67@@ -333,12 +333,11 @@ void swc_xwm_manage_window(xcb_window_t id, struct swc_surface * surface)
68 
69     geometry_cookie = xcb_get_geometry(xwm.connection, id);
70 
71+    window_initialize(&xwl_window->window, &xwl_window_handler, surface);
72     xwl_window->id = id;
73     xwl_window->surface_destroy_listener.notify = &handle_surface_destroy;
74     wl_resource_add_destroy_listener(surface->resource,
75                                      &xwl_window->surface_destroy_listener);
76-    swc_window_initialize(&xwl_window->window.base,
77-                          &xwl_window_handler, surface);
78 
79     entry->xwl_window = xwl_window;
80 
81@@ -363,8 +362,7 @@ void swc_xwm_manage_window(xcb_window_t id, struct swc_surface * surface)
82         xcb_configure_window(xwm.connection, id, mask, values);
83         update_name(xwl_window);
84 
85-        swc_window_set_state(&xwl_window->window.base,
86-                             SWC_WINDOW_STATE_TOPLEVEL);
87+        window_set_state(&xwl_window->window, SWC_WINDOW_STATE_TOPLEVEL);
88     }
89 }
90