Move map requests to shell
authorKristian Høgsberg <krh@bitplanet.net>
Sat, 18 Jun 2011 10:12:54 +0000 (06:12 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Mon, 20 Jun 2011 14:45:24 +0000 (10:45 -0400)
clients/simple-client.c
clients/window.c
compositor/compositor.c
compositor/shell.c

index 0a97be0..9e60cbb 100644 (file)
@@ -37,6 +37,7 @@ struct display {
        struct wl_display *display;
        struct wl_visual *premultiplied_argb_visual;
        struct wl_compositor *compositor;
+       struct wl_shell *shell;
        struct {
                EGLDisplay dpy;
                EGLContext ctx;
@@ -227,7 +228,7 @@ create_surface(struct window *window)
                                       window->native,
                                       NULL);
 
-       wl_surface_map_toplevel(window->surface);
+       wl_shell_set_toplevel(display->shell, window->surface);
 
        ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface,
                             window->egl_surface, window->display->egl.ctx);
@@ -320,6 +321,8 @@ display_handle_global(struct wl_display *display, uint32_t id,
                d->compositor = wl_compositor_create(display, id, 1);
                wl_compositor_add_listener(d->compositor,
                                           &compositor_listener, d);
+       } else if (strcmp(interface, "wl_shell") == 0) {
+               d->shell = wl_shell_create(display, id, 1);
        }
 }
 
index 944981c..612e5b3 100644 (file)
@@ -733,13 +733,13 @@ window_attach_surface(struct window *window)
        }
 
        if (window->fullscreen)
-               wl_surface_map_fullscreen(window->surface);
+               wl_shell_set_fullscreen(display->shell, window->surface);
        else if (!window->parent)
-               wl_surface_map_toplevel(window->surface);
+               wl_shell_set_toplevel(display->shell, window->surface);
        else
