commit 3509094

Michael Forney  ·  2014-02-25 22:09:23 +0000 UTC
parent 10a70b6
shell_surface: Add basic support for state transitions
4 files changed,  +62, -19
+5, -0
 1@@ -518,6 +518,11 @@ void compositor_view_destroy(struct compositor_view * view)
 2     free(view);
 3 }
 4 
 5+struct compositor_view * compositor_view(struct view * view)
 6+{
 7+    return view->impl == &view_impl ? (struct compositor_view *) view : NULL;
 8+}
 9+
10 void compositor_view_set_parent(struct compositor_view * view,
11                                 struct compositor_view * parent)
12 {
+5, -0
 1@@ -71,6 +71,11 @@ struct compositor_view * swc_compositor_create_view
 2 
 3 void compositor_view_destroy(struct compositor_view * view);
 4 
 5+/**
 6+ * Returns view as a compositor_view, or NULL if view is not a compositor_view.
 7+ */
 8+struct compositor_view * compositor_view(struct view * view);
 9+
10 void compositor_view_set_parent(struct compositor_view * view,
11                                 struct compositor_view * parent);
12 
+49, -19
  1@@ -24,6 +24,8 @@
  2 #include "shell_surface.h"
  3 #include "compositor.h"
  4 #include "internal.h"
  5+#include "output.h"
  6+#include "screen.h"
  7 #include "seat.h"
  8 #include "surface.h"
  9 #include "swc.h"
 10@@ -39,16 +41,6 @@ struct shell_surface
 11 
 12     struct wl_resource * resource;
 13     struct wl_listener surface_destroy_listener;
 14-
 15-    enum
 16-    {
 17-        SHELL_SURFACE_TYPE_UNSPECIFIED,
 18-        SHELL_SURFACE_TYPE_TOPLEVEL,
 19-        SHELL_SURFACE_TYPE_TRANSIENT,
 20-        SHELL_SURFACE_TYPE_FULLSCREEN,
 21-        SHELL_SURFACE_TYPE_POPUP,
 22-        SHELL_SURFACE_TYPE_MAXIMIZED
 23-    } type;
 24 };
 25 
 26 static void pong(struct wl_client * client, struct wl_resource * resource,
 27@@ -86,11 +78,8 @@ static void set_toplevel(struct wl_client * client,
 28 {
 29     struct shell_surface * shell_surface = wl_resource_get_user_data(resource);
 30 
 31-    if (shell_surface->type == SHELL_SURFACE_TYPE_TOPLEVEL)
 32-        return;
 33-
 34-    shell_surface->type = SHELL_SURFACE_TYPE_TOPLEVEL;
 35     window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
 36+    window_set_parent(&shell_surface->window, NULL);
 37 }
 38 
 39 static void set_transient(struct wl_client * client,
 40@@ -98,7 +87,20 @@ static void set_transient(struct wl_client * client,
 41                           struct wl_resource * parent_resource,
 42                           int32_t x, int32_t y, uint32_t flags)
 43 {
 44-    /* XXX: Handle transient */
 45+    struct shell_surface * shell_surface = wl_resource_get_user_data(resource);
 46+    struct swc_surface * parent_surface
 47+        = wl_resource_get_user_data(parent_resource);
 48+    struct compositor_view * parent_view
 49+        = compositor_view(parent_surface->view);
 50+
 51+    if (!parent_view || !parent_view->window)
 52+        return;
 53+
 54+    window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
 55+    window_set_parent(&shell_surface->window, parent_view->window);
 56+    view_move(&shell_surface->window.view->base,
 57+              parent_view->base.geometry.x + x,
 58+              parent_view->base.geometry.y + y);
 59 }
 60 
 61 static void set_fullscreen(struct wl_client * client,
 62@@ -106,7 +108,18 @@ static void set_fullscreen(struct wl_client * client,
 63                            uint32_t method, uint32_t framerate,
 64                            struct wl_resource * output_resource)
 65 {
 66-    /* XXX: Handle fullscreen */
 67+    struct shell_surface * shell_surface = wl_resource_get_user_data(resource);
 68+    struct swc_output * output = output_resource
 69+        ? wl_resource_get_user_data(output_resource) : NULL;
 70+    struct screen * screen;
 71+
 72+    screen = output ? output->screen
 73+                    : CONTAINER_OF(swc.screens.next, typeof(*screen), link);
 74+
 75+    /* TODO: Handle fullscreen windows. */
 76+
 77+    window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
 78+    window_set_parent(&shell_surface->window, NULL);
 79 }
 80 
 81 static void set_popup(struct wl_client * client, struct wl_resource * resource,
 82@@ -114,14 +127,32 @@ static void set_popup(struct wl_client * client, struct wl_resource * resource,
 83                       struct wl_resource * parent_resource,
 84                       int32_t x, int32_t y, uint32_t flags)
 85 {
 86-    /* XXX: Handle popup */
 87+    struct shell_surface * shell_surface = wl_resource_get_user_data(resource);
 88+    struct swc_surface * parent_surface
 89+        = wl_resource_get_user_data(parent_resource);
 90+    struct compositor_view * parent_view
 91+        = compositor_view(parent_surface->view);
 92+
 93+    if (!parent_view || !parent_view->window)
 94+        return;
 95+
 96+    window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NONE);
 97+    window_set_parent(&shell_surface->window, parent_view->window);
 98+    view_move(&shell_surface->window.view->base,
 99+              parent_view->base.geometry.x + x,
100+              parent_view->base.geometry.y + y);
101 }
102 
103 static void set_maximized(struct wl_client * client,
104                           struct wl_resource * resource,
105                           struct wl_resource * output_resource)
106 {
107-    /* XXX: Handle maximized */
108+    struct shell_surface * shell_surface = wl_resource_get_user_data(resource);
109+
110+    /* TODO: Handle maximized windows. */
111+
112+    window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
113+    window_set_parent(&shell_surface->window, NULL);
114 }
115 
116 static void set_title(struct wl_client * client, struct wl_resource * resource,
117@@ -201,7 +232,6 @@ struct shell_surface * shell_surface_new(struct wl_client * client, uint32_t id,
118         goto error1;
119 
120     window_initialize(&shell_surface->window, &shell_window_impl, surface);
121-    shell_surface->type = SHELL_SURFACE_TYPE_UNSPECIFIED;
122     shell_surface->surface_destroy_listener.notify = &handle_surface_destroy;
123     wl_resource_add_destroy_listener(surface->resource,
124                                      &shell_surface->surface_destroy_listener);
+3, -0
 1@@ -280,6 +280,9 @@ void window_set_class(struct window * window, const char * class)
 2 
 3 void window_set_state(struct window * window, uint32_t state)
 4 {
 5+    if (window->base.state == state)
 6+        return;
 7+
 8     window->base.state = state;
 9     swc_send_event(&window->base.event_signal, SWC_WINDOW_STATE_CHANGED, NULL);
10 }