[mutter/wip/tablet-protocol: 2/17] wayland: Refactor MetaWaylandSurfaceRoleCursor



commit 1334c690a4622adc2ecebd376e7d6cccf92db4f6
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Oct 21 16:36:44 2015 +0200

    wayland: Refactor MetaWaylandSurfaceRoleCursor
    
    Move into a standalone meta-wayland-surface-role-cursor.[ch], and
    make generic enough to work for pointe and additional (eg. tablet)
    cursors.
    
    Most notably, the sprite is now kept completely internal to the
    cursor role, and updates are routed through the given
    MetaCursorRenderer (which may be the default one for the pointer,
    or something else).
    
    The way cursor updates after cursor surface destruction has also
    been reworked, the pointer will just keep track of the last cursor
    surface, so older surfaces being destroyed don't trigger pointer
    rechecks/updates.

 src/Makefile.am                                |    2 +
 src/wayland/meta-wayland-pointer.c             |  228 ++++-------------------
 src/wayland/meta-wayland-pointer.h             |   11 +-
 src/wayland/meta-wayland-surface-role-cursor.c |  233 ++++++++++++++++++++++++
 src/wayland/meta-wayland-surface-role-cursor.h |   46 +++++
 src/wayland/meta-wayland-surface.c             |    1 +
 src/wayland/meta-wayland-surface.h             |    1 +
 7 files changed, 327 insertions(+), 195 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 3e48bd0..bee8741 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -274,6 +274,8 @@ libmutter_la_SOURCES +=                             \
        wayland/meta-wayland-touch.h            \
        wayland/meta-wayland-surface.c          \
        wayland/meta-wayland-surface.h          \
+       wayland/meta-wayland-surface-role-cursor.c      \
+       wayland/meta-wayland-surface-role-cursor.h      \
        wayland/meta-wayland-types.h            \
        wayland/meta-wayland-versions.h         \
        wayland/meta-wayland-outputs.c          \
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index 894a64d..eaba20e 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -53,6 +53,7 @@
 #include "meta-wayland-private.h"
 #include "meta-wayland-surface.h"
 #include "meta-wayland-buffer.h"
+#include "meta-wayland-surface-role-cursor.h"
 #include "meta-xwayland.h"
 #include "meta-cursor.h"
 #include "meta-cursor-tracker-private.h"
@@ -66,22 +67,6 @@
 
 #define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int (10)
 
-struct _MetaWaylandSurfaceRoleCursor
-{
-  MetaWaylandSurfaceRole parent;
-
-  int hot_x;
-  int hot_y;
-  MetaCursorSprite *cursor_sprite;
-};
-
-G_DEFINE_TYPE (MetaWaylandSurfaceRoleCursor,
-               meta_wayland_surface_role_cursor,
-               META_TYPE_WAYLAND_SURFACE_ROLE);
-
-static void
-meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer);
-
 static MetaWaylandPointerClient *
 meta_wayland_pointer_client_new (void)
 {
@@ -396,6 +381,12 @@ meta_wayland_pointer_release (MetaWaylandPointer *pointer)
                                         (gpointer) meta_wayland_pointer_on_cursor_changed,
                                         pointer);
 
+  if (pointer->cursor_surface && pointer->cursor_surface_destroy_id)
+    {
+      g_signal_handler_disconnect (pointer->cursor_surface,
+                                   pointer->cursor_surface_destroy_id);
+    }
+
   meta_wayland_pointer_set_focus (pointer, NULL);
 
   g_clear_pointer (&pointer->pointer_clients, g_hash_table_unref);
@@ -742,7 +733,7 @@ meta_wayland_pointer_get_relative_coordinates (MetaWaylandPointer *pointer,
   *sy = wl_fixed_from_double (yf) / surface->scale;
 }
 
-static void
+void
 meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
 {
   MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
@@ -756,7 +747,7 @@ meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
           MetaWaylandSurfaceRoleCursor *cursor_role =
             META_WAYLAND_SURFACE_ROLE_CURSOR (pointer->cursor_surface->role);
 
-          cursor_sprite = cursor_role->cursor_sprite;
+          cursor_sprite = meta_wayland_surface_role_cursor_get_sprite (cursor_role);
         }
 
       meta_cursor_tracker_set_window_cursor (cursor_tracker, cursor_sprite);
@@ -768,65 +759,14 @@ meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
 }
 
 static void