-               wl_surface_map_transient(window->surface,
-                                        window->parent->surface,
-                                        window->x, window->y, 0);
+               wl_shell_set_transient(display->shell, window->surface,
+                                      window->parent->surface,
+                                      window->x, window->y, 0);
 
        wl_surface_damage(window->surface, 0, 0,
                          window->allocation.width,
index b9f812b..4cd5009 100644 (file)
@@ -862,20 +862,14 @@ surface_attach(struct wl_client *client,
         * damaged by the client. */
        wlsc_surface_damage(es);
 
-       switch (es->map_type) {
-       case WLSC_SURFACE_MAP_FULLSCREEN:
-               es->x = (es->fullscreen_output->width - es->width) / 2;
-               es->y = (es->fullscreen_output->height - es->height) / 2;
-               break;
-       default:
-               es->x += x;
-               es->y += y;
-               break;
-       }
+       es->x += x;
+       es->y += y;
        es->width = buffer->width;
        es->height = buffer->height;
        if (x != 0 || y != 0)
                wlsc_surface_assign_output(es);
+       if (es->visual == NULL)
+               wl_list_insert(&es->compositor->surface_list, &es->link);
 
        wlsc_buffer_attach(buffer, surface);
 
@@ -883,99 +877,6 @@ surface_attach(struct wl_client *client,
 }
 
 static void
-surface_map_toplevel(struct wl_client *client,
-                    struct wl_surface *surface)
-{
-       struct wlsc_surface *es = (struct wlsc_surface *) surface;
-       struct wlsc_compositor *ec = es->compositor;
-
-       switch (es->map_type) {
-       case WLSC_SURFACE_MAP_UNMAPPED:
-               es->x = 10 + random() % 400;
-               es->y = 10 + random() % 400;
-               /* assign to first output */
-               es->output = container_of(ec->output_list.next,
-                                         struct wlsc_output, link);
-               wl_list_insert(&es->compositor->surface_list, &es->link);
-               break;
-       case WLSC_SURFACE_MAP_TOPLEVEL:
-               return;
-       case WLSC_SURFACE_MAP_FULLSCREEN:
-               es->fullscreen_output = NULL;
-               es->x = es->saved_x;
-               es->y = es->saved_y;
-               break;
-       default:
-               break;
-       }
-
-       wlsc_surface_damage(es);
-       es->map_type = WLSC_SURFACE_MAP_TOPLEVEL;
-}
-
-static void
-surface_map_transient(struct wl_client *client,
-                     struct wl_surface *surface, struct wl_surface *parent,
-                     int x, int y, uint32_t flags)
-{
-       struct wlsc_surface *es = (struct wlsc_surface *) surface;
-       struct wlsc_surface *pes = (struct wlsc_surface *) parent;
-
-       switch (es->map_type) {
-       case WLSC_SURFACE_MAP_UNMAPPED:
-               wl_list_insert(&es->compositor->surface_list, &es->link);
-               /* assign to parents output  */
-               es->output = pes->output;
-               break;
-       case WLSC_SURFACE_MAP_FULLSCREEN:
-               es->fullscreen_output = NULL;
-               break;
-       default:
-               break;
-       }
-
-       es->x = pes->x + x;
-       es->y = pes->y + y;
-
-       wlsc_surface_damage(es);
-       es->map_type = WLSC_SURFACE_MAP_TRANSIENT;
-}
-
-static void
-surface_map_fullscreen(struct wl_client *client, struct wl_surface *surface)
-{
-       struct wlsc_surface *es = (struct wlsc_surface *) surface;
-       struct wlsc_output *output;
-
-       /* FIXME: Fullscreen on first output */
-       /* FIXME: Handle output going away */
-       output = container_of(es->compositor->output_list.next,
-                             struct wlsc_output, link);
-
-       switch (es->map_type) {
-       case WLSC_SURFACE_MAP_UNMAPPED:
-               es->x = 10 + random() % 400;
-               es->y = 10 + random() % 400;
-               /* assign to first output */
-               es->output = output;
-               wl_list_insert(&es->compositor->surface_list, &es->link);
-               break;
-       case WLSC_SURFACE_MAP_FULLSCREEN:
-               return;
-       default:
-               break;
-       }
-
-       es->saved_x = es->x;
-       es->saved_y = es->y;
-       es->x = (output->width - es->width) / 2;
-       es->y = (output->height - es->height) / 2;
-       es->fullscreen_output = output;
-       wlsc_surface_damage(es);
-       es->map_type = WLSC_SURFACE_MAP_FULLSCREEN;
-}
-
-static void
 surface_damage(struct wl_client *client,
               struct wl_surface *surface,
               int32_t x, int32_t y, int32_t width, int32_t height)
@@ -988,9 +889,6 @@ surface_damage(struct wl_client *client,
 const static struct wl_surface_interface surface_interface = {
        surface_destroy,
        surface_attach,
-       surface_map_toplevel,
-       surface_map_transient,
-       surface_map_fullscreen,
        surface_damage
 };
 
index ddf4d5f..577aa57 100644 (file)
@@ -240,6 +240,75 @@ shell_resize(struct wl_client *client, struct wl_shell *shell,
 }
 
 static void
+shell_set_toplevel(struct wl_client *client,
+                  struct wl_shell *wl_shell,
+                  struct wl_surface *surface)
+
+{
+       struct wlsc_surface *es = (struct wlsc_surface *) surface;
+       struct wlsc_compositor *ec = es->compositor;
+
+       if (es->map_type == WLSC_SURFACE_MAP_FULLSCREEN) {
+               es->x = es->saved_x;
+               es->y = es->saved_y;
+       } else if (es->map_type == WLSC_SURFACE_MAP_UNMAPPED) {
+               es->x = 10 + random() % 400;
+               es->y = 10 + random() % 400;
+               /* assign to first output */
+               es->output = container_of(ec->output_list.next,
+                                         struct wlsc_output, link);
+       }
+
+       wlsc_surface_damage(es);
+       es->map_type = WLSC_SURFACE_MAP_TOPLEVEL;
+       es->fullscreen_output = NULL;
+}
+
+static void
+shell_set_transient(struct wl_client *client,
+                   struct wl_shell *wl_shell,
+                   struct wl_surface *surface,
+                   struct wl_surface *parent,
+                   int x, int y, uint32_t flags)
+{
+       struct wlsc_surface *es = (struct wlsc_surface *) surface;
+       struct wlsc_surface *pes = (struct wlsc_surface *) parent;
+
+       /* assign to parents output  */
+       es->output = pes->output;
+       es->x = pes->x + x;
+       es->y = pes->y + y;
+
+       wlsc_surface_damage(es);
+       es->map_type = WLSC_SURFACE_MAP_TRANSIENT;
+}
+
+static void
+shell_set_fullscreen(struct wl_client *client,
+                    struct wl_shell *wl_shell,
+                    struct wl_surface *surface)
+
+{
+       struct wlsc_surface *es = (struct wlsc_surface *) surface;
+       struct wlsc_output *output;
+
+       /* FIXME: Fullscreen on first output */
+       /* FIXME: Handle output going away */
+       output = container_of(es->compositor->output_list.next,
+                             struct wlsc_output, link);
+       es->output = output;
+
+       es->saved_x = es->x;
+       es->saved_y = es->y;
+       es->x = (output->width - es->width) / 2;
+       es->y = (output->height - es->height) / 2;
+       es->fullscreen_output = output;
+       wlsc_surface_damage(es);
+       es->map_type = WLSC_SURFACE_MAP_FULLSCREEN;
+}
+
+static void
 destroy_drag(struct wl_resource *resource, struct wl_client *client)
 {
        struct wl_drag *drag =
@@ -676,7 +745,10 @@ const static struct wl_shell_interface shell_interface = {
        shell_move,
        shell_resize,
        shell_create_drag,
-       shell_create_selection
+       shell_create_selection,
+       shell_set_toplevel,
+       shell_set_transient,
+       shell_set_fullscreen
 };
 
 static void
@@ -732,8 +804,12 @@ lock(struct wlsc_shell *shell)
 }
 
 static void
-attach(struct wlsc_shell *shell, struct wlsc_surface *surface)
+attach(struct wlsc_shell *shell, struct wlsc_surface *es)
 {
+       if (es->map_type == WLSC_SURFACE_MAP_FULLSCREEN) {
+               es->x = (es->fullscreen_output->width - es->width) / 2;
+               es->y = (es->fullscreen_output->height - es->height) / 2;
+       }
 }
 
 int