[mutter/wip/wayland-work: 47/54] wayland: generalize ShellSurface to SurfaceExtension



commit 6beef436bb8bacdcbf4d8d9173ee747fdc02ba52
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Thu Aug 29 16:44:37 2013 +0200

    wayland: generalize ShellSurface to SurfaceExtension
    
    We want to implement new shells and new extension interfaces
    for wl_surface, so generalize the book-keeping structures.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707128

 src/wayland/meta-wayland-private.h |    2 +-
 src/wayland/meta-wayland.c         |   85 ++++++++++++++++++++----------------
 2 files changed, 49 insertions(+), 38 deletions(-)
---
diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h
index bb18e12..cdf5ae8 100644
--- a/src/wayland/meta-wayland-private.h
+++ b/src/wayland/meta-wayland-private.h
@@ -106,7 +106,7 @@ typedef struct
   MetaWaylandSurface *surface;
   struct wl_resource *resource;
   struct wl_listener surface_destroy_listener;
-} MetaWaylandShellSurface;
+} MetaWaylandSurfaceExtension;
 
 typedef struct
 {
diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c
index f21e663..6de434b 100644
--- a/src/wayland/meta-wayland.c
+++ b/src/wayland/meta-wayland.c
@@ -899,7 +899,7 @@ shell_surface_pong (struct wl_client *client,
 typedef struct _MetaWaylandGrab
 {
   MetaWaylandPointerGrab grab;
-  MetaWaylandShellSurface *shell_surface;
+  MetaWaylandSurfaceExtension *shell_surface;
   struct wl_listener shell_surface_destroy_listener;
   MetaWaylandPointer *pointer;
 } MetaWaylandGrab;
@@ -931,7 +931,7 @@ typedef enum _GrabCursor
 static void
 grab_pointer (MetaWaylandGrab *grab,
               const MetaWaylandPointerGrabInterface *interface,
-              MetaWaylandShellSurface *shell_surface,
+              MetaWaylandSurfaceExtension *shell_surface,
               MetaWaylandPointer *pointer,
               GrabCursor cursor)
 {
@@ -992,7 +992,7 @@ move_grab_motion (MetaWaylandPointerGrab *grab,
 {
   MetaWaylandMoveGrab *move = (MetaWaylandMoveGrab *)grab;
   MetaWaylandPointer *pointer = move->base.pointer;
-  MetaWaylandShellSurface *shell_surface = move->base.shell_surface;
+  MetaWaylandSurfaceExtension *shell_surface = move->base.shell_surface;
 
   if (!shell_surface)
     return;
@@ -1029,7 +1029,7 @@ static const MetaWaylandPointerGrabInterface move_grab_interface = {
 };
 
 static void
-start_surface_move (MetaWaylandShellSurface *shell_surface,
+start_surface_move (MetaWaylandSurfaceExtension *shell_surface,
                     MetaWaylandSeat *seat)
 {
   MetaWaylandMoveGrab *move;
@@ -1058,7 +1058,7 @@ shell_surface_move (struct wl_client *client,
                     guint32 serial)
 {
   MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
-  MetaWaylandShellSurface *shell_surface = wl_resource_get_user_data (resource);
+  MetaWaylandSurfaceExtension *shell_surface = wl_resource_get_user_data (resource);
 
   if (seat->pointer.button_count == 0 ||
       seat->pointer.grab_serial != serial ||
@@ -1111,7 +1111,7 @@ shell_surface_set_toplevel (struct wl_client *client,
                             struct wl_resource *resource)
 {
   MetaWaylandCompositor *compositor = &_meta_wayland_compositor;
-  MetaWaylandShellSurface *shell_surface = wl_resource_get_user_data (resource);
+  MetaWaylandSurfaceExtension *shell_surface = wl_resource_get_user_data (resource);
   MetaWaylandSurface *surface = shell_surface->surface;
 
   /* NB: Surfaces from xwayland become managed based on X events. */
@@ -1132,7 +1132,7 @@ shell_surface_set_transient (struct wl_client *client,
                              guint32 flags)
 {
   MetaWaylandCompositor *compositor = &_meta_wayland_compositor;
-  MetaWaylandShellSurface *shell_surface = wl_resource_get_user_data (resource);
+  MetaWaylandSurfaceExtension *shell_surface = wl_resource_get_user_data (resource);
   MetaWaylandSurface *surface = shell_surface->surface;
 
   /* NB: Surfaces from xwayland become managed based on X events. */
@@ -1150,7 +1150,7 @@ shell_surface_set_fullscreen (struct wl_client *client,
                               struct wl_resource *output)
 {
   MetaWaylandCompositor *compositor = &_meta_wayland_compositor;
-  MetaWaylandShellSurface *shell_surface = wl_resource_get_user_data (resource);
+  MetaWaylandSurfaceExtension *shell_surface = wl_resource_get_user_data (resource);
   MetaWaylandSurface *surface = shell_surface->surface;
 
   /* NB: Surfaces from xwayland become managed based on X events. */
@@ -1213,29 +1213,51 @@ static const struct wl_shell_surface_interface meta_wayland_shell_surface_interf
 };
 
 static void
-shell_handle_surface_destroy (struct wl_listener *listener,
-                              void *data)
+extension_handle_surface_destroy (struct wl_listener *listener,
+                                 void *data)
 {
-  MetaWaylandShellSurface *shell_surface =
-    wl_container_of (listener, shell_surface, surface_destroy_listener);
-  shell_surface->surface->has_shell_surface = FALSE;
-  shell_surface->surface = NULL;
-  wl_resource_destroy (shell_surface->resource);
+  MetaWaylandSurfaceExtension *extension =
+    wl_container_of (listener, extension, surface_destroy_listener);
+
+  extension->surface = NULL;
+  wl_resource_destroy (extension->resource);
 }
 
 static void
-destroy_shell_surface (struct wl_resource *resource)
+destroy_surface_extension (struct wl_resource *resource)
 {
-  MetaWaylandShellSurface *shell_surface = wl_resource_get_user_data (resource);
+  MetaWaylandSurfaceExtension *extension = wl_resource_get_user_data (resource);
 
-  /* In case cleaning up a dead client destroys shell_surface first */
-  if (shell_surface->surface)
+  /* In case cleaning up a dead client destroys extension first */
+  if (extension->surface)
     {
-      wl_list_remove (&shell_surface->surface_destroy_listener.link);
-      shell_surface->surface->has_shell_surface = FALSE;
+      wl_list_remove (&extension->surface_destroy_listener.link);
     }
 
-  g_free (shell_surface);
+  g_free (extension);
+}
+
+static void
+create_surface_extension (struct wl_client          *client,
+                         struct wl_resource        *master_resource,
+                         guint32                    id,
+                         MetaWaylandSurface        *surface,
+                         const struct wl_interface *interface,
+                         const void                *implementation)
+{
+  MetaWaylandSurfaceExtension *extension;
+
+  extension = g_new0 (MetaWaylandSurfaceExtension, 1);
+
+  extension->resource = wl_resource_create (client, interface,
+                                           wl_resource_get_version (master_resource), id);
+  wl_resource_set_implementation (extension->resource, implementation,
+                                 extension, destroy_surface_extension);
+
+  extension->surface = surface;
+  extension->surface_destroy_listener.notify = extension_handle_surface_destroy;
+  wl_resource_add_destroy_listener (surface->resource,
+                                    &extension->surface_destroy_listener);
 }
 
 static void
@@ -1245,7 +1267,6 @@ get_shell_surface (struct wl_client *client,
                    struct wl_resource *surface_resource)
 {
   MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
-  MetaWaylandShellSurface *shell_surface;
 
   if (surface->has_shell_surface)
     {
@@ -1255,19 +1276,9 @@ get_shell_surface (struct wl_client *client,
       return;
     }
 
-  shell_surface = g_new0 (MetaWaylandShellSurface, 1);
-
-  /* a shell surface inherits the version from the shell */
-  shell_surface->resource =
-    wl_resource_create (client, &wl_shell_surface_interface,
-                       wl_resource_get_version (resource), id);
-  wl_resource_set_implementation (shell_surface->resource, &meta_wayland_shell_surface_interface,
-                                 shell_surface, destroy_shell_surface);
-
-  shell_surface->surface = surface;
-  shell_surface->surface_destroy_listener.notify = shell_handle_surface_destroy;
-  wl_resource_add_destroy_listener (surface->resource,
-                                    &shell_surface->surface_destroy_listener);
+  create_surface_extension (client, resource, id, surface,
+                           &wl_shell_surface_interface,
+                           &meta_wayland_shell_surface_interface);
   surface->has_shell_surface = TRUE;
 }
 


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