-update_cursor_sprite_texture (MetaWaylandSurface *surface)
+ensure_update_cursor_surface (MetaWaylandPointer *pointer,
+                              MetaWaylandSurface *surface)
 {
-  MetaCursorRenderer *cursor_renderer =
-    meta_backend_get_cursor_renderer (meta_get_backend ());
-  MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
-  MetaWaylandSurfaceRoleCursor *cursor_role =
-    META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
-  MetaCursorSprite *cursor_sprite = cursor_role->cursor_sprite;
-  ClutterBackend *clutter_backend = clutter_get_default_backend ();
-  CoglContext *cogl_context =
-    clutter_backend_get_cogl_context (clutter_backend);
-  CoglTexture *texture;
-
-  if (surface->buffer)
-    {
-      struct wl_resource *buffer;
-
-      buffer = surface->buffer->resource;
-      texture = cogl_wayland_texture_2d_new_from_buffer (cogl_context,
-                                                         buffer,
-                                                         NULL);
-
-      meta_cursor_sprite_set_texture (cursor_sprite,
-                                      texture,
-                                      cursor_role->hot_x * surface->scale,
-                                      cursor_role->hot_y * surface->scale);
-      meta_cursor_renderer_realize_cursor_from_wl_buffer (cursor_renderer,
-                                                          cursor_sprite,
-                                                          buffer);
-      cogl_object_unref (texture);
-    }
-  else
-    {
-      meta_cursor_sprite_set_texture (cursor_sprite, NULL, 0, 0);
-    }
-
-  if (cursor_sprite == meta_cursor_tracker_get_displayed_cursor (cursor_tracker))
-    meta_cursor_renderer_force_update (cursor_renderer);
-}
-
-static void
-cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite,
-                          int x,
-                          int y,
-                          MetaWaylandSurfaceRoleCursor *cursor_role)
-{
-  MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_role);
-  MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role);
-  MetaDisplay *display = meta_get_display ();
-  MetaScreen *screen = display->screen;
-  const MetaMonitorInfo *monitor;
+  if (pointer->cursor_surface != surface)
+    return;
 
-  if (!meta_xwayland_is_xwayland_surface (surface))
-    {
-      monitor = meta_screen_get_monitor_for_point (screen, x, y);
-      meta_cursor_sprite_set_texture_scale (cursor_sprite,
-                                            (float)monitor->scale / surface->scale);
-    }
-  meta_wayland_surface_update_outputs (surface);
+  pointer->cursor_surface = NULL;
+  meta_wayland_pointer_update_cursor_surface (pointer);
 }
 
 static void
@@ -836,14 +776,28 @@ meta_wayland_pointer_set_cursor_surface (MetaWaylandPointer *pointer,
   MetaWaylandSurface *prev_cursor_surface;
 
   prev_cursor_surface = pointer->cursor_surface;
+
+  if (prev_cursor_surface == cursor_surface)
+    return;
+
   pointer->cursor_surface = cursor_surface;
 
-  if (prev_cursor_surface != cursor_surface)
+  if (prev_cursor_surface)
+    {
+      meta_wayland_surface_update_outputs (prev_cursor_surface);
+      g_signal_handler_disconnect (prev_cursor_surface,
+                                   pointer->cursor_surface_destroy_id);
+    }
+
+  if (cursor_surface)
     {
-      if (prev_cursor_surface)
-        meta_wayland_surface_update_outputs (prev_cursor_surface);
-      meta_wayland_pointer_update_cursor_surface (pointer);
+      pointer->cursor_surface_destroy_id =
+        g_signal_connect_swapped (cursor_surface, "destroy",
+                                  G_CALLBACK (ensure_update_cursor_surface),
+                                  pointer);
     }
+
+  meta_wayland_pointer_update_cursor_surface (pointer);
 }
 
 static void
