commit 335822a

Michael Forney  ·  2013-11-24 06:40:15 +0000 UTC
parent 7fd9167
Remove awkward internal struct stuff
4 files changed,  +22, -29
+2, -13
 1@@ -26,13 +26,6 @@
 2 
 3 #include "util.h"
 4 
 5-#define INTERNAL_DECL(type, name)                                           \
 6-    struct                                                                  \
 7-    {                                                                       \
 8-        struct swc_ ## type name;                                           \
 9-        struct swc_ ## type ## _internal _ ## name ## _internal;            \
10-    }
11-
12 #define INTERNAL_ASSOCIATIONS(ptr, base)                                    \
13     INTERNAL_ASSOCIATION(window, ptr,                                       \
14     base)
15@@ -49,7 +42,7 @@
16 #if HAVE_GENERIC
17 #   define INTERNAL_ASSOCIATION(type, ptr, next)                            \
18         struct swc_ ## type *:                                              \
19-            &((INTERNAL_DECL(type, dummy) *) ptr)->_dummy_internal          \
20+            (struct swc_ ## type ## _internal *) ptr                        \
21         next
22 #   define INTERNAL(ptr)                                                    \
23         _Generic(ptr, INTERNAL_ASSOCIATIONS(ptr,))
24@@ -58,14 +51,10 @@
25 #   define INTERNAL_ASSOCIATION(type, ptr, next)                            \
26         __builtin_choose_expr(                                              \
27         __builtin_types_compatible_p(typeof(ptr), struct swc_ ## type *),   \
28-        &((INTERNAL_DECL(type, dummy) *) ptr)->_dummy_internal, next)
29+        (struct swc_ ## type ## _internal *) ptr, next)
30 #   define INTERNAL(ptr) \
31         INTERNAL_ASSOCIATIONS(ptr, (void) 0)
32 #endif
33 
34-#define CONTAINER_OF_INTERNAL(ptr, type, member)                            \
35-    &CONTAINER_OF(ptr, INTERNAL_DECL(type, dummy),                          \
36-                  _dummy_internal.member)->dummy
37-
38 #endif
39 
+12, -10
 1@@ -31,7 +31,7 @@
 2 
 3 struct swc_shell_surface
 4 {
 5-    INTERNAL_DECL(window, window);
 6+    struct swc_window_internal window;
 7 
 8     struct wl_resource * resource;
 9 
10@@ -72,7 +72,8 @@ 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, SWC_WINDOW_STATE_TOPLEVEL);
15+    swc_window_set_state(&shell_surface->window.base,
16+                         SWC_WINDOW_STATE_TOPLEVEL);
17 }
18 
19 static void set_transient(struct wl_client * client,
20@@ -84,9 +85,9 @@ static void set_transient(struct wl_client * client,
21         = wl_resource_get_user_data(resource);
22     struct swc_surface * parent = wl_resource_get_user_data(parent_resource);
23 
24-    swc_surface_move(INTERNAL(&shell_surface->window)->surface,
25+    swc_surface_move(shell_surface->window.surface,
26                      parent->geometry.x + x, parent->geometry.y + y);
27-    swc_compositor_surface_show(INTERNAL(&shell_surface->window)->surface);
28+    swc_compositor_surface_show(shell_surface->window.surface);
29 
30     /* XXX: Handle transient */
31 }
32@@ -108,9 +109,9 @@ static void set_popup(struct wl_client * client, struct wl_resource * resource,
33         = wl_resource_get_user_data(resource);
34     struct swc_surface * parent = wl_resource_get_user_data(parent_resource);
35 
36-    swc_surface_move(INTERNAL(&shell_surface->window)->surface,
37+    swc_surface_move(shell_surface->window.surface,
38                      parent->geometry.x + x, parent->geometry.y + y);
39-    swc_compositor_surface_show(INTERNAL(&shell_surface->window)->surface);
40+    swc_compositor_surface_show(shell_surface->window.surface);
41 
42     /* XXX: Handle popup */
43 }
44@@ -128,7 +129,7 @@ static void set_title(struct wl_client * client, struct wl_resource * resource,
45     struct swc_shell_surface * shell_surface
46         = wl_resource_get_user_data(resource);
47 
48-    swc_window_set_title(&shell_surface->window, title, -1);
49+    swc_window_set_title(&shell_surface->window.base, title, -1);
50 }
51 
52 static void set_class(struct wl_client * client, struct wl_resource * resource,
53@@ -137,7 +138,7 @@ static void set_class(struct wl_client * client, struct wl_resource * resource,
54     struct swc_shell_surface * shell_surface
55         = wl_resource_get_user_data(resource);
56 
57-    swc_window_set_class(&shell_surface->window, class);
58+    swc_window_set_class(&shell_surface->window.base, class);
59 }
60 
61 static const struct wl_shell_surface_interface shell_surface_implementation = {
62@@ -157,7 +158,7 @@ static void configure(struct swc_window * window,
63                       const struct swc_rectangle * geometry)
64 {
65     struct swc_shell_surface * shell_surface
66-        = CONTAINER_OF(window, typeof(*shell_surface), window);
67+        = CONTAINER_OF(window, typeof(*shell_surface), window.base);
68 
69     wl_shell_surface_send_configure(shell_surface->resource,
70                                     WL_SHELL_SURFACE_RESIZE_NONE,
71@@ -179,7 +180,8 @@ struct swc_shell_surface * swc_shell_surface_new
72         return NULL;
73 
74     shell_surface->type = SHELL_SURFACE_TYPE_UNSPECIFIED;
75-    swc_window_initialize(&shell_surface->window, &shell_window_impl, surface);
76+    swc_window_initialize(&shell_surface->window.base,
77+                          &shell_window_impl, surface);
78 
79     shell_surface->resource = wl_resource_create
80         (client, &wl_shell_surface_interface, 1, id);
+4, -4
 1@@ -95,8 +95,8 @@ void swc_window_set_border(struct swc_window * window,
 2 
 3 static void handle_surface_destroy(struct wl_listener * listener, void * data)
 4 {
 5-    struct swc_window * window = CONTAINER_OF_INTERNAL
 6-        (listener, window, surface_destroy_listener);
 7+    struct swc_window * window = &CONTAINER_OF
 8+        (listener, struct swc_window_internal, surface_destroy_listener)->base;
 9 
10     swc_send_event(&window->event_signal, SWC_WINDOW_DESTROYED, NULL);
11     free(window);
12@@ -131,8 +131,8 @@ struct swc_window * swc_window_get(struct swc_surface * surface)
13     listener = wl_resource_get_destroy_listener(surface->resource,
14                                                 &handle_surface_destroy);
15 
16-    return listener ? CONTAINER_OF_INTERNAL(listener, window,
17-                                            surface_destroy_listener)
18+    return listener ? &CONTAINER_OF(listener, struct swc_window_internal,
19+                                    surface_destroy_listener)->base
20                     : NULL;
21 }
22 
+4, -2
 1@@ -24,11 +24,11 @@
 2 #ifndef SWC_WINDOW_H
 3 #define SWC_WINDOW_H
 4 
 5+#include "swc.h"
 6+
 7 #include <stdint.h>
 8 #include <wayland-server.h>
 9 
10-struct swc_window;
11-
12 struct swc_window_impl
13 {
14     void (* configure)(struct swc_window * window,
15@@ -38,6 +38,8 @@ struct swc_window_impl
16 
17 struct swc_window_internal
18 {
19+    struct swc_window base;
20+
21     struct swc_surface * surface;
22     struct wl_listener surface_destroy_listener;
23     const struct swc_window_impl * impl;