[clutter/fosdem-2012: 2/6] test-wayland-surface: Update to the new shell interface



commit db18221739cf8c4026afdd35d69e16f79f670439
Author: Robert Bragg <robert linux intel com>
Date:   Tue Jan 3 23:40:51 2012 +0000

    test-wayland-surface: Update to the new shell interface
    
    Wayland has changed so that the shell interface now only has one
    function which returns a shell surface for the surface. This patch makes
    it create a dummy service in the same way that the wayland demo
    compositor does. The implementation of the shell_surface_interface for
    that dummy service is all no-ops.  ate test-wayland-surface to support
    latest protocol
    
    This patch was based on an equivalent patch made to cogland by Neil
    Roberts.

 tests/interactive/test-wayland-surface.c |  128 +++++++++++++++++++++++------
 1 files changed, 101 insertions(+), 27 deletions(-)
---
diff --git a/tests/interactive/test-wayland-surface.c b/tests/interactive/test-wayland-surface.c
index 69de77b..f8938f6 100644
--- a/tests/interactive/test-wayland-surface.c
+++ b/tests/interactive/test-wayland-surface.c
@@ -35,10 +35,18 @@ typedef struct
   int y;
   TWSBuffer *buffer;
   ClutterActor *actor;
+  gboolean has_shell_surface;
 } TWSSurface;
 
 typedef struct
 {
+  TWSSurface *surface;
+  struct wl_resource resource;
+  struct wl_listener surface_destroy_listener;
+} TWSShellSurface;
+
+typedef struct
+{
   guint32 flags;
   int width;
   int height;
@@ -485,54 +493,120 @@ compositor_bind (struct wl_client *client,
 }
 
 static void
-shell_move(struct wl_client *client,
-           struct wl_resource *resource,
-           struct wl_resource *surface_resource,
-           struct wl_resource *input_resource,
-           guint32 time)
+shell_surface_move(struct wl_client *client,
+                   struct wl_resource *resource,
+                   struct wl_resource *input_resource,
+                   guint32 time)
 {
 }
 
 static void
-shell_resize (struct wl_client *client,
-              struct wl_resource *resource,
-              struct wl_resource *surface_resource,
-              struct wl_resource *input_resource,
-              guint32 time,
-              guint32 edges)
+shell_surface_resize (struct wl_client *client,
+                      struct wl_resource *resource,
+                      struct wl_resource *input_resource,
+                      guint32 time,
+                      guint32 edges)
 {
 }
 
 static void
-shell_set_toplevel (struct wl_client *client,
-		    struct wl_resource *resource,
-		    struct wl_resource *surface_resource)
+shell_surface_set_toplevel (struct wl_client *client,
+                            struct wl_resource *resource)
 {
 }
 
 static void
-shell_set_transient (struct wl_client *client,
-		     struct wl_resource *resource,
-		     struct wl_resource *surface_resource,
-		     struct wl_resource *parent_resource,
-		     int x, int y, uint32_t flags)
+shell_surface_set_transient (struct wl_client *client,
+                             struct wl_resource *resource,
+                             struct wl_resource *parent_resource,
+                             int x,
+                             int y,
+                             guint32 flags)
 {
 }
 
 static void
-shell_set_fullscreen (struct wl_client *client,
-		      struct wl_resource *resource,
-		      struct wl_resource *surface_resource)
+shell_surface_set_fullscreen (struct wl_client *client,
+                              struct wl_resource *resource)
 {
 }
 
+static const struct wl_shell_surface_interface tws_shell_surface_interface =
+{
+  shell_surface_move,
+  shell_surface_resize,
+  shell_surface_set_toplevel,
+  shell_surface_set_transient,
+  shell_surface_set_fullscreen
+};
+
+static void
+shell_handle_surface_destroy (struct wl_listener *listener,
+                              struct wl_resource *resource,
+                              guint32 time)
+{
+  TWSShellSurface *shell_surface = container_of (listener,
+                                                 TWSShellSurface,
+                                                 surface_destroy_listener);
+
+  shell_surface->surface->has_shell_surface = FALSE;
+  shell_surface->surface = NULL;
+  wl_resource_destroy (&shell_surface->resource, time);
+}
+
+static void
+destroy_shell_surface (struct wl_resource *resource)
+{
+  TWSShellSurface *shell_surface = resource->data;
+
+  /* In case cleaning up a dead client destroys shell_surface first */
+  if (shell_surface->surface)
+    {
+      wl_list_remove (&shell_surface->surface_destroy_listener.link);
+      shell_surface->surface->has_shell_surface = FALSE;
+    }
+
+  g_free (shell_surface);
+}
+
+static void
+get_shell_surface (struct wl_client *client,
+                   struct wl_resource *resource,
+                   guint32 id,
+                   struct wl_resource *surface_resource)
+{
+  TWSSurface *surface = surface_resource->data;
+  TWSShellSurface *shell_surface;
+
+  if (surface->has_shell_surface)
+    {
+      wl_resource_post_error (surface_resource,
+                              WL_DISPLAY_ERROR_INVALID_OBJECT,
+                              "wl_shell::get_shell_surface already requested");
+      return;
+    }
+
+  shell_surface = g_new0 (TWSShellSurface, 1);
+  shell_surface->resource.destroy = destroy_shell_surface;
+  shell_surface->resource.object.id = id;
+  shell_surface->resource.object.interface = &wl_shell_surface_interface;
+  shell_surface->resource.object.implementation =
+    (void (**) (void)) &tws_shell_surface_interface;
+  shell_surface->resource.data = shell_surface;
+
+  shell_surface->surface = surface;
+  shell_surface->surface_destroy_listener.func = shell_handle_surface_destroy;
+  wl_list_insert (surface->wayland_surface.resource.destroy_listener_list.prev,
+                  &shell_surface->surface_destroy_listener.link);
+
+  surface->has_shell_surface = TRUE;
+
+  wl_client_add_resource (client, &shell_surface->resource);
+}
+
 static const struct wl_shell_interface tws_shell_interface =
 {
-  shell_move,
-  shell_resize,
-  shell_set_toplevel,
-  shell_set_transient,
-  shell_set_fullscreen
+  get_shell_surface
 };
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]