@@ -877,23 +831,15 @@ pointer_set_cursor (struct wl_client *client,
 
   if (surface)
     {
+      MetaCursorRenderer *cursor_renderer =
+        meta_backend_get_cursor_renderer (meta_get_backend ());
       MetaWaylandSurfaceRoleCursor *cursor_role;
 
       cursor_role = META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
-      if (!cursor_role->cursor_sprite)
-        {
-          cursor_role->cursor_sprite = meta_cursor_sprite_new ();
-          g_signal_connect_object (cursor_role->cursor_sprite,
-                                   "prepare-at",
-                                   G_CALLBACK (cursor_sprite_prepare_at),
-                                   cursor_role,
-                                   0);
-        }
-
-      cursor_role->hot_x = hot_x;
-      cursor_role->hot_y = hot_y;
-
-      update_cursor_sprite_texture (surface);
+      meta_wayland_surface_role_cursor_set_renderer (cursor_role,
+                                                     cursor_renderer);
+      meta_wayland_surface_role_cursor_set_hotspot (cursor_role,
+                                                    hot_x, hot_y);
     }
 
   meta_wayland_pointer_set_cursor_surface (pointer, surface);
@@ -960,99 +906,3 @@ meta_wayland_pointer_get_top_popup (MetaWaylandPointer *pointer)
   grab = (MetaWaylandPopupGrab*)pointer->grab;
   return meta_wayland_popup_grab_get_top_popup(grab);
 }
-
-static void
-cursor_surface_role_assigned (MetaWaylandSurfaceRole *surface_role)
-{
-  MetaWaylandSurface *surface =
-    meta_wayland_surface_role_get_surface (surface_role);
-
-  meta_wayland_surface_queue_pending_frame_callbacks (surface);
-}
-
-static void
-cursor_surface_role_commit (MetaWaylandSurfaceRole  *surface_role,
-                            MetaWaylandPendingState *pending)
-{
-  MetaWaylandSurface *surface =
-    meta_wayland_surface_role_get_surface (surface_role);
-
-  meta_wayland_surface_queue_pending_state_frame_callbacks (surface, pending);
-
-  if (pending->newly_attached)
-    update_cursor_sprite_texture (surface);
-}
-
-static gboolean
-cursor_surface_role_is_on_output (MetaWaylandSurfaceRole *role,
-                                  MetaMonitorInfo        *monitor)
-{
-  MetaWaylandSurface *surface =
-    meta_wayland_surface_role_get_surface (role);
-  MetaWaylandPointer *pointer = &surface->compositor->seat->pointer;
-  MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
-  MetaCursorRenderer *cursor_renderer =
-    meta_backend_get_cursor_renderer (meta_get_backend ());
-  MetaWaylandSurfaceRoleCursor *cursor_role =
-    META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
-  MetaCursorSprite *displayed_cursor_sprite;
-  MetaRectangle rect;
-
-  if (surface != pointer->cursor_surface)
-    return FALSE;
-
-  displayed_cursor_sprite =
-    meta_cursor_tracker_get_displayed_cursor (cursor_tracker);
-  if (!displayed_cursor_sprite)
-    return FALSE;
-
-  if (cursor_role->cursor_sprite != displayed_cursor_sprite)
-    return FALSE;
-
-  rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
-                                              cursor_role->cursor_sprite);
-  return meta_rectangle_overlap (&rect, &monitor->rect);
-}
-
-static void
-cursor_surface_role_dispose (GObject *object)
-{
-  MetaWaylandSurfaceRoleCursor *cursor_role =
-    META_WAYLAND_SURFACE_ROLE_CURSOR (object);
-  MetaWaylandSurface *surface =
-    meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (object));
-  MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
-  MetaWaylandPointer *pointer = &compositor->seat->pointer;
-  MetaCursorTracker *cursor_tracker = meta_cursor_tracker_get_for_screen (NULL);
-
-  g_signal_handlers_disconnect_by_func (cursor_tracker,
-                                        (gpointer) cursor_sprite_prepare_at,
-                                        cursor_role);
-
-  if (pointer->cursor_surface == surface)
-    pointer->cursor_surface = NULL;
-  meta_wayland_pointer_update_cursor_surface (pointer);
-
-  g_clear_object (&cursor_role->cursor_sprite);
-
-  G_OBJECT_CLASS (meta_wayland_surface_role_cursor_parent_class)->dispose (object);
-}
-
-static void
-meta_wayland_surface_role_cursor_init (MetaWaylandSurfaceRoleCursor *role)
-{
-}
-
-static void
-meta_wayland_surface_role_cursor_class_init (MetaWaylandSurfaceRoleCursorClass *klass)
-{
-  MetaWaylandSurfaceRoleClass *surface_role_class =
-    META_WAYLAND_SURFACE_ROLE_CLASS (klass);
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-  surface_role_class->assigned = cursor_surface_role_assigned;
-  surface_role_class->commit = cursor_surface_role_commit;
-  surface_role_class->is_on_output = cursor_surface_role_is_on_output;
-
-  object_class->dispose = cursor_surface_role_dispose;
-}
diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h
index 7e31da9..162b6d9 100644
--- a/src/wayland/meta-wayland-pointer.h
+++ b/src/wayland/meta-wayland-pointer.h
@@ -31,12 +31,6 @@
 
 #include <meta/meta-cursor-tracker.h>
 
