commit 67856a4

Michael Forney  ·  2014-08-07 07:22:32 +0000 UTC
parent dd0b216
Split swc_window_set_geometry into swc_window_set_{position,size}
5 files changed,  +98, -52
+32, -33
 1@@ -43,6 +43,33 @@ struct shell_surface
 2     struct wl_listener surface_destroy_listener;
 3 };
 4 
 5+static void configure(struct window * window, uint32_t width, uint32_t height)
 6+{
 7+    struct shell_surface * shell_surface
 8+        = wl_container_of(window, shell_surface, window);
 9+
10+    wl_shell_surface_send_configure(shell_surface->resource,
11+                                    WL_SHELL_SURFACE_RESIZE_NONE,
12+                                    width, height);
13+}
14+
15+static void close(struct window * window)
16+{
17+    struct shell_surface * shell_surface
18+        = wl_container_of(window, shell_surface, window);
19+    struct wl_client * client;
20+    pid_t pid;
21+
22+    client = wl_resource_get_client(shell_surface->resource);
23+    wl_client_get_credentials(client, &pid, NULL, NULL);
24+    kill(pid, SIGTERM);
25+}
26+
27+static const struct window_impl window_impl = {
28+    .configure = &configure,
29+    .close = &close,
30+};
31+
32 static void pong(struct wl_client * client, struct wl_resource * resource,
33                  uint32_t serial)
34 {
35@@ -184,34 +211,6 @@ static const struct wl_shell_surface_interface shell_surface_implementation = {
36     .set_class = &set_class
37 };
38 
39-static void configure(struct window * window,
40-                      const struct swc_rectangle * geometry)
41-{
42-    struct shell_surface * shell_surface
43-        = wl_container_of(window, shell_surface, window);
44-
45-    wl_shell_surface_send_configure(shell_surface->resource,
46-                                    WL_SHELL_SURFACE_RESIZE_NONE,
47-                                    geometry->width, geometry->height);
48-}
49-
50-static void close(struct window * window)
51-{
52-    struct shell_surface * shell_surface
53-        = wl_container_of(window, shell_surface, window);
54-    struct wl_client * client;
55-    pid_t pid;
56-
57-    client = wl_resource_get_client(shell_surface->resource);
58-    wl_client_get_credentials(client, &pid, NULL, NULL);
59-    kill(pid, SIGTERM);
60-}
61-
62-static const struct window_impl shell_window_impl = {
63-    .configure = &configure,
64-    .close = &close,
65-};
66-
67 static void handle_surface_destroy(struct wl_listener * listener, void * data)
68 {
69     struct shell_surface * shell_surface
70@@ -244,15 +243,15 @@ struct shell_surface * shell_surface_new(struct wl_client * client, uint32_t id,
71     if (!shell_surface->resource)
72         goto error1;
73 
74-    window_initialize(&shell_surface->window, &shell_window_impl, surface);
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     wl_resource_set_implementation(shell_surface->resource,
80                                    &shell_surface_implementation,
81                                    shell_surface, &destroy_shell_surface);
82 
83+    window_initialize(&shell_surface->window, &window_impl, surface);
84+    shell_surface->surface_destroy_listener.notify = &handle_surface_destroy;
85+    wl_resource_add_destroy_listener(surface->resource,
86+                                     &shell_surface->surface_destroy_listener);
87+
88     return shell_surface;
89 
90   error1:
+20, -3
 1@@ -125,10 +125,27 @@ void swc_window_hide(struct swc_window * window);
 2 void swc_window_focus(struct swc_window * window);
 3 
 4 /**
 5- * Set the window's geometry.
 6+ * Set the window's position.
 7  *
 8- * The geometry's coordinates refer to the actual contents of the window, and
 9- * should be adjusted for the border size.
10+ * The x and y coordinates refer to the top-left corner of the actual contents
11+ * of the window and should be adjusted for the border size.
12+ */
13+void swc_window_set_position(struct swc_window * window, int32_t x, int32_t y);
14+
15+/**
16+ * Set the window's size.
17+ *
18+ * The width and height refer to the dimension of the actual contents of the
19+ * window and should be adjusted for the border size.
20+ */
21+void swc_window_set_size(struct swc_window * window,
22+                         uint32_t width, uint32_t height);
23+
24+/**
25+ * Set the window's size and position.
26+ *
27+ * This is a convenience function that is equivalent to calling
28+ * swc_window_set_size and then swc_window_set_position.
29  */
30 void swc_window_set_geometry(struct swc_window * window,
31                              const struct swc_rectangle * geometry);
+24, -5
 1@@ -98,15 +98,34 @@ void swc_window_focus(struct swc_window * base)
 2 }
 3 
 4 EXPORT
 5-void swc_window_set_geometry(struct swc_window * base,
 6-                             const struct swc_rectangle * geometry)
 7+void swc_window_set_position(struct swc_window * base, int32_t x, int32_t y)
 8+{
 9+    struct window * window = INTERNAL(base);
10+    struct swc_rectangle * geometry = &window->view->base.geometry;
11+
12+    if (x == geometry->x && y == geometry->y)
13+        return;
14+
15+    if (window->impl->move)
16+        window->impl->move(window, x, y);
17+    view_move(&window->view->base, x, y);
18+}
19+
20+EXPORT
21+void swc_window_set_size(struct swc_window * base,
22+                         uint32_t width, uint32_t height)
23 {
24     struct window * window = INTERNAL(base);
25 
26-    if (window->impl->configure)
27-        window->impl->configure(window, geometry);
28+    window->impl->configure(window, width, height);
29+}
30 
31-    view_move(&window->view->base, geometry->x, geometry->y);
32+EXPORT
33+void swc_window_set_geometry(struct swc_window * window,
34+                             const struct swc_rectangle * geometry)
35+{
36+    swc_window_set_size(window, geometry->width, geometry->height);
37+    swc_window_set_position(window, geometry->x, geometry->y);
38 }
39 
40 EXPORT
+2, -2
 1@@ -57,8 +57,8 @@ struct window
 2 
 3 struct window_impl
 4 {
 5-    void (* configure)(struct window * window,
 6-                       const struct swc_rectangle * geometry);
 7+    void (* move)(struct window * window, int32_t x, int32_t y);
 8+    void (* configure)(struct window * window, uint32_t width, uint32_t height);
 9     void (* focus)(struct window * window);
10     void (* unfocus)(struct window * window);
11     void (* close)(struct window * window);
+20, -9
 1@@ -151,19 +151,29 @@ static struct xwl_window * find_window_by_surface_id(struct wl_list * list,
 2     return NULL;
 3 }
 4 
 5-static void configure(struct window * window,
 6-                      const struct swc_rectangle * geometry)
 7+static void move(struct window * window, int32_t x, int32_t y)
 8 {
 9-    uint32_t mask, values[4];
10+    uint32_t mask, values[2];
11     struct xwl_window * xwl_window
12         = wl_container_of(window, xwl_window, window);
13 
14-    mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
15-         | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
16-    values[0] = geometry->x;
17-    values[1] = geometry->y;
18-    values[2] = geometry->width;
19-    values[3] = geometry->height;
20+    mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y;
21+    values[0] = x;
22+    values[1] = y;
23+
24+    xcb_configure_window(xwm.connection, xwl_window->id, mask, values);
25+    xcb_flush(xwm.connection);
26+}
27+
28+static void configure(struct window * window, uint32_t width, uint32_t height)
29+{
30+    uint32_t mask, values[2];
31+    struct xwl_window * xwl_window
32+        = wl_container_of(window, xwl_window, window);
33+
34+    mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
35+    values[0] = width;
36+    values[1] = height;
37 
38     xcb_configure_window(xwm.connection, xwl_window->id, mask, values);
39     xcb_flush(xwm.connection);
40@@ -225,6 +235,7 @@ static void close(struct window * window)
41 }
42 
43 static const struct window_impl xwl_window_handler = {
44+    .move = &move,
45     .configure = &configure,
46     .focus = &focus,
47     .unfocus = &unfocus,