-#define META_TYPE_WAYLAND_SURFACE_ROLE_CURSOR (meta_wayland_surface_role_cursor_get_type ())
-G_DECLARE_FINAL_TYPE (MetaWaylandSurfaceRoleCursor,
-                      meta_wayland_surface_role_cursor,
-                      META, WAYLAND_SURFACE_ROLE_CURSOR,
-                      MetaWaylandSurfaceRole);
-
 struct _MetaWaylandPointerGrabInterface
 {
   void (*focus) (MetaWaylandPointerGrab *grab,
@@ -73,6 +67,7 @@ struct _MetaWaylandPointer
   guint32 click_serial;
 
   MetaWaylandSurface *cursor_surface;
+  guint cursor_surface_destroy_id;
 
   MetaWaylandPointerGrab *grab;
   MetaWaylandPointerGrab default_grab;
@@ -142,4 +137,8 @@ MetaWaylandPointerClient * meta_wayland_pointer_get_pointer_client (MetaWaylandP
                                                                     struct wl_client   *client);
 void meta_wayland_pointer_unbind_pointer_client_resource (struct wl_resource *resource);
 
+void meta_wayland_surface_cursor_update (MetaWaylandSurface *cursor_surface);
+
+void meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer);
+
 #endif /* META_WAYLAND_POINTER_H */
diff --git a/src/wayland/meta-wayland-surface-role-cursor.c b/src/wayland/meta-wayland-surface-role-cursor.c
new file mode 100644
index 0000000..74e0aa8
--- /dev/null
+++ b/src/wayland/meta-wayland-surface-role-cursor.c
@@ -0,0 +1,233 @@
+/*
+ * Wayland Support
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <cogl/cogl.h>
+#include <cogl/cogl-wayland-server.h>
+#include "meta-wayland-surface-role-cursor.h"
+#include "meta-wayland-buffer.h"
+#include "meta-xwayland.h"
+#include "screen-private.h"
+
+struct _MetaWaylandSurfaceRoleCursor
+{
+  MetaWaylandSurfaceRole parent;
+
+  int hot_x;
+  int hot_y;
+  MetaCursorSprite *cursor_sprite;
+  MetaCursorRenderer *cursor_renderer;
+};
+
+G_DEFINE_TYPE (MetaWaylandSurfaceRoleCursor,
+               meta_wayland_surface_role_cursor,
+               META_TYPE_WAYLAND_SURFACE_ROLE);
+
+static void
+update_cursor_sprite_texture (MetaWaylandSurfaceRoleCursor *cursor_role)
+{
+  MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE 
(cursor_role));
+  MetaCursorSprite *cursor_sprite = cursor_role->cursor_sprite;
+  ClutterBackend *clutter_backend = clutter_get_default_backend ();
+  CoglContext *cogl_context =
+    clutter_backend_get_cogl_context (clutter_backend);
+  CoglTexture *texture;
+
+  if (!cursor_role->cursor_renderer || !cursor_role->cursor_sprite)
+    return;
+
+  if (surface->buffer)
+    {
+      struct wl_resource *buffer;
+
+      buffer = surface->buffer->resource;
+      texture = cogl_wayland_texture_2d_new_from_buffer (cogl_context,
+                                                         buffer,
+                                                         NULL);
+
+      meta_cursor_sprite_set_texture (cursor_sprite,
+                                      texture,
+                                      cursor_role->hot_x * surface->scale,
+                                      cursor_role->hot_y * surface->scale);
+      meta_cursor_renderer_realize_cursor_from_wl_buffer (cursor_role->cursor_renderer,
+                                                          cursor_sprite,
+                                                          buffer);
+      cogl_object_unref (texture);
+    }
+  else
+    {
+      meta_cursor_sprite_set_texture (cursor_sprite, NULL, 0, 0);
+    }
+
+  meta_cursor_renderer_force_update (cursor_role->cursor_renderer);
+}
+
+static void
+cursor_sprite_prepare_at (MetaCursorSprite             *cursor_sprite,
+                          int                           x,
+                          int                           y,
+                          MetaWaylandSurfaceRoleCursor *cursor_role)
+{
+  MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_role);
+  MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role);
+  MetaDisplay *display = meta_get_display ();
+  MetaScreen *screen = display->screen;
+  const MetaMonitorInfo *monitor;
+
+  if (!meta_xwayland_is_xwayland_surface (surface))
+    {
+      monitor = meta_screen_get_monitor_for_point (screen, x, y);
+      meta_cursor_sprite_set_texture_scale (cursor_sprite,
+                                            (float)monitor->scale / surface->scale);
+    }
+  meta_wayland_surface_update_outputs (surface);
+}
+
+static void
+cursor_surface_role_assigned (MetaWaylandSurfaceRole *surface_role)
+{
+  MetaWaylandSurface *surface =
+    meta_wayland_surface_role_get_surface (surface_role);
+
+  meta_wayland_surface_queue_pending_frame_callbacks (surface);
+}
+
+static void
+cursor_surface_role_commit (MetaWaylandSurfaceRole  *surface_role,
+                            MetaWaylandPendingState *pending)
+{
+  MetaWaylandSurface *surface =
+    meta_wayland_surface_role_get_surface (surface_role);
+
+  meta_wayland_surface_queue_pending_state_frame_callbacks (surface, pending);
+
+  if (pending->newly_attached)
+    update_cursor_sprite_texture (META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role));
+}
+
+static gboolean
+cursor_surface_role_is_on_output (MetaWaylandSurfaceRole *role,
+                                  MetaMonitorInfo        *monitor)
+{
+  MetaWaylandSurface *surface =
+    meta_wayland_surface_role_get_surface (role);
+  MetaWaylandSurfaceRoleCursor *cursor_role =
+    META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
+  MetaRectangle rect;
+
+  rect = meta_cursor_renderer_calculate_rect (cursor_role->cursor_renderer,
+                                              cursor_role->cursor_sprite);
+  return meta_rectangle_overlap (&rect, &monitor->rect);
+}
+
+static void
+cursor_surface_role_dispose (GObject *object)
+{
+  MetaWaylandSurfaceRoleCursor *cursor_role =
+    META_WAYLAND_SURFACE_ROLE_CURSOR (object);
+
+  g_signal_handlers_disconnect_by_func (cursor_role->cursor_sprite,
+                                        cursor_sprite_prepare_at, cursor_role);
+
+  g_clear_object (&cursor_role->cursor_renderer);
+  g_clear_object (&cursor_role->cursor_sprite);
+
+  G_OBJECT_CLASS (meta_wayland_surface_role_cursor_parent_class)->dispose (object);
+}
+
+static void
+meta_wayland_surface_role_cursor_init (MetaWaylandSurfaceRoleCursor *role)
+{
+  role->cursor_sprite = meta_cursor_sprite_new ();
+  g_signal_connect_object (role->cursor_sprite,
+                           "prepare-at",
+                           G_CALLBACK (cursor_sprite_prepare_at),
+                           role,
+                           0);
+}
+
+static void
+meta_wayland_surface_role_cursor_class_init (MetaWaylandSurfaceRoleCursorClass *klass)
+{
+  MetaWaylandSurfaceRoleClass *surface_role_class =
+    META_WAYLAND_SURFACE_ROLE_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  surface_role_class->assigned = cursor_surface_role_assigned;
+  surface_role_class->commit = cursor_surface_role_commit;
+  surface_role_class->is_on_output = cursor_surface_role_is_on_output;
+
+  object_class->dispose = cursor_surface_role_dispose;
+}
+
+MetaCursorSprite *
+meta_wayland_surface_role_cursor_get_sprite (MetaWaylandSurfaceRoleCursor *cursor_role)
+{
+  return cursor_role->cursor_sprite;
+}
+
+void
+meta_wayland_surface_role_cursor_set_hotspot (MetaWaylandSurfaceRoleCursor *cursor_role,
+                                              gint                          hotspot_x,
+                                              gint                          hotspot_y)
+{
+  if (cursor_role->hot_x == hotspot_x &&
+      cursor_role->hot_y == hotspot_y)
+    return;
+
+  cursor_role->hot_x = hotspot_x;
+  cursor_role->hot_y = hotspot_y;
+  update_cursor_sprite_texture (cursor_role);
+}
+
+void
+meta_wayland_surface_role_cursor_get_hotspot (MetaWaylandSurfaceRoleCursor *cursor_role,
+                                              gint                         *hotspot_x,
+                                              gint                         *hotspot_y)
+{
+  if (hotspot_x)
+    *hotspot_x = cursor_role->hot_x;
+  if (hotspot_y)
+    *hotspot_y = cursor_role->hot_y;
+}
+
+void
+meta_wayland_surface_role_cursor_set_renderer (MetaWaylandSurfaceRoleCursor *cursor_role,
+                                               MetaCursorRenderer           *renderer)
+{
+  if (cursor_role->cursor_renderer == renderer)
+    return;
+
+  if (renderer)
+    g_object_ref (renderer);
+  if (cursor_role->cursor_renderer)
+    g_object_unref (cursor_role->cursor_renderer);
+
+  cursor_role->cursor_renderer = renderer;
+  update_cursor_sprite_texture (cursor_role);
+}
+
+MetaCursorRenderer *
+meta_wayland_surface_role_cursor_get_renderer (MetaWaylandSurfaceRoleCursor *cursor_role)
+{
+  return cursor_role->cursor_renderer;
+}
diff --git a/src/wayland/meta-wayland-surface-role-cursor.h b/src/wayland/meta-wayland-surface-role-cursor.h
new file mode 100644
index 0000000..6389971
--- /dev/null
+++ b/src/wayland/meta-wayland-surface-role-cursor.h
@@ -0,0 +1,46 @@
+/*
+ * Wayland Support
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef META_WAYLAND_SURFACE_ROLE_CURSOR_H
+#define META_WAYLAND_SURFACE_ROLE_CURSOR_H
+
+#include "meta-wayland-surface.h"
+
+#define META_TYPE_WAYLAND_SURFACE_ROLE_CURSOR (meta_wayland_surface_role_cursor_get_type ())
+G_DECLARE_FINAL_TYPE (MetaWaylandSurfaceRoleCursor,
+                      meta_wayland_surface_role_cursor,
+                      META, WAYLAND_SURFACE_ROLE_CURSOR,
+                      MetaWaylandSurfaceRole);
+
+MetaCursorSprite *   meta_wayland_surface_role_cursor_get_sprite   (MetaWaylandSurfaceRoleCursor 
*cursor_role);
+
+void                 meta_wayland_surface_role_cursor_set_hotspot  (MetaWaylandSurfaceRoleCursor 
*cursor_role,
+                                                                    gint                          hotspot_x,
+                                                                    gint                          hotspot_y);
+void                 meta_wayland_surface_role_cursor_get_hotspot  (MetaWaylandSurfaceRoleCursor 
*cursor_role,
+                                                                    gint                         *hotspot_x,
+                                                                    gint                         *hotspot_y);
+void                 meta_wayland_surface_role_cursor_set_renderer (MetaWaylandSurfaceRoleCursor 
*cursor_role,
+                                                                    MetaCursorRenderer           *renderer);
+MetaCursorRenderer * meta_wayland_surface_role_cursor_get_renderer (MetaWaylandSurfaceRoleCursor 
*cursor_role);
+
+
+#endif /* META_WAYLAND_SURFACE_ROLE_CURSOR_H */
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index 5f8cc49..c038522 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -54,6 +54,7 @@
 #include "meta-surface-actor.h"
 #include "meta-surface-actor-wayland.h"
 #include "meta-xwayland-private.h"
+#include "meta-xwayland.h"
 
 typedef struct _MetaWaylandSurfaceRolePrivate
 {
diff --git a/src/wayland/meta-wayland-surface.h b/src/wayland/meta-wayland-surface.h
index 03af951..46a4e29 100644
--- a/src/wayland/meta-wayland-surface.h
+++ b/src/wayland/meta-wayland-surface.h
@@ -31,6 +31,7 @@
 #include "meta-wayland-types.h"
 #include "meta-surface-actor.h"
 #include "backends/meta-monitor-manager-private.h"
+#include "backends/meta-cursor-renderer.h"
 
 typedef struct _MetaWaylandPendingState MetaWaylandPendingState;
 


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