Blame SOURCES/hw-cursor-on-demand-gnome-3-28.patch

f73620
diff --git a/src/Makefile.am b/src/Makefile.am
f73620
index bcb3505c7..5bbac70e8 100644
f73620
--- a/src/Makefile.am
f73620
+++ b/src/Makefile.am
f73620
@@ -114,6 +114,8 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES =	\
f73620
 	backends/meta-cursor-tracker-private.h	\
f73620
 	backends/meta-cursor-renderer.c		\
f73620
 	backends/meta-cursor-renderer.h		\
f73620
+	backends/meta-cursor-sprite-xcursor.c	\
f73620
+	backends/meta-cursor-sprite-xcursor.h	\
f73620
 	backends/meta-dnd-private.h		\
f73620
 	backends/meta-egl.c			\
f73620
 	backends/meta-egl.h			\
f73620
@@ -176,6 +178,8 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES =	\
f73620
 	backends/x11/meta-gpu-xrandr.h			\
f73620
 	backends/x11/cm/meta-backend-x11-cm.c		\
f73620
 	backends/x11/cm/meta-backend-x11-cm.h		\
f73620
+	backends/x11/cm/meta-cursor-sprite-xfixes.c	\
f73620
+	backends/x11/cm/meta-cursor-sprite-xfixes.h	\
f73620
 	backends/x11/cm/meta-renderer-x11-cm.c		\
f73620
 	backends/x11/cm/meta-renderer-x11-cm.h		\
f73620
 	backends/x11/nested/meta-backend-x11-nested.c	\
f73620
@@ -370,6 +374,8 @@ if HAVE_WAYLAND
f73620
 libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES +=	\
f73620
 	compositor/meta-surface-actor-wayland.c	\
f73620
 	compositor/meta-surface-actor-wayland.h	\
f73620
+	wayland/meta-cursor-sprite-wayland.c	\
f73620
+	wayland/meta-cursor-sprite-wayland.h	\
f73620
 	wayland/meta-wayland.c			\
f73620
 	wayland/meta-wayland.h			\
f73620
 	wayland/meta-wayland-private.h		\
f73620
@@ -431,10 +437,10 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES +=	\
f73620
 	wayland/meta-wayland-touch.h		\
f73620
 	wayland/meta-wayland-surface.c		\
f73620
 	wayland/meta-wayland-surface.h		\
f73620
-	wayland/meta-wayland-surface-role-cursor.c	\
f73620
-	wayland/meta-wayland-surface-role-cursor.h	\
f73620
-	wayland/meta-wayland-surface-role-tablet-cursor.c	\
f73620
-	wayland/meta-wayland-surface-role-tablet-cursor.h	\
f73620
+	wayland/meta-wayland-cursor-surface.c	\
f73620
+	wayland/meta-wayland-cursor-surface.h	\
f73620
+	wayland/meta-wayland-tablet-cursor-surface.c	\
f73620
+	wayland/meta-wayland-tablet-cursor-surface.h	\
f73620
 	wayland/meta-wayland-actor-surface.c	\
f73620
 	wayland/meta-wayland-actor-surface.h	\
f73620
 	wayland/meta-wayland-subsurface.c	\
f73620
diff --git a/src/backends/meta-cursor-renderer.c b/src/backends/meta-cursor-renderer.c
f73620
index f6470e66a..eb79737f1 100644
f73620
--- a/src/backends/meta-cursor-renderer.c
f73620
+++ b/src/backends/meta-cursor-renderer.c
f73620
@@ -193,8 +193,8 @@ meta_cursor_renderer_calculate_rect (MetaCursorRenderer *renderer,
f73620
 }
f73620
 
f73620
 static void
f73620
-update_cursor (MetaCursorRenderer *renderer,
f73620
-               MetaCursorSprite   *cursor_sprite)
f73620
+meta_cursor_renderer_update_cursor (MetaCursorRenderer *renderer,
f73620
+                                    MetaCursorSprite   *cursor_sprite)
f73620
 {
f73620
   MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
f73620
   gboolean handled_by_backend;
f73620
@@ -237,7 +237,7 @@ meta_cursor_renderer_set_cursor (MetaCursorRenderer *renderer,
f73620
     return;
f73620
   priv->displayed_cursor = cursor_sprite;
f73620
 
f73620
-  update_cursor (renderer, cursor_sprite);
f73620
+  meta_cursor_renderer_update_cursor (renderer, cursor_sprite);
f73620
 }
f73620
 
f73620
 void
f73620
@@ -246,7 +246,7 @@ meta_cursor_renderer_force_update (MetaCursorRenderer *renderer)
f73620
   MetaCursorRendererPrivate *priv =
f73620
     meta_cursor_renderer_get_instance_private (renderer);
f73620
 
f73620
-  update_cursor (renderer, priv->displayed_cursor);
f73620
+  meta_cursor_renderer_update_cursor (renderer, priv->displayed_cursor);
f73620
 }
f73620
 
f73620
 void
f73620
@@ -261,7 +261,7 @@ meta_cursor_renderer_set_position (MetaCursorRenderer *renderer,
f73620
   priv->current_x = x;
f73620
   priv->current_y = y;
f73620
 
f73620
-  update_cursor (renderer, priv->displayed_cursor);
f73620
+  meta_cursor_renderer_update_cursor (renderer, priv->displayed_cursor);
f73620
 }
f73620
 
f73620
 ClutterPoint
f73620
@@ -283,28 +283,3 @@ meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer)
f73620
 
f73620
   return priv->displayed_cursor;
f73620
 }
f73620
-
f73620
-#ifdef HAVE_WAYLAND
f73620
-void
f73620
-meta_cursor_renderer_realize_cursor_from_wl_buffer (MetaCursorRenderer *renderer,
f73620
-                                                    MetaCursorSprite   *cursor_sprite,
f73620
-                                                    struct wl_resource *buffer)
f73620
-{
f73620
-
f73620
-  MetaCursorRendererClass *renderer_class = META_CURSOR_RENDERER_GET_CLASS (renderer);
f73620
-
f73620
-  if (renderer_class->realize_cursor_from_wl_buffer)
f73620
-    renderer_class->realize_cursor_from_wl_buffer (renderer, cursor_sprite, buffer);
f73620
-}
f73620
-#endif
f73620
-
f73620
-void
f73620
-meta_cursor_renderer_realize_cursor_from_xcursor (MetaCursorRenderer *renderer,
f73620
-                                                  MetaCursorSprite   *cursor_sprite,
f73620
-                                                  XcursorImage       *xc_image)
f73620
-{
f73620
-  MetaCursorRendererClass *renderer_class = META_CURSOR_RENDERER_GET_CLASS (renderer);
f73620
-
f73620
-  if (renderer_class->realize_cursor_from_xcursor)
f73620
-    renderer_class->realize_cursor_from_xcursor (renderer, cursor_sprite, xc_image);
f73620
-}
f73620
diff --git a/src/backends/meta-cursor-renderer.h b/src/backends/meta-cursor-renderer.h
f73620
index 1691f4471..830d16ef6 100644
f73620
--- a/src/backends/meta-cursor-renderer.h
f73620
+++ b/src/backends/meta-cursor-renderer.h
f73620
@@ -26,10 +26,6 @@
f73620
 #define META_CURSOR_RENDERER_H
f73620
 
f73620
 #include <glib-object.h>
f73620
-#include <X11/Xcursor/Xcursor.h>
f73620
-#ifdef HAVE_WAYLAND
f73620
-#include <wayland-server.h>
f73620
-#endif
f73620
 
f73620
 #include <meta/screen.h>
f73620
 #include "meta-cursor.h"
f73620
@@ -44,14 +40,6 @@ struct _MetaCursorRendererClass
f73620
 
f73620
   gboolean (* update_cursor) (MetaCursorRenderer *renderer,
f73620
                               MetaCursorSprite   *cursor_sprite);
f73620
-#ifdef HAVE_WAYLAND
f73620
-  void (* realize_cursor_from_wl_buffer) (MetaCursorRenderer *renderer,
f73620
-                                          MetaCursorSprite *cursor_sprite,
f73620
-                                          struct wl_resource *buffer);
f73620
-#endif
f73620
-  void (* realize_cursor_from_xcursor) (MetaCursorRenderer *renderer,
f73620
-                                        MetaCursorSprite *cursor_sprite,
f73620
-                                        XcursorImage *xc_image);
f73620
 };
f73620
 
f73620
 MetaCursorRenderer * meta_cursor_renderer_new (void);
f73620
@@ -70,16 +58,6 @@ MetaCursorSprite * meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer
f73620
 ClutterRect meta_cursor_renderer_calculate_rect (MetaCursorRenderer *renderer,
f73620
                                                  MetaCursorSprite   *cursor_sprite);
f73620
 
f73620
-#ifdef HAVE_WAYLAND
f73620
-void meta_cursor_renderer_realize_cursor_from_wl_buffer (MetaCursorRenderer *renderer,
f73620
-                                                         MetaCursorSprite   *cursor_sprite,
f73620
-                                                         struct wl_resource *buffer);
f73620
-#endif
f73620
-
f73620
-void meta_cursor_renderer_realize_cursor_from_xcursor (MetaCursorRenderer *renderer,
f73620
-                                                       MetaCursorSprite   *cursor_sprite,
f73620
-                                                       XcursorImage       *xc_image);
f73620
-
f73620
 void meta_cursor_renderer_emit_painted (MetaCursorRenderer *renderer,
f73620
                                         MetaCursorSprite   *cursor_sprite);
f73620
 
f73620
diff --git a/src/backends/meta-cursor-sprite-xcursor.c b/src/backends/meta-cursor-sprite-xcursor.c
f73620
new file mode 100644
f73620
index 000000000..657c1dae8
f73620
--- /dev/null
f73620
+++ b/src/backends/meta-cursor-sprite-xcursor.c
f73620
@@ -0,0 +1,292 @@
f73620
+/*
f73620
+ * Copyright 2013, 2018 Red Hat, Inc.
f73620
+ *
f73620
+ * This program is free software; you can redistribute it and/or
f73620
+ * modify it under the terms of the GNU General Public License as
f73620
+ * published by the Free Software Foundation; either version 2 of the
f73620
+ * License, or (at your option) any later version.
f73620
+ *
f73620
+ * This program is distributed in the hope that it will be useful, but
f73620
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
f73620
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f73620
+ * General Public License for more details.
f73620
+ *
f73620
+ * You should have received a copy of the GNU General Public License
f73620
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
f73620
+ *
f73620
+ */
f73620
+
f73620
+#include "config.h"
f73620
+
f73620
+#include "backends/meta-cursor-sprite-xcursor.h"
f73620
+
f73620
+#include "backends/meta-cursor.h"
f73620
+#include "backends/meta-cursor-renderer.h"
f73620
+#include "clutter/clutter.h"
f73620
+#include "cogl/cogl.h"
f73620
+#include "meta/prefs.h"
f73620
+
f73620
+struct _MetaCursorSpriteXcursor
f73620
+{
f73620
+  MetaCursorSprite parent;
f73620
+
f73620
+  MetaCursor cursor;
f73620
+
f73620
+  int current_frame;
f73620
+  XcursorImages *xcursor_images;
f73620
+
f73620
+  int theme_scale;
f73620
+  gboolean theme_dirty;
f73620
+};
f73620
+
f73620
+G_DEFINE_TYPE (MetaCursorSpriteXcursor, meta_cursor_sprite_xcursor,
f73620
+               META_TYPE_CURSOR_SPRITE)
f73620
+
f73620
+static const char *
f73620
+translate_meta_cursor (MetaCursor cursor)
f73620
+{
f73620
+  switch (cursor)
f73620
+    {
f73620
+    case META_CURSOR_DEFAULT:
f73620
+      return "left_ptr";
f73620
+    case META_CURSOR_NORTH_RESIZE:
f73620
+      return "top_side";
f73620
+    case META_CURSOR_SOUTH_RESIZE:
f73620
+      return "bottom_side";
f73620
+    case META_CURSOR_WEST_RESIZE:
f73620
+      return "left_side";
f73620
+    case META_CURSOR_EAST_RESIZE:
f73620
+      return "right_side";
f73620
+    case META_CURSOR_SE_RESIZE:
f73620
+      return "bottom_right_corner";
f73620
+    case META_CURSOR_SW_RESIZE:
f73620
+      return "bottom_left_corner";
f73620
+    case META_CURSOR_NE_RESIZE:
f73620
+      return "top_right_corner";
f73620
+    case META_CURSOR_NW_RESIZE:
f73620
+      return "top_left_corner";
f73620
+    case META_CURSOR_MOVE_OR_RESIZE_WINDOW:
f73620
+      return "fleur";
f73620
+    case META_CURSOR_BUSY:
f73620
+      return "watch";
f73620
+    case META_CURSOR_DND_IN_DRAG:
f73620
+      return "dnd-none";
f73620
+    case META_CURSOR_DND_MOVE:
f73620
+      return "dnd-move";
f73620
+    case META_CURSOR_DND_COPY:
f73620
+      return "dnd-copy";
f73620
+    case META_CURSOR_DND_UNSUPPORTED_TARGET:
f73620
+      return "dnd-none";
f73620
+    case META_CURSOR_POINTING_HAND:
f73620
+      return "hand2";
f73620
+    case META_CURSOR_CROSSHAIR:
f73620
+      return "crosshair";
f73620
+    case META_CURSOR_IBEAM:
f73620
+      return "xterm";
f73620
+    default:
f73620
+      break;
f73620
+    }
f73620
+
f73620
+  g_assert_not_reached ();
f73620
+}
f73620
+
f73620
+MetaCursor
f73620
+meta_cursor_sprite_xcursor_get_cursor (MetaCursorSpriteXcursor *sprite_xcursor)
f73620
+{
f73620
+  return sprite_xcursor->cursor;
f73620
+}
f73620
+
f73620
+Cursor
f73620
+meta_create_x_cursor (Display    *xdisplay,
f73620
+                      MetaCursor  cursor)
f73620
+{
f73620
+  return XcursorLibraryLoadCursor (xdisplay, translate_meta_cursor (cursor));
f73620
+}
f73620
+
f73620
+static XcursorImages *
f73620
+load_cursor_on_client (MetaCursor cursor, int scale)
f73620
+{
f73620
+  return XcursorLibraryLoadImages (translate_meta_cursor (cursor),
f73620
+                                   meta_prefs_get_cursor_theme (),
f73620
+                                   meta_prefs_get_cursor_size () * scale);
f73620
+}
f73620
+
f73620
+static void
f73620
+load_from_current_xcursor_image (MetaCursorSpriteXcursor *sprite_xcursor)
f73620
+{
f73620
+  MetaCursorSprite *sprite = META_CURSOR_SPRITE (sprite_xcursor);
f73620
+  XcursorImage *xc_image;
f73620
+  int width, height, rowstride;
f73620
+  CoglPixelFormat cogl_format;
f73620
+  ClutterBackend *clutter_backend;
f73620
+  CoglContext *cogl_context;
f73620
+  CoglTexture2D *texture;
f73620
+  CoglError *error = NULL;
f73620
+
f73620
+  g_assert (!meta_cursor_sprite_get_cogl_texture (sprite));
f73620
+
f73620
+  xc_image = meta_cursor_sprite_xcursor_get_current_image (sprite_xcursor);
f73620
+  width = (int) xc_image->width;
f73620
+  height = (int) xc_image->height;
f73620
+  rowstride = width * 4;
f73620
+
f73620
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
f73620
+  cogl_format = COGL_PIXEL_FORMAT_BGRA_8888;
f73620
+#else
f73620
+  cogl_format = COGL_PIXEL_FORMAT_ARGB_8888;
f73620
+#endif
f73620
+
f73620
+  clutter_backend = clutter_get_default_backend ();
f73620
+  cogl_context = clutter_backend_get_cogl_context (clutter_backend);
f73620
+  texture = cogl_texture_2d_new_from_data (cogl_context,
f73620
+                                           width, height,
f73620
+                                           cogl_format,
f73620
+                                           rowstride,
f73620
+                                           (uint8_t *) xc_image->pixels,
f73620
+                                           &error);
f73620
+  if (!texture)
f73620
+    {
f73620
+      g_warning ("Failed to allocate cursor texture: %s\n", error->message);
f73620
+      cogl_error_free (error);
f73620
+    }
f73620
+
f73620
+  meta_cursor_sprite_set_texture (sprite,
f73620
+                                  COGL_TEXTURE (texture),
f73620
+                                  xc_image->xhot, xc_image->yhot);
f73620
+
f73620
+  if (texture)
f73620
+    cogl_object_unref (texture);
f73620
+}
f73620
+
f73620
+void
f73620
+meta_cursor_sprite_xcursor_set_theme_scale (MetaCursorSpriteXcursor *sprite_xcursor,
f73620
+                                            int                      theme_scale)
f73620
+{
f73620
+  if (sprite_xcursor->theme_scale != theme_scale)
f73620
+    sprite_xcursor->theme_dirty = TRUE;
f73620
+  sprite_xcursor->theme_scale = theme_scale;
f73620
+}
f73620
+
f73620
+
f73620
+static gboolean
f73620
+meta_cursor_sprite_xcursor_is_animated (MetaCursorSprite *sprite)
f73620
+{
f73620
+  MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (sprite);
f73620
+
f73620
+  return (sprite_xcursor->xcursor_images &&
f73620
+          sprite_xcursor->xcursor_images->nimage > 1);
f73620
+}
f73620
+
f73620
+XcursorImage *
f73620
+meta_cursor_sprite_xcursor_get_current_image (MetaCursorSpriteXcursor *sprite_xcursor)
f73620
+{
f73620
+  return sprite_xcursor->xcursor_images->images[sprite_xcursor->current_frame];
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_xcursor_tick_frame (MetaCursorSprite *sprite)
f73620
+{
f73620
+  MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (sprite);
f73620
+
f73620
+  if (!meta_cursor_sprite_is_animated (sprite))
f73620
+    return;
f73620
+
f73620
+  sprite_xcursor->current_frame++;
f73620
+
f73620
+  if (sprite_xcursor->current_frame >= sprite_xcursor->xcursor_images->nimage)
f73620
+    sprite_xcursor->current_frame = 0;
f73620
+
f73620
+  meta_cursor_sprite_clear_texture (sprite);
f73620
+  load_from_current_xcursor_image (sprite_xcursor);
f73620
+}
f73620
+
f73620
+static unsigned int
f73620
+meta_cursor_sprite_xcursor_get_current_frame_time (MetaCursorSprite *sprite)
f73620
+{
f73620
+  MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (sprite);
f73620
+  XcursorImages *xcursor_images;
f73620
+
f73620
+  g_return_val_if_fail (meta_cursor_sprite_is_animated (sprite), 0);
f73620
+
f73620
+  xcursor_images = sprite_xcursor->xcursor_images;
f73620
+  return xcursor_images->images[sprite_xcursor->current_frame]->delay;
f73620
+}
f73620
+
f73620
+static void
f73620
+load_cursor_from_theme (MetaCursorSprite *sprite)
f73620
+{
f73620
+  MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (sprite);
f73620
+
f73620
+  g_assert (sprite_xcursor->cursor != META_CURSOR_NONE);
f73620
+
f73620
+  sprite_xcursor->theme_dirty = FALSE;
f73620
+
f73620
+  /* We might be reloading with a different scale. If so clear the old data. */
f73620
+  if (sprite_xcursor->xcursor_images)
f73620
+    {
f73620
+      meta_cursor_sprite_clear_texture (sprite);
f73620
+      XcursorImagesDestroy (sprite_xcursor->xcursor_images);
f73620
+    }
f73620
+
f73620
+  sprite_xcursor->current_frame = 0;
f73620
+  sprite_xcursor->xcursor_images =
f73620
+    load_cursor_on_client (sprite_xcursor->cursor,
f73620
+                           sprite_xcursor->theme_scale);
f73620
+  if (!sprite_xcursor->xcursor_images)
f73620
+    g_error ("Could not find cursor. Perhaps set XCURSOR_PATH?");
f73620
+
f73620
+  load_from_current_xcursor_image (sprite_xcursor);
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_xcursor_realize_texture (MetaCursorSprite *sprite)
f73620
+{
f73620
+  MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (sprite);
f73620
+
f73620
+  if (sprite_xcursor->theme_dirty)
f73620
+    load_cursor_from_theme (sprite);
f73620
+}
f73620
+
f73620
+MetaCursorSpriteXcursor *
f73620
+meta_cursor_sprite_xcursor_new (MetaCursor cursor)
f73620
+{
f73620
+  MetaCursorSpriteXcursor *sprite_xcursor;
f73620
+
f73620
+  sprite_xcursor = g_object_new (META_TYPE_CURSOR_SPRITE_XCURSOR, NULL);
f73620
+  sprite_xcursor->cursor = cursor;
f73620
+
f73620
+  return sprite_xcursor;
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_xcursor_finalize (GObject *object)
f73620
+{
f73620
+  MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (object);
f73620
+
f73620
+  g_clear_pointer (&sprite_xcursor->xcursor_images,
f73620
+                   XcursorImagesDestroy);
f73620
+
f73620
+  G_OBJECT_CLASS (meta_cursor_sprite_xcursor_parent_class)->finalize (object);
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_xcursor_init (MetaCursorSpriteXcursor *sprite_xcursor)
f73620
+{
f73620
+  sprite_xcursor->theme_dirty = TRUE;
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_xcursor_class_init (MetaCursorSpriteXcursorClass *klass)
f73620
+{
f73620
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
f73620
+  MetaCursorSpriteClass *cursor_sprite_class = META_CURSOR_SPRITE_CLASS (klass);
f73620
+
f73620
+  object_class->finalize = meta_cursor_sprite_xcursor_finalize;
f73620
+
f73620
+  cursor_sprite_class->realize_texture =
f73620
+    meta_cursor_sprite_xcursor_realize_texture;
f73620
+  cursor_sprite_class->is_animated = meta_cursor_sprite_xcursor_is_animated;
f73620
+  cursor_sprite_class->tick_frame = meta_cursor_sprite_xcursor_tick_frame;
f73620
+  cursor_sprite_class->get_current_frame_time =
f73620
+    meta_cursor_sprite_xcursor_get_current_frame_time;
f73620
+}
f73620
diff --git a/src/backends/meta-cursor-sprite-xcursor.h b/src/backends/meta-cursor-sprite-xcursor.h
f73620
new file mode 100644
f73620
index 000000000..dbc927484
f73620
--- /dev/null
f73620
+++ b/src/backends/meta-cursor-sprite-xcursor.h
f73620
@@ -0,0 +1,43 @@
f73620
+/*
f73620
+ * Copyright 2013, 2018 Red Hat, Inc.
f73620
+ *
f73620
+ * This program is free software; you can redistribute it and/or
f73620
+ * modify it under the terms of the GNU General Public License as
f73620
+ * published by the Free Software Foundation; either version 2 of the
f73620
+ * License, or (at your option) any later version.
f73620
+ *
f73620
+ * This program is distributed in the hope that it will be useful, but
f73620
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
f73620
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f73620
+ * General Public License for more details.
f73620
+ *
f73620
+ * You should have received a copy of the GNU General Public License
f73620
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
f73620
+ *
f73620
+ */
f73620
+
f73620
+#ifndef META_CURSOR_SPRITE_XCURSOR_H
f73620
+#define META_CURSOR_SPRITE_XCURSOR_H
f73620
+
f73620
+#include <glib-object.h>
f73620
+#include <X11/Xcursor/Xcursor.h>
f73620
+
f73620
+#include "backends/meta-cursor.h"
f73620
+
f73620
+#define META_TYPE_CURSOR_SPRITE_XCURSOR meta_cursor_sprite_xcursor_get_type ()
f73620
+G_DECLARE_FINAL_TYPE (MetaCursorSpriteXcursor, meta_cursor_sprite_xcursor,
f73620
+                      META, CURSOR_SPRITE_XCURSOR, MetaCursorSprite)
f73620
+
f73620
+MetaCursorSpriteXcursor * meta_cursor_sprite_xcursor_new (MetaCursor cursor);
f73620
+
f73620
+void meta_cursor_sprite_xcursor_set_theme_scale (MetaCursorSpriteXcursor *sprite_xcursor,
f73620
+                                                 int                      scale);
f73620
+
f73620
+MetaCursor meta_cursor_sprite_xcursor_get_cursor (MetaCursorSpriteXcursor *sprite_xcusror);
f73620
+
f73620
+XcursorImage * meta_cursor_sprite_xcursor_get_current_image (MetaCursorSpriteXcursor *sprite_xcursor);
f73620
+
f73620
+Cursor meta_create_x_cursor (Display    *xdisplay,
f73620
+                             MetaCursor  cursor);
f73620
+
f73620
+#endif /* META_CURSOR_SPRITE_XCURSOR_H */
f73620
diff --git a/src/backends/meta-cursor-tracker-private.h b/src/backends/meta-cursor-tracker-private.h
f73620
index 2ec946847..6f4f84b83 100644
f73620
--- a/src/backends/meta-cursor-tracker-private.h
f73620
+++ b/src/backends/meta-cursor-tracker-private.h
f73620
@@ -26,6 +26,7 @@
f73620
 
f73620
 #include "meta-cursor.h"
f73620
 #include "meta-cursor-renderer.h"
f73620
+#include "backends/x11/cm/meta-cursor-sprite-xfixes.h"
f73620
 
f73620
 struct _MetaCursorTracker {
f73620
   GObject parent_instance;
f73620
@@ -46,7 +47,7 @@ struct _MetaCursorTracker {
f73620
   MetaCursorSprite *root_cursor;
f73620
 
f73620
   /* The cursor from the X11 server. */
f73620
-  MetaCursorSprite *xfixes_cursor;
f73620
+  MetaCursorSpriteXfixes *xfixes_cursor;
f73620
 };
f73620
 
f73620
 struct _MetaCursorTrackerClass {
f73620
diff --git a/src/backends/meta-cursor-tracker.c b/src/backends/meta-cursor-tracker.c
f73620
index 74fa4351d..6244f11ee 100644
f73620
--- a/src/backends/meta-cursor-tracker.c
f73620
+++ b/src/backends/meta-cursor-tracker.c
f73620
@@ -40,9 +40,9 @@
f73620
 
f73620
 #include <gdk/gdk.h>
f73620
 #include <gdk/gdkx.h>
f73620
-#include <X11/extensions/Xfixes.h>
f73620
 
f73620
 #include "meta-backend-private.h"
f73620
+#include "backends/x11/cm/meta-cursor-sprite-xfixes.h"
f73620
 
f73620
 G_DEFINE_TYPE (MetaCursorTracker, meta_cursor_tracker, G_TYPE_OBJECT);
f73620
 
f73620
@@ -218,75 +218,14 @@ static void
f73620
 ensure_xfixes_cursor (MetaCursorTracker *tracker)
f73620
 {
f73620
   MetaDisplay *display = meta_get_display ();
f73620
-  XFixesCursorImage *cursor_image;
f73620
-  CoglTexture2D *sprite;
f73620
-  guint8 *cursor_data;
f73620
-  gboolean free_cursor_data;
f73620
-  CoglContext *ctx;
f73620
-  CoglError *error = NULL;
f73620
+  g_autoptr (GError) error = NULL;
f73620
 
f73620
   if (tracker->xfixes_cursor)
f73620
     return;
f73620
 
f73620
-  cursor_image = XFixesGetCursorImage (display->xdisplay);
f73620
-  if (!cursor_image)
f73620
-    return;
f73620
-
f73620
-  /* Like all X APIs, XFixesGetCursorImage() returns arrays of 32-bit
f73620
-   * quantities as arrays of long; we need to convert on 64 bit */
f73620
-  if (sizeof(long) == 4)
f73620
-    {
f73620
-      cursor_data = (guint8 *)cursor_image->pixels;
f73620
-      free_cursor_data = FALSE;
f73620
-    }
f73620
-  else
f73620
-    {
f73620
-      int i, j;
f73620
-      guint32 *cursor_words;
f73620
-      gulong *p;
f73620
-      guint32 *q;
f73620
-
f73620
-      cursor_words = g_new (guint32, cursor_image->width * cursor_image->height);
f73620
-      cursor_data = (guint8 *)cursor_words;
f73620
-
f73620
-      p = cursor_image->pixels;
f73620
-      q = cursor_words;
f73620
-      for (j = 0; j < cursor_image->height; j++)
f73620
-        for (i = 0; i < cursor_image->width; i++)
f73620
-          *(q++) = *(p++);
f73620
-
f73620
-      free_cursor_data = TRUE;
f73620
-    }
f73620
-
f73620
-  ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
f73620
-  sprite = cogl_texture_2d_new_from_data (ctx,
f73620
-                                          cursor_image->width,
f73620
-                                          cursor_image->height,
f73620
-                                          CLUTTER_CAIRO_FORMAT_ARGB32,
f73620
-                                          cursor_image->width * 4, /* stride */
f73620
-                                          cursor_data,
f73620
-                                          &error);
f73620
-
f73620
-  if (free_cursor_data)
f73620
-    g_free (cursor_data);
f73620
-
f73620
-  if (error != NULL)
f73620
-    {
f73620
-      meta_warning ("Failed to allocate cursor sprite texture: %s\n", error->message);
f73620
-      cogl_error_free (error);
f73620
-    }
f73620
-
f73620
-  if (sprite != NULL)
f73620
-    {
f73620
-      MetaCursorSprite *cursor_sprite = meta_cursor_sprite_new ();
f73620
-      meta_cursor_sprite_set_texture (cursor_sprite,
f73620
-                                      COGL_TEXTURE (sprite),
f73620
-                                      cursor_image->xhot,
f73620
-                                      cursor_image->yhot);
f73620
-      cogl_object_unref (sprite);
f73620
-      tracker->xfixes_cursor = cursor_sprite;
f73620
-    }
f73620
-  XFree (cursor_image);
f73620
+  tracker->xfixes_cursor = meta_cursor_sprite_xfixes_new (display, &error);
f73620
+  if (!tracker->xfixes_cursor)
f73620
+    g_warning ("Failed to create XFIXES cursor: %s", error->message);
f73620
 }
f73620
 
f73620
 /**
f73620
@@ -308,7 +247,7 @@ meta_cursor_tracker_get_sprite (MetaCursorTracker *tracker)
f73620
   else
f73620
     {
f73620
       ensure_xfixes_cursor (tracker);
f73620
-      cursor_sprite = tracker->xfixes_cursor;
f73620
+      cursor_sprite = META_CURSOR_SPRITE (tracker->xfixes_cursor);
f73620
     }
f73620
 
f73620
   if (cursor_sprite)
f73620
@@ -345,7 +284,7 @@ meta_cursor_tracker_get_hot (MetaCursorTracker *tracker,
f73620
   else
f73620
     {
f73620
       ensure_xfixes_cursor (tracker);
f73620
-      cursor_sprite = tracker->xfixes_cursor;
f73620
+      cursor_sprite = META_CURSOR_SPRITE (tracker->xfixes_cursor);
f73620
     }
f73620
 
f73620
   if (cursor_sprite)
f73620
diff --git a/src/backends/meta-cursor.c b/src/backends/meta-cursor.c
f73620
index beeee765b..9750dc00b 100644
f73620
--- a/src/backends/meta-cursor.c
f73620
+++ b/src/backends/meta-cursor.c
f73620
@@ -23,19 +23,12 @@
f73620
 
f73620
 #include "meta-cursor.h"
f73620
 
f73620
-#include <meta/errors.h>
f73620
+#include "backends/meta-backend-private.h"
f73620
+#include "cogl/cogl.h"
f73620
+#include "meta/common.h"
f73620
 
f73620
-#include "display-private.h"
f73620
-#include "screen-private.h"
f73620
-#include "meta-backend-private.h"
f73620
-
f73620
-#include <string.h>
f73620
-
f73620
-#include <X11/cursorfont.h>
f73620
-#include <X11/extensions/Xfixes.h>
f73620
-#include <X11/Xcursor/Xcursor.h>
f73620
-
f73620
-enum {
f73620
+enum
f73620
+{
f73620
   PREPARE_AT,
f73620
   TEXTURE_CHANGED,
f73620
 
f73620
@@ -44,316 +37,148 @@ enum {
f73620
 
f73620
 static guint signals[LAST_SIGNAL];
f73620
 
f73620
-struct _MetaCursorSprite
f73620
+typedef struct _MetaCursorSpritePrivate
f73620
 {
f73620
   GObject parent;
f73620
 
f73620
-  MetaCursor cursor;
f73620
-
f73620
   CoglTexture2D *texture;
f73620
   float texture_scale;
f73620
   int hot_x, hot_y;
f73620
+} MetaCursorSpritePrivate;
f73620
 
f73620
-  int current_frame;
f73620
-  XcursorImages *xcursor_images;
f73620
-
f73620
-  int theme_scale;
f73620
-  gboolean theme_dirty;
f73620
-};
f73620
-
f73620
-G_DEFINE_TYPE (MetaCursorSprite, meta_cursor_sprite, G_TYPE_OBJECT)
f73620
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCursorSprite,
f73620
+                                     meta_cursor_sprite,
f73620
+                                     G_TYPE_OBJECT)
f73620
 
f73620
-static const char *
f73620
-translate_meta_cursor (MetaCursor cursor)
f73620
-{
f73620
-  switch (cursor)
f73620
-    {
f73620
-    case META_CURSOR_DEFAULT:
f73620
-      return "left_ptr";
f73620
-    case META_CURSOR_NORTH_RESIZE:
f73620
-      return "top_side";
f73620
-    case META_CURSOR_SOUTH_RESIZE:
f73620
-      return "bottom_side";
f73620
-    case META_CURSOR_WEST_RESIZE:
f73620
-      return "left_side";
f73620
-    case META_CURSOR_EAST_RESIZE:
f73620
-      return "right_side";
f73620
-    case META_CURSOR_SE_RESIZE:
f73620
-      return "bottom_right_corner";
f73620
-    case META_CURSOR_SW_RESIZE:
f73620
-      return "bottom_left_corner";
f73620
-    case META_CURSOR_NE_RESIZE:
f73620
-      return "top_right_corner";
f73620
-    case META_CURSOR_NW_RESIZE:
f73620
-      return "top_left_corner";
f73620
-    case META_CURSOR_MOVE_OR_RESIZE_WINDOW:
f73620
-      return "fleur";
f73620
-    case META_CURSOR_BUSY:
f73620
-      return "watch";
f73620
-    case META_CURSOR_DND_IN_DRAG:
f73620
-      return "dnd-none";
f73620
-    case META_CURSOR_DND_MOVE:
f73620
-      return "dnd-move";
f73620
-    case META_CURSOR_DND_COPY:
f73620
-      return "dnd-copy";
f73620
-    case META_CURSOR_DND_UNSUPPORTED_TARGET:
f73620
-      return "dnd-none";
f73620
-    case META_CURSOR_POINTING_HAND:
f73620
-      return "hand2";
f73620
-    case META_CURSOR_CROSSHAIR:
f73620
-      return "crosshair";
f73620
-    case META_CURSOR_IBEAM:
f73620
-      return "xterm";
f73620
-    default:
f73620
-      break;
f73620
-    }
f73620
-
f73620
-  g_assert_not_reached ();
f73620
-}
f73620
-
f73620
-Cursor
f73620
-meta_cursor_create_x_cursor (Display    *xdisplay,
f73620
-                             MetaCursor  cursor)
f73620
-{
f73620
-  return XcursorLibraryLoadCursor (xdisplay, translate_meta_cursor (cursor));
f73620
-}
f73620
-
f73620
-static XcursorImages *
f73620
-load_cursor_on_client (MetaCursor cursor, int scale)
f73620
-{
f73620
-  return XcursorLibraryLoadImages (translate_meta_cursor (cursor),
f73620
-                                   meta_prefs_get_cursor_theme (),
f73620
-                                   meta_prefs_get_cursor_size () * scale);
f73620
-}
f73620
-
f73620
-static void
f73620
-meta_cursor_sprite_load_from_xcursor_image (MetaCursorSprite *self,
f73620
-                                            XcursorImage     *xc_image)
f73620
+gboolean
f73620
+meta_cursor_sprite_is_animated (MetaCursorSprite *sprite)
f73620
 {
f73620
-  MetaBackend *meta_backend = meta_get_backend ();
f73620
-  MetaCursorRenderer *renderer = meta_backend_get_cursor_renderer (meta_backend);
f73620
-  uint width, height, rowstride;
f73620
-  CoglPixelFormat cogl_format;
f73620
-  ClutterBackend *clutter_backend;
f73620
-  CoglContext *cogl_context;
f73620
-  CoglTexture2D *texture;
f73620
-  CoglError *error = NULL;
f73620
-
f73620
-  g_assert (self->texture == NULL);
f73620
-
f73620
-  width           = xc_image->width;
f73620
-  height          = xc_image->height;
f73620
-  rowstride       = width * 4;
f73620
-
f73620
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
f73620
-  cogl_format = COGL_PIXEL_FORMAT_BGRA_8888;
f73620
-#else
f73620
-  cogl_format = COGL_PIXEL_FORMAT_ARGB_8888;
f73620
-#endif
f73620
-
f73620
-  clutter_backend = clutter_get_default_backend ();
f73620
-  cogl_context = clutter_backend_get_cogl_context (clutter_backend);
f73620
-  texture = cogl_texture_2d_new_from_data (cogl_context,
f73620
-                                           width, height,
f73620
-                                           cogl_format,
f73620
-                                           rowstride,
f73620
-                                           (uint8_t *) xc_image->pixels,
f73620
-                                           &error);
f73620
-
f73620
-  if (error)
f73620
-    {
f73620
-      meta_warning ("Failed to allocate cursor texture: %s\n", error->message);
f73620
-      cogl_error_free (error);
f73620
-    }
f73620
-
f73620
-  meta_cursor_sprite_set_texture (self, COGL_TEXTURE (texture),
f73620
-                                  xc_image->xhot, xc_image->yhot);
f73620
+  MetaCursorSpriteClass *klass = META_CURSOR_SPRITE_GET_CLASS (sprite);
f73620
 
f73620
-  if (texture)
f73620
-    cogl_object_unref (texture);
f73620
-
f73620
-  meta_cursor_renderer_realize_cursor_from_xcursor (renderer, self, xc_image);
f73620
-}
f73620
-
f73620
-static XcursorImage *
f73620
-meta_cursor_sprite_get_current_frame_image (MetaCursorSprite *self)
f73620
-{
f73620
-  return self->xcursor_images->images[self->current_frame];
f73620
+  if (klass->is_animated)
f73620
+    return klass->is_animated (sprite);
f73620
+  else
f73620
+    return FALSE;
f73620
 }
f73620
 
f73620
 void
f73620
-meta_cursor_sprite_tick_frame (MetaCursorSprite *self)
f73620
-{
f73620
-  XcursorImage *image;
f73620
-
f73620
-  if (!meta_cursor_sprite_is_animated (self))
f73620
-    return;
f73620
-
f73620
-  self->current_frame++;
f73620
-
f73620
-  if (self->current_frame >= self->xcursor_images->nimage)
f73620
-    self->current_frame = 0;
f73620
-
f73620
-  image = meta_cursor_sprite_get_current_frame_image (self);
f73620
-
f73620
-  g_clear_pointer (&self->texture, cogl_object_unref);
f73620
-  meta_cursor_sprite_load_from_xcursor_image (self, image);
f73620
-}
f73620
-
f73620
-guint
f73620
-meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *self)
f73620
-{
f73620
-  if (!meta_cursor_sprite_is_animated (self))
f73620
-    return 0;
f73620
-
f73620
-  return self->xcursor_images->images[self->current_frame]->delay;
f73620
-}
f73620
-
f73620
-gboolean
f73620
-meta_cursor_sprite_is_animated (MetaCursorSprite *self)
f73620
+meta_cursor_sprite_tick_frame (MetaCursorSprite *sprite)
f73620
 {
f73620
-  return (self->xcursor_images &&
f73620
-          self->xcursor_images->nimage > 1);
f73620
+  return META_CURSOR_SPRITE_GET_CLASS (sprite)->tick_frame (sprite);
f73620
 }
f73620
 
f73620
-MetaCursorSprite *
f73620
-meta_cursor_sprite_new (void)
f73620
+unsigned int
f73620
+meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *sprite)
f73620
 {
f73620
-  return g_object_new (META_TYPE_CURSOR_SPRITE, NULL);
f73620
+  return META_CURSOR_SPRITE_GET_CLASS (sprite)->get_current_frame_time (sprite);
f73620
 }
f73620
 
f73620
-static void
f73620
-meta_cursor_sprite_load_from_theme (MetaCursorSprite *self)
f73620
-{
f73620
-  XcursorImage *image;
f73620
-
f73620
-  g_assert (self->cursor != META_CURSOR_NONE);
f73620
-
f73620
-  self->theme_dirty = FALSE;
f73620
-
f73620
-  /* We might be reloading with a different scale. If so clear the old data. */
f73620
-  if (self->xcursor_images)
f73620
-    {
f73620
-      g_clear_pointer (&self->texture, cogl_object_unref);
f73620
-      XcursorImagesDestroy (self->xcursor_images);
f73620
-    }
f73620
-
f73620
-  self->current_frame = 0;
f73620
-  self->xcursor_images = load_cursor_on_client (self->cursor,
f73620
-                                                self->theme_scale);
f73620
-  if (!self->xcursor_images)
f73620
-    meta_fatal ("Could not find cursor. Perhaps set XCURSOR_PATH?");
f73620
-
f73620
-  image = meta_cursor_sprite_get_current_frame_image (self);
f73620
-  meta_cursor_sprite_load_from_xcursor_image (self, image);
f73620
-}
f73620
-
f73620
-MetaCursorSprite *
f73620
-meta_cursor_sprite_from_theme (MetaCursor cursor)
f73620
+void
f73620
+meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite)
f73620
 {
f73620
-  MetaCursorSprite *self;
f73620
-
f73620
-  self = meta_cursor_sprite_new ();
f73620
-
f73620
-  self->cursor = cursor;
f73620
-  self->theme_dirty = TRUE;
f73620
+  MetaCursorSpritePrivate *priv =
f73620
+    meta_cursor_sprite_get_instance_private (sprite);
f73620
 
f73620
-  return self;
f73620
+  g_clear_pointer (&priv->texture, cogl_object_unref);
f73620
 }
f73620
 
f73620
 void
f73620
-meta_cursor_sprite_set_texture (MetaCursorSprite *self,
f73620
+meta_cursor_sprite_set_texture (MetaCursorSprite *sprite,
f73620
                                 CoglTexture      *texture,
f73620
                                 int               hot_x,
f73620
                                 int               hot_y)
f73620
 {
f73620
-  if (self->texture == COGL_TEXTURE_2D (texture) &&
f73620
-      self->hot_x == hot_x &&
f73620
-      self->hot_y == hot_y)
f73620
+  MetaCursorSpritePrivate *priv =
f73620
+    meta_cursor_sprite_get_instance_private (sprite);
f73620
+
f73620
+  if (priv->texture == COGL_TEXTURE_2D (texture) &&
f73620
+      priv->hot_x == hot_x &&
f73620
+      priv->hot_y == hot_y)
f73620
     return;
f73620
 
f73620
-  g_clear_pointer (&self->texture, cogl_object_unref);
f73620
+  g_clear_pointer (&priv->texture, cogl_object_unref);
f73620
   if (texture)
f73620
-    self->texture = cogl_object_ref (texture);
f73620
-  self->hot_x = hot_x;
f73620
-  self->hot_y = hot_y;
f73620
+    priv->texture = cogl_object_ref (texture);
f73620
+  priv->hot_x = hot_x;
f73620
+  priv->hot_y = hot_y;
f73620
 
f73620
-  g_signal_emit (self, signals[TEXTURE_CHANGED], 0);
f73620
+  g_signal_emit (sprite, signals[TEXTURE_CHANGED], 0);
f73620
 }
f73620
 
f73620
 void
f73620
-meta_cursor_sprite_set_texture_scale (MetaCursorSprite *self,
f73620
+meta_cursor_sprite_set_texture_scale (MetaCursorSprite *sprite,
f73620
                                       float             scale)
f73620
 {
f73620
-  self->texture_scale = scale;
f73620
-}
f73620
+  MetaCursorSpritePrivate *priv =
f73620
+    meta_cursor_sprite_get_instance_private (sprite);
f73620
 
f73620
-void
f73620
-meta_cursor_sprite_set_theme_scale (MetaCursorSprite *self,
f73620
-                                    int               theme_scale)
f73620
-{
f73620
-  if (self->theme_scale != theme_scale)
f73620
-    self->theme_dirty = TRUE;
f73620
-  self->theme_scale = theme_scale;
f73620
+  priv->texture_scale = scale;
f73620
 }
f73620
 
f73620
 CoglTexture *
f73620
-meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *self)
f73620
+meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *sprite)
f73620
 {
f73620
-  return COGL_TEXTURE (self->texture);
f73620
-}
f73620
+  MetaCursorSpritePrivate *priv =
f73620
+    meta_cursor_sprite_get_instance_private (sprite);
f73620
 
f73620
-MetaCursor
f73620
-meta_cursor_sprite_get_meta_cursor (MetaCursorSprite *self)
f73620
-{
f73620
-  return self->cursor;
f73620
+  return COGL_TEXTURE (priv->texture);
f73620
 }
f73620
 
f73620
 void
f73620
-meta_cursor_sprite_get_hotspot (MetaCursorSprite *self,
f73620
+meta_cursor_sprite_get_hotspot (MetaCursorSprite *sprite,
f73620
                                 int              *hot_x,
f73620
                                 int              *hot_y)
f73620
 {
f73620
-  *hot_x = self->hot_x;
f73620
-  *hot_y = self->hot_y;
f73620
+  MetaCursorSpritePrivate *priv =
f73620
+    meta_cursor_sprite_get_instance_private (sprite);
f73620
+
f73620
+  *hot_x = priv->hot_x;
f73620
+  *hot_y = priv->hot_y;
f73620
 }
f73620
 
f73620
 float
f73620
-meta_cursor_sprite_get_texture_scale (MetaCursorSprite *self)
f73620
+meta_cursor_sprite_get_texture_scale (MetaCursorSprite *sprite)
f73620
 {
f73620
-  return self->texture_scale;
f73620
+  MetaCursorSpritePrivate *priv =
f73620
+    meta_cursor_sprite_get_instance_private (sprite);
f73620
+
f73620
+  return priv->texture_scale;
f73620
 }
f73620
 
f73620
 void
f73620
-meta_cursor_sprite_prepare_at (MetaCursorSprite *self,
f73620
+meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite,
f73620
                                int               x,
f73620
                                int               y)
f73620
 {
f73620
-  g_signal_emit (self, signals[PREPARE_AT], 0, x, y);
f73620
+  g_signal_emit (sprite, signals[PREPARE_AT], 0, x, y);
f73620
 }
f73620
 
f73620
 void
f73620
-meta_cursor_sprite_realize_texture (MetaCursorSprite *self)
f73620
+meta_cursor_sprite_realize_texture (MetaCursorSprite *sprite)
f73620
 {
f73620
-  if (self->theme_dirty)
f73620
-    meta_cursor_sprite_load_from_theme (self);
f73620
+  MetaCursorSpriteClass *klass = META_CURSOR_SPRITE_GET_CLASS (sprite);
f73620
+
f73620
+  if (klass->realize_texture)
f73620
+    klass->realize_texture (sprite);
f73620
 }
f73620
 
f73620
 static void
f73620
-meta_cursor_sprite_init (MetaCursorSprite *self)
f73620
+meta_cursor_sprite_init (MetaCursorSprite *sprite)
f73620
 {
f73620
-  self->texture_scale = 1.0f;
f73620
+  MetaCursorSpritePrivate *priv =
f73620
+    meta_cursor_sprite_get_instance_private (sprite);
f73620
+
f73620
+  priv->texture_scale = 1.0f;
f73620
 }
f73620
 
f73620
 static void
f73620
 meta_cursor_sprite_finalize (GObject *object)
f73620
 {
f73620
-  MetaCursorSprite *self = META_CURSOR_SPRITE (object);
f73620
-
f73620
-  if (self->xcursor_images)
f73620
-    XcursorImagesDestroy (self->xcursor_images);
f73620
+  MetaCursorSprite *sprite = META_CURSOR_SPRITE (object);
f73620
+  MetaCursorSpritePrivate *priv =
f73620
+    meta_cursor_sprite_get_instance_private (sprite);
f73620
 
f73620
-  g_clear_pointer (&self->texture, cogl_object_unref);
f73620
+  g_clear_pointer (&priv->texture, cogl_object_unref);
f73620
 
f73620
   G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->finalize (object);
f73620
 }
f73620
diff --git a/src/backends/meta-cursor.h b/src/backends/meta-cursor.h
f73620
index 6087df69c..3051fdee6 100644
f73620
--- a/src/backends/meta-cursor.h
f73620
+++ b/src/backends/meta-cursor.h
f73620
@@ -25,51 +25,50 @@
f73620
 #include <meta/common.h>
f73620
 #include <meta/boxes.h>
f73620
 
f73620
-typedef struct _MetaCursorSprite MetaCursorSprite;
f73620
-
f73620
 #define META_TYPE_CURSOR_SPRITE (meta_cursor_sprite_get_type ())
f73620
-G_DECLARE_FINAL_TYPE (MetaCursorSprite,
f73620
-                      meta_cursor_sprite,
f73620
-                      META, CURSOR_SPRITE,
f73620
-                      GObject);
f73620
-
f73620
-MetaCursorSprite * meta_cursor_sprite_new (void);
f73620
-
f73620
-MetaCursorSprite * meta_cursor_sprite_from_theme  (MetaCursor cursor);
f73620
-
f73620
-
f73620
-void meta_cursor_sprite_set_theme_scale (MetaCursorSprite *self,
f73620
-                                         int               scale);
f73620
-
f73620
-MetaCursor meta_cursor_sprite_get_meta_cursor (MetaCursorSprite *self);
f73620
-
f73620
-Cursor meta_cursor_create_x_cursor (Display    *xdisplay,
f73620
-                                    MetaCursor  cursor);
f73620
-
f73620
-void meta_cursor_sprite_prepare_at (MetaCursorSprite *self,
f73620
+G_DECLARE_DERIVABLE_TYPE (MetaCursorSprite,
f73620
+                          meta_cursor_sprite,
f73620
+                          META, CURSOR_SPRITE,
f73620
+                          GObject)
f73620
+
f73620
+struct _MetaCursorSpriteClass
f73620
+{
f73620
+  GObjectClass parent_class;
f73620
+
f73620
+  void (* realize_texture) (MetaCursorSprite *sprite);
f73620
+  gboolean (* is_animated) (MetaCursorSprite *sprite);
f73620
+  void (* tick_frame) (MetaCursorSprite *sprite);
f73620
+  unsigned int (* get_current_frame_time) (MetaCursorSprite *sprite);
f73620
+};
f73620
+
f73620
+void meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite,
f73620
                                     int               x,
f73620
                                     int               y);
f73620
 
f73620
-void meta_cursor_sprite_realize_texture (MetaCursorSprite *self);
f73620
+void meta_cursor_sprite_realize_texture (MetaCursorSprite *sprite);
f73620
+
f73620
+void meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite);
f73620
 
f73620
-void meta_cursor_sprite_set_texture (MetaCursorSprite *self,
f73620
+void meta_cursor_sprite_set_texture (MetaCursorSprite *sprite,
f73620
                                      CoglTexture      *texture,
f73620
                                      int               hot_x,
f73620
                                      int               hot_y);
f73620
 
f73620
-void meta_cursor_sprite_set_texture_scale (MetaCursorSprite *self,
f73620
+void meta_cursor_sprite_set_texture_scale (MetaCursorSprite *sprite,
f73620
                                            float             scale);
f73620
 
f73620
-CoglTexture *meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *self);
f73620
+CoglTexture *meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *sprite);
f73620
 
f73620
-void meta_cursor_sprite_get_hotspot (MetaCursorSprite *self,
f73620
+void meta_cursor_sprite_get_hotspot (MetaCursorSprite *sprite,
f73620
                                      int              *hot_x,
f73620
                                      int              *hot_y);
f73620
 
f73620
-float meta_cursor_sprite_get_texture_scale (MetaCursorSprite *self);
f73620
+float meta_cursor_sprite_get_texture_scale (MetaCursorSprite *sprite);
f73620
+
f73620
+gboolean meta_cursor_sprite_is_animated (MetaCursorSprite *sprite);
f73620
+
f73620
+void meta_cursor_sprite_tick_frame (MetaCursorSprite *sprite);
f73620
 
f73620
-gboolean meta_cursor_sprite_is_animated            (MetaCursorSprite *self);
f73620
-void     meta_cursor_sprite_tick_frame             (MetaCursorSprite *self);
f73620
-guint    meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *self);
f73620
+unsigned int meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *sprite);
f73620
 
f73620
 #endif /* META_CURSOR_H */
f73620
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
f73620
index a29f593ea..042d96ec6 100644
f73620
--- a/src/backends/native/meta-backend-native.c
f73620
+++ b/src/backends/native/meta-backend-native.c
f73620
@@ -645,8 +645,6 @@ void meta_backend_native_resume (MetaBackendNative *native)
f73620
     meta_backend_get_monitor_manager (backend);
f73620
   MetaMonitorManagerKms *monitor_manager_kms =
f73620
     META_MONITOR_MANAGER_KMS (monitor_manager);
f73620
-  MetaCursorRenderer *cursor_renderer;
f73620
-  MetaCursorRendererNative *cursor_renderer_native;
f73620
   ClutterActor *stage;
f73620
   MetaIdleMonitor *idle_monitor;
f73620
 
f73620
@@ -658,10 +656,6 @@ void meta_backend_native_resume (MetaBackendNative *native)
f73620
   stage = meta_backend_get_stage (backend);
f73620
   clutter_actor_queue_redraw (stage);
f73620
 
f73620
-  cursor_renderer = meta_backend_get_cursor_renderer (backend);
f73620
-  cursor_renderer_native = META_CURSOR_RENDERER_NATIVE (cursor_renderer);
f73620
-  meta_cursor_renderer_native_force_update (cursor_renderer_native);
f73620
-
f73620
   idle_monitor = meta_backend_get_idle_monitor (backend, 0);
f73620
   meta_idle_monitor_reset_idletime (idle_monitor);
f73620
 }
f73620
diff --git a/src/backends/native/meta-cursor-renderer-native.c b/src/backends/native/meta-cursor-renderer-native.c
f73620
index c7326af42..29800953b 100644
f73620
--- a/src/backends/native/meta-cursor-renderer-native.c
f73620
+++ b/src/backends/native/meta-cursor-renderer-native.c
f73620
@@ -35,6 +35,7 @@
f73620
 #include <meta/meta-backend.h>
f73620
 
f73620
 #include "backends/meta-backend-private.h"
f73620
+#include "backends/meta-cursor-sprite-xcursor.h"
f73620
 #include "backends/meta-logical-monitor.h"
f73620
 #include "backends/meta-monitor.h"
f73620
 #include "backends/meta-monitor-manager-private.h"
f73620
@@ -43,6 +44,11 @@
f73620
 #include "core/boxes-private.h"
f73620
 #include "meta/boxes.h"
f73620
 
f73620
+#ifdef HAVE_WAYLAND
f73620
+#include "wayland/meta-cursor-sprite-wayland.h"
f73620
+#include "wayland/meta-wayland-buffer.h"
f73620
+#endif
f73620
+
f73620
 #ifndef DRM_CAP_CURSOR_WIDTH
f73620
 #define DRM_CAP_CURSOR_WIDTH 0x8
f73620
 #endif
f73620
@@ -113,6 +119,11 @@ static GQuark quark_cursor_renderer_native_gpu_data = 0;
f73620
 
f73620
 G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRendererNative, meta_cursor_renderer_native, META_TYPE_CURSOR_RENDERER);
f73620
 
f73620
+static void
f73620
+realize_cursor_sprite (MetaCursorRenderer *renderer,
f73620
+                       MetaCursorSprite   *cursor_sprite,
f73620
+                       GList              *gpus);
f73620
+
f73620
 static MetaCursorNativeGpuState *
f73620
 get_cursor_gpu_state (MetaCursorNativePrivate *cursor_priv,
f73620
                       MetaGpuKms              *gpu_kms);
f73620
@@ -152,7 +163,8 @@ static void
f73620
 meta_cursor_renderer_native_finalize (GObject *object)
f73620
 {
f73620
   MetaCursorRendererNative *renderer = META_CURSOR_RENDERER_NATIVE (object);
f73620
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (renderer);
f73620
+  MetaCursorRendererNativePrivate *priv =
f73620
+    meta_cursor_renderer_native_get_instance_private (renderer);
f73620
 
f73620
   if (priv->animation_timeout_id)
f73620
     g_source_remove (priv->animation_timeout_id);
f73620
@@ -203,7 +215,8 @@ set_crtc_cursor (MetaCursorRendererNative *native,
f73620
                  MetaCrtc                 *crtc,
f73620
                  MetaCursorSprite         *cursor_sprite)
f73620
 {
f73620
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
f73620
+  MetaCursorRendererNativePrivate *priv =
f73620
+    meta_cursor_renderer_native_get_instance_private (native);
f73620
   MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
f73620
   MetaGpuKms *gpu_kms;
f73620
   int kms_fd;
f73620
@@ -371,7 +384,8 @@ static void
f73620
 update_hw_cursor (MetaCursorRendererNative *native,
f73620
                   MetaCursorSprite         *cursor_sprite)
f73620
 {
f73620
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
f73620
+  MetaCursorRendererNativePrivate *priv =
f73620
+    meta_cursor_renderer_native_get_instance_private (native);
f73620
   MetaCursorRenderer *renderer = META_CURSOR_RENDERER (native);
f73620
   MetaMonitorManager *monitor_manager = priv->monitor_manager;
f73620
   GList *logical_monitors;
f73620
@@ -564,18 +578,15 @@ can_draw_cursor_unscaled (MetaCursorRenderer *renderer,
f73620
 
f73620
 static gboolean
f73620
 should_have_hw_cursor (MetaCursorRenderer *renderer,
f73620
-                       MetaCursorSprite   *cursor_sprite)
f73620
+                       MetaCursorSprite   *cursor_sprite,
f73620
+                       GList              *gpus)
f73620
 {
f73620
-  MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
f73620
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
f73620
-  GList *gpus;
f73620
   GList *l;
f73620
   CoglTexture *texture;
f73620
 
f73620
   if (!cursor_sprite)
f73620
     return FALSE;
f73620
 
f73620
-  gpus = meta_monitor_manager_get_gpus (priv->monitor_manager);
f73620
   for (l = gpus; l; l = l->next)
f73620
     {
f73620
       MetaGpuKms *gpu_kms = l->data;
f73620
@@ -609,7 +620,8 @@ should_have_hw_cursor (MetaCursorRenderer *renderer,
f73620
 static gboolean
f73620
 meta_cursor_renderer_native_update_animation (MetaCursorRendererNative *native)
f73620
 {
f73620
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
f73620
+  MetaCursorRendererNativePrivate *priv =
f73620
+    meta_cursor_renderer_native_get_instance_private (native);
f73620
   MetaCursorRenderer *renderer = META_CURSOR_RENDERER (native);
f73620
   MetaCursorSprite *cursor_sprite = meta_cursor_renderer_get_cursor (renderer);
f73620
 
f73620
@@ -621,10 +633,11 @@ meta_cursor_renderer_native_update_animation (MetaCursorRendererNative *native)
f73620
 }
f73620
 
f73620
 static void
f73620
-meta_cursor_renderer_native_trigger_frame (MetaCursorRendererNative *native,
f73620
-                                           MetaCursorSprite         *cursor_sprite)
f73620
+maybe_schedule_cursor_sprite_animation_frame (MetaCursorRendererNative *native,
f73620
+                                              MetaCursorSprite         *cursor_sprite)
f73620
 {
f73620
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
f73620
+  MetaCursorRendererNativePrivate *priv =
f73620
+    meta_cursor_renderer_native_get_instance_private (native);
f73620
   gboolean cursor_change;
f73620
   guint delay;
f73620
 
f73620
@@ -656,21 +669,78 @@ meta_cursor_renderer_native_trigger_frame (MetaCursorRendererNative *native,
f73620
     }
f73620
 }
f73620
 
f73620
+static GList *
f73620
+calculate_cursor_sprite_gpus (MetaCursorRenderer *renderer,
f73620
+                              MetaCursorSprite   *cursor_sprite)
f73620
+{
f73620
+  MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
f73620
+  MetaCursorRendererNativePrivate *priv =
f73620
+    meta_cursor_renderer_native_get_instance_private (native);
f73620
+  MetaMonitorManager *monitor_manager = priv->monitor_manager;
f73620
+  GList *gpus = NULL;
f73620
+  GList *logical_monitors;
f73620
+  GList *l;
f73620
+  ClutterRect cursor_rect;
f73620
+
f73620
+  cursor_rect = meta_cursor_renderer_calculate_rect (renderer, cursor_sprite);
f73620
+
f73620
+  logical_monitors =
f73620
+    meta_monitor_manager_get_logical_monitors (monitor_manager);
f73620
+  for (l = logical_monitors; l; l = l->next)
f73620
+    {
f73620
+      MetaLogicalMonitor *logical_monitor = l->data;
f73620
+      MetaRectangle logical_monitor_layout;
f73620
+      ClutterRect logical_monitor_rect;
f73620
+      GList *monitors, *l_mon;
f73620
+
f73620
+      logical_monitor_layout =
f73620
+        meta_logical_monitor_get_layout (logical_monitor);
f73620
+      logical_monitor_rect =
f73620
+        meta_rectangle_to_clutter_rect (&logical_monitor_layout);
f73620
+
f73620
+      if (!clutter_rect_intersection (&cursor_rect, &logical_monitor_rect,
f73620
+                                      NULL))
f73620
+        continue;
f73620
+
f73620
+      monitors = meta_logical_monitor_get_monitors (logical_monitor);
f73620
+      for (l_mon = monitors; l_mon; l_mon = l_mon->next)
f73620
+        {
f73620
+          MetaMonitor *monitor = l_mon->data;
f73620
+          MetaGpu *gpu;
f73620
+
f73620
+          gpu = meta_monitor_get_gpu (monitor);
f73620
+          if (!g_list_find (gpus, gpu))
f73620
+            gpus = g_list_prepend (gpus, gpu);
f73620
+        }
f73620
+    }
f73620
+
f73620
+  return gpus;
f73620
+}
f73620
+
f73620
 static gboolean
f73620
 meta_cursor_renderer_native_update_cursor (MetaCursorRenderer *renderer,
f73620
                                            MetaCursorSprite   *cursor_sprite)
f73620
 {
f73620
   MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
f73620
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
f73620
+  MetaCursorRendererNativePrivate *priv =
f73620
+    meta_cursor_renderer_native_get_instance_private (native);
f73620
+  g_autoptr (GList) gpus = NULL;
f73620
 
f73620
   if (cursor_sprite)
f73620
-    meta_cursor_sprite_realize_texture (cursor_sprite);
f73620
+    {
f73620
+      meta_cursor_sprite_realize_texture (cursor_sprite);
f73620
+      gpus = calculate_cursor_sprite_gpus (renderer, cursor_sprite);
f73620
+      realize_cursor_sprite (renderer, cursor_sprite, gpus);
f73620
+    }
f73620
 
f73620
-  meta_cursor_renderer_native_trigger_frame (native, cursor_sprite);
f73620
+  maybe_schedule_cursor_sprite_animation_frame (native, cursor_sprite);
f73620
 
f73620
-  priv->has_hw_cursor = should_have_hw_cursor (renderer, cursor_sprite);
f73620
+  priv->has_hw_cursor = should_have_hw_cursor (renderer, cursor_sprite, gpus);
f73620
   update_hw_cursor (native, cursor_sprite);
f73620
-  return priv->has_hw_cursor;
f73620
+
f73620
+  return (priv->has_hw_cursor ||
f73620
+          !cursor_sprite ||
f73620
+          !meta_cursor_sprite_get_cogl_texture (cursor_sprite));
f73620
 }
f73620
 
f73620
 static void
f73620
@@ -706,6 +776,24 @@ ensure_cursor_gpu_state (MetaCursorNativePrivate *cursor_priv,
f73620
   return cursor_gpu_state;
f73620
 }
f73620
 
f73620
+static void
f73620
+on_cursor_sprite_texture_changed (MetaCursorSprite *cursor_sprite)
f73620
+{
f73620
+  MetaCursorNativePrivate *cursor_priv = get_cursor_priv (cursor_sprite);
f73620
+  GHashTableIter iter;
f73620
+  MetaCursorNativeGpuState *cursor_gpu_state;
f73620
+
f73620
+  g_hash_table_iter_init (&iter, cursor_priv->gpu_states);
f73620
+  while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cursor_gpu_state))
f73620
+    {
f73620
+      guint pending_bo;
f73620
+      pending_bo = get_pending_cursor_sprite_gbm_bo_index (cursor_gpu_state);
f73620
+      g_clear_pointer (&cursor_gpu_state->bos[pending_bo],
f73620
+                       (GDestroyNotify) gbm_bo_destroy);
f73620
+      cursor_gpu_state->pending_bo_state = META_CURSOR_GBM_BO_STATE_INVALIDATED;
f73620
+    }
f73620
+}
f73620
+
f73620
 static void
f73620
 cursor_priv_free (MetaCursorNativePrivate *cursor_priv)
f73620
 {
f73620
@@ -738,6 +826,9 @@ ensure_cursor_priv (MetaCursorSprite *cursor_sprite)
f73620
                            cursor_priv,
f73620
                            (GDestroyNotify) cursor_priv_free);
f73620
 
f73620
+  g_signal_connect (cursor_sprite, "texture-changed",
f73620
+                    G_CALLBACK (on_cursor_sprite_texture_changed), NULL);
f73620
+
f73620
   return cursor_priv;
f73620
 }
f73620
 
f73620
@@ -805,57 +896,71 @@ load_cursor_sprite_gbm_buffer_for_gpu (MetaCursorRendererNative *native,
f73620
     }
f73620
 }
f73620
 
f73620
-static void
f73620
-invalidate_pending_cursor_sprite_gbm_bo (MetaCursorSprite *cursor_sprite,
f73620
-                                         MetaGpuKms       *gpu_kms)
f73620
+static gboolean
f73620
+is_cursor_hw_state_valid (MetaCursorSprite *cursor_sprite,
f73620
+                          MetaGpuKms       *gpu_kms)
f73620
 {
f73620
   MetaCursorNativePrivate *cursor_priv;
f73620
   MetaCursorNativeGpuState *cursor_gpu_state;
f73620
-  guint pending_bo;
f73620
 
f73620
   cursor_priv = get_cursor_priv (cursor_sprite);
f73620
   if (!cursor_priv)
f73620
-    return;
f73620
+    return FALSE;
f73620
 
f73620
   cursor_gpu_state = get_cursor_gpu_state (cursor_priv, gpu_kms);
f73620
   if (!cursor_gpu_state)
f73620
-    return;
f73620
+    return FALSE;
f73620
 
f73620
-  pending_bo = get_pending_cursor_sprite_gbm_bo_index (cursor_gpu_state);
f73620
-  g_clear_pointer (&cursor_gpu_state->bos[pending_bo],
f73620
-                   (GDestroyNotify) gbm_bo_destroy);
f73620
-  cursor_gpu_state->pending_bo_state = META_CURSOR_GBM_BO_STATE_INVALIDATED;
f73620
+  switch (cursor_gpu_state->pending_bo_state)
f73620
+    {
f73620
+    case META_CURSOR_GBM_BO_STATE_SET:
f73620
+    case META_CURSOR_GBM_BO_STATE_NONE:
f73620
+      return TRUE;
f73620
+    case META_CURSOR_GBM_BO_STATE_INVALIDATED:
f73620
+      return FALSE;
f73620
+    }
f73620
+
f73620
+  g_assert_not_reached ();
f73620
 }
f73620
 
f73620
 #ifdef HAVE_WAYLAND
f73620
 static void
f73620
-meta_cursor_renderer_native_realize_cursor_from_wl_buffer_for_gpu (MetaCursorRenderer *renderer,
f73620
-                                                                   MetaGpuKms         *gpu_kms,
f73620
-                                                                   MetaCursorSprite   *cursor_sprite,
f73620
-                                                                   struct wl_resource *buffer)
f73620
+realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer      *renderer,
f73620
+                                              MetaGpuKms              *gpu_kms,
f73620
+                                              MetaCursorSpriteWayland *sprite_wayland)
f73620
 {
f73620
   MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
f73620
+  MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (sprite_wayland);
f73620
   MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
f73620
   uint32_t gbm_format;
f73620
   uint64_t cursor_width, cursor_height;
f73620
   CoglTexture *texture;
f73620
   uint width, height;
f73620
+  MetaWaylandBuffer *buffer;
f73620
+  struct wl_resource *buffer_resource;
f73620
+  struct wl_shm_buffer *shm_buffer;
f73620
 
f73620
   cursor_renderer_gpu_data =
f73620
     meta_cursor_renderer_native_gpu_data_from_gpu (gpu_kms);
f73620
   if (!cursor_renderer_gpu_data || cursor_renderer_gpu_data->hw_cursor_broken)
f73620
     return;
f73620
 
f73620
-  /* Destroy any previous pending cursor buffer; we'll always either fail (which
f73620
-   * should unset, or succeed, which will set new buffer.
f73620
-   */
f73620
-  invalidate_pending_cursor_sprite_gbm_bo (cursor_sprite, gpu_kms);
f73620
+  if (is_cursor_hw_state_valid (cursor_sprite, gpu_kms))
f73620
+    return;
f73620
 
f73620
   texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
f73620
   width = cogl_texture_get_width (texture);
f73620
   height = cogl_texture_get_height (texture);
f73620
 
f73620
-  struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get (buffer);
f73620
+  buffer = meta_cursor_sprite_wayland_get_buffer (sprite_wayland);
f73620
+  if (!buffer)
f73620
+    return;
f73620
+
f73620
+  buffer_resource = meta_wayland_buffer_get_resource (buffer);
f73620
+  if (!buffer_resource)
f73620
+    return;
f73620
+
f73620
+  shm_buffer = wl_shm_buffer_get (buffer_resource);
f73620
   if (shm_buffer)
f73620
     {
f73620
       int rowstride = wl_shm_buffer_get_stride (shm_buffer);
f73620
@@ -929,47 +1034,27 @@ meta_cursor_renderer_native_realize_cursor_from_wl_buffer_for_gpu (MetaCursorRen
f73620
       set_pending_cursor_sprite_gbm_bo (cursor_sprite, gpu_kms, bo);
f73620
     }
f73620
 }
f73620
-
f73620
-static void
f73620
-meta_cursor_renderer_native_realize_cursor_from_wl_buffer (MetaCursorRenderer *renderer,
f73620
-                                                           MetaCursorSprite *cursor_sprite,
f73620
-                                                           struct wl_resource *buffer)
f73620
-{
f73620
-  MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
f73620
-  MetaCursorRendererNativePrivate *priv =
f73620
-	  meta_cursor_renderer_native_get_instance_private (native);
f73620
-  GList *gpus;
f73620
-  GList *l;
f73620
-
f73620
-  gpus = meta_monitor_manager_get_gpus (priv->monitor_manager);
f73620
-  for (l = gpus; l; l = l->next)
f73620
-    {
f73620
-      MetaGpuKms *gpu_kms = l->data;
f73620
-
f73620
-      meta_cursor_renderer_native_realize_cursor_from_wl_buffer_for_gpu (
f73620
-        renderer,
f73620
-        gpu_kms,
f73620
-        cursor_sprite,
f73620
-        buffer);
f73620
-    }
f73620
-}
f73620
 #endif
f73620
 
f73620
 static void
f73620
-meta_cursor_renderer_native_realize_cursor_from_xcursor_for_gpu (MetaCursorRenderer *renderer,
f73620
-                                                                 MetaGpuKms         *gpu_kms,
f73620
-                                                                 MetaCursorSprite   *cursor_sprite,
f73620
-                                                                 XcursorImage       *xc_image)
f73620
+realize_cursor_sprite_from_xcursor_for_gpu (MetaCursorRenderer      *renderer,
f73620
+                                            MetaGpuKms              *gpu_kms,
f73620
+                                            MetaCursorSpriteXcursor *sprite_xcursor)
f73620
 {
f73620
   MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
f73620
   MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
f73620
+  MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (sprite_xcursor);
f73620
+  XcursorImage *xc_image;
f73620
 
f73620
   cursor_renderer_gpu_data =
f73620
     meta_cursor_renderer_native_gpu_data_from_gpu (gpu_kms);
f73620
   if (!cursor_renderer_gpu_data || cursor_renderer_gpu_data->hw_cursor_broken)
f73620
     return;
f73620
 
f73620
-  invalidate_pending_cursor_sprite_gbm_bo (cursor_sprite, gpu_kms);
f73620
+  if (is_cursor_hw_state_valid (cursor_sprite, gpu_kms))
f73620
+    return;
f73620
+
f73620
+  xc_image = meta_cursor_sprite_xcursor_get_current_image (sprite_xcursor);
f73620
 
f73620
   load_cursor_sprite_gbm_buffer_for_gpu (native,
f73620
                                          gpu_kms,
f73620
@@ -982,26 +1067,45 @@ meta_cursor_renderer_native_realize_cursor_from_xcursor_for_gpu (MetaCursorRende
f73620
 }
f73620
 
f73620
 static void
f73620
-meta_cursor_renderer_native_realize_cursor_from_xcursor (MetaCursorRenderer *renderer,
f73620
-                                                         MetaCursorSprite   *cursor_sprite,
f73620
-                                                         XcursorImage       *xc_image)
f73620
+realize_cursor_sprite_for_gpu (MetaCursorRenderer *renderer,
f73620
+                               MetaGpuKms         *gpu_kms,
f73620
+                               MetaCursorSprite   *cursor_sprite)
f73620
+{
f73620
+#ifdef HAVE_WAYLAND
f73620
+  if (META_IS_CURSOR_SPRITE_WAYLAND (cursor_sprite))
f73620
+    {
f73620
+      MetaCursorSpriteWayland *sprite_wayland =
f73620
+        META_CURSOR_SPRITE_WAYLAND (cursor_sprite);
f73620
+
f73620
+      realize_cursor_sprite_from_wl_buffer_for_gpu (renderer,
f73620
+                                                    gpu_kms,
f73620
+                                                    sprite_wayland);
f73620
+    }
f73620
+  else
f73620
+#endif
f73620
+  if (META_IS_CURSOR_SPRITE_XCURSOR (cursor_sprite))
f73620
+    {
f73620
+      MetaCursorSpriteXcursor *sprite_xcursor =
f73620
+        META_CURSOR_SPRITE_XCURSOR (cursor_sprite);
f73620
+
f73620
+      realize_cursor_sprite_from_xcursor_for_gpu (renderer,
f73620
+                                                  gpu_kms,
f73620
+                                                  sprite_xcursor);
f73620
+    }
f73620
+}
f73620
+
f73620
+static void
f73620
+realize_cursor_sprite (MetaCursorRenderer *renderer,
f73620
+                       MetaCursorSprite   *cursor_sprite,
f73620
+                       GList              *gpus)
f73620
 {
f73620
-  MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
f73620
-  MetaCursorRendererNativePrivate *priv =
f73620
-	  meta_cursor_renderer_native_get_instance_private (native);
f73620
-  GList *gpus;
f73620
   GList *l;
f73620
 
f73620
-  gpus = meta_monitor_manager_get_gpus (priv->monitor_manager);
f73620
   for (l = gpus; l; l = l->next)
f73620
     {
f73620
       MetaGpuKms *gpu_kms = l->data;
f73620
 
f73620
-      meta_cursor_renderer_native_realize_cursor_from_xcursor_for_gpu (
f73620
-        renderer,
f73620
-        gpu_kms,
f73620
-        cursor_sprite,
f73620
-        xc_image);
f73620
+      realize_cursor_sprite_for_gpu (renderer, gpu_kms, cursor_sprite);
f73620
     }
f73620
 }
f73620
 
f73620
@@ -1013,12 +1117,6 @@ meta_cursor_renderer_native_class_init (MetaCursorRendererNativeClass *klass)
f73620
 
f73620
   object_class->finalize = meta_cursor_renderer_native_finalize;
f73620
   renderer_class->update_cursor = meta_cursor_renderer_native_update_cursor;
f73620
-#ifdef HAVE_WAYLAND
f73620
-  renderer_class->realize_cursor_from_wl_buffer =
f73620
-    meta_cursor_renderer_native_realize_cursor_from_wl_buffer;
f73620
-#endif
f73620
-  renderer_class->realize_cursor_from_xcursor =
f73620
-    meta_cursor_renderer_native_realize_cursor_from_xcursor;
f73620
 
f73620
   quark_cursor_sprite = g_quark_from_static_string ("-meta-cursor-native");
f73620
   quark_cursor_renderer_native_gpu_data =
f73620
@@ -1033,14 +1131,13 @@ force_update_hw_cursor (MetaCursorRendererNative *native)
f73620
     meta_cursor_renderer_native_get_instance_private (native);
f73620
 
f73620
   priv->hw_state_invalidated = TRUE;
f73620
-  update_hw_cursor (native, meta_cursor_renderer_get_cursor (renderer));
f73620
+  meta_cursor_renderer_force_update (renderer);
f73620
 }
f73620
 
f73620
 static void
f73620
 on_monitors_changed (MetaMonitorManager       *monitors,
f73620
                      MetaCursorRendererNative *native)
f73620
 {
f73620
-  /* Our tracking is all messed up, so force an update. */
f73620
   force_update_hw_cursor (native);
f73620
 }
f73620
 
f73620
@@ -1112,9 +1209,3 @@ static void
f73620
 meta_cursor_renderer_native_init (MetaCursorRendererNative *native)
f73620
 {
f73620
 }
f73620
-
f73620
-void
f73620
-meta_cursor_renderer_native_force_update (MetaCursorRendererNative *native)
f73620
-{
f73620
-  force_update_hw_cursor (native);
f73620
-}
f73620
diff --git a/src/backends/native/meta-cursor-renderer-native.h b/src/backends/native/meta-cursor-renderer-native.h
f73620
index 09203a5f7..fb4c8edc7 100644
f73620
--- a/src/backends/native/meta-cursor-renderer-native.h
f73620
+++ b/src/backends/native/meta-cursor-renderer-native.h
f73620
@@ -32,8 +32,6 @@ G_DECLARE_FINAL_TYPE (MetaCursorRendererNative, meta_cursor_renderer_native,
f73620
                       META, CURSOR_RENDERER_NATIVE,
f73620
                       MetaCursorRenderer)
f73620
 
f73620
-void meta_cursor_renderer_native_force_update (MetaCursorRendererNative *renderer);
f73620
-
f73620
 MetaCursorRendererNative * meta_cursor_renderer_native_new (MetaBackend *backend);
f73620
 
f73620
 #endif /* META_CURSOR_RENDERER_NATIVE_H */
f73620
diff --git a/src/backends/x11/cm/meta-cursor-sprite-xfixes.c b/src/backends/x11/cm/meta-cursor-sprite-xfixes.c
f73620
new file mode 100644
f73620
index 000000000..143ebb791
f73620
--- /dev/null
f73620
+++ b/src/backends/x11/cm/meta-cursor-sprite-xfixes.c
f73620
@@ -0,0 +1,226 @@
f73620
+/*
f73620
+ * Copyright 2013, 2018 Red Hat, Inc.
f73620
+ *
f73620
+ * This program is free software; you can redistribute it and/or
f73620
+ * modify it under the terms of the GNU General Public License as
f73620
+ * published by the Free Software Foundation; either version 2 of the
f73620
+ * License, or (at your option) any later version.
f73620
+ *
f73620
+ * This program is distributed in the hope that it will be useful, but
f73620
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
f73620
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f73620
+ * General Public License for more details.
f73620
+ *
f73620
+ * You should have received a copy of the GNU General Public License
f73620
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
f73620
+ *
f73620
+ */
f73620
+
f73620
+#include "config.h"
f73620
+
f73620
+#include "backends/x11/cm/meta-cursor-sprite-xfixes.h"
f73620
+
f73620
+#include <X11/extensions/Xfixes.h>
f73620
+
f73620
+#include "core/display-private.h"
f73620
+
f73620
+enum
f73620
+{
f73620
+  PROP_0,
f73620
+
f73620
+  PROP_DISPLAY,
f73620
+
f73620
+  N_PROPS
f73620
+};
f73620
+
f73620
+static GParamSpec *obj_props[N_PROPS];
f73620
+
f73620
+struct _MetaCursorSpriteXfixes
f73620
+{
f73620
+  MetaCursorSprite parent;
f73620
+
f73620
+  MetaDisplay *display;
f73620
+};
f73620
+
f73620
+static void
f73620
+meta_screen_cast_xfixes_init_initable_iface (GInitableIface *iface);
f73620
+
f73620
+G_DEFINE_TYPE_WITH_CODE (MetaCursorSpriteXfixes,
f73620
+                         meta_cursor_sprite_xfixes,
f73620
+                         META_TYPE_CURSOR_SPRITE,
f73620
+                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
f73620
+                                                meta_screen_cast_xfixes_init_initable_iface))
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_xfixes_realize_texture (MetaCursorSprite *sprite)
f73620
+{
f73620
+}
f73620
+
f73620
+static gboolean
f73620
+meta_cursor_sprite_xfixes_is_animated (MetaCursorSprite *sprite)
f73620
+{
f73620
+  return FALSE;
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_xfixes_get_property (GObject    *object,
f73620
+                                        guint       prop_id,
f73620
+                                        GValue     *value,
f73620
+                                        GParamSpec *pspec)
f73620
+{
f73620
+  MetaCursorSpriteXfixes *sprite_xfixes = META_CURSOR_SPRITE_XFIXES (object);
f73620
+
f73620
+  switch (prop_id)
f73620
+    {
f73620
+    case PROP_DISPLAY:
f73620
+      g_value_set_object (value, sprite_xfixes->display);
f73620
+      break;
f73620
+    default:
f73620
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
f73620
+      break;
f73620
+    }
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_xfixes_set_property (GObject      *object,
f73620
+                                        guint         prop_id,
f73620
+                                        const GValue *value,
f73620
+                                        GParamSpec   *pspec)
f73620
+{
f73620
+  MetaCursorSpriteXfixes *sprite_xfixes = META_CURSOR_SPRITE_XFIXES (object);
f73620
+
f73620
+  switch (prop_id)
f73620
+    {
f73620
+    case PROP_DISPLAY:
f73620
+      sprite_xfixes->display = g_value_get_object (value);
f73620
+      break;
f73620
+    default:
f73620
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
f73620
+      break;
f73620
+    }
f73620
+}
f73620
+
f73620
+MetaCursorSpriteXfixes *
f73620
+meta_cursor_sprite_xfixes_new (MetaDisplay  *display,
f73620
+                               GError      **error)
f73620
+{
f73620
+  return g_initable_new (META_TYPE_CURSOR_SPRITE_XFIXES,
f73620
+                         NULL, error,
f73620
+                         "display", display,
f73620
+                         NULL);
f73620
+}
f73620
+
f73620
+static gboolean
f73620
+meta_cursor_sprite_xfixes_initable_init (GInitable     *initable,
f73620
+                                         GCancellable  *cancellable,
f73620
+                                         GError       **error)
f73620
+{
f73620
+  MetaCursorSpriteXfixes *sprite_xfixes =
f73620
+    META_CURSOR_SPRITE_XFIXES (initable);
f73620
+  MetaCursorSprite *sprite = META_CURSOR_SPRITE (sprite_xfixes);
f73620
+  XFixesCursorImage *cursor_image;
f73620
+  CoglTexture2D *texture;
f73620
+  uint8_t *cursor_data;
f73620
+  gboolean free_cursor_data;
f73620
+  ClutterBackend *clutter_backend;
f73620
+  CoglContext *cogl_context;
f73620
+
f73620
+  cursor_image = XFixesGetCursorImage (sprite_xfixes->display->xdisplay);
f73620
+  if (!cursor_image)
f73620
+    {
f73620
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
f73620
+                   "Failed to get cursor image");
f73620
+      return FALSE;
f73620
+    }
f73620
+
f73620
+  /*
f73620
+   * Like all X APIs, XFixesGetCursorImage() returns arrays of 32-bit
f73620
+   * quantities as arrays of long; we need to convert on 64 bit
f73620
+   */
f73620
+  if (sizeof (long) == 4)
f73620
+    {
f73620
+      cursor_data = (uint8_t *) cursor_image->pixels;
f73620
+      free_cursor_data = FALSE;
f73620
+    }
f73620
+  else
f73620
+    {
f73620
+      int i, j;
f73620
+      uint32_t *cursor_words;
f73620
+      unsigned long *p;
f73620
+      uint32_t *q;
f73620
+
f73620
+      cursor_words = g_new (uint32_t,
f73620
+                            cursor_image->width * cursor_image->height);
f73620
+      cursor_data = (uint8_t *) cursor_words;
f73620
+
f73620
+      p = cursor_image->pixels;
f73620
+      q = cursor_words;
f73620
+      for (j = 0; j < cursor_image->height; j++)
f73620
+        {
f73620
+          for (i = 0; i < cursor_image->width; i++)
f73620
+            *(q++) = *(p++);
f73620
+        }
f73620
+
f73620
+      free_cursor_data = TRUE;
f73620
+    }
f73620
+
f73620
+  clutter_backend = clutter_get_default_backend ();
f73620
+  cogl_context = clutter_backend_get_cogl_context (clutter_backend);
f73620
+  texture = cogl_texture_2d_new_from_data (cogl_context,
f73620
+                                          cursor_image->width,
f73620
+                                          cursor_image->height,
f73620
+                                          CLUTTER_CAIRO_FORMAT_ARGB32,
f73620
+                                          cursor_image->width * 4, /* stride */
f73620
+                                          cursor_data,
f73620
+                                          error);
f73620
+
f73620
+  if (free_cursor_data)
f73620
+    g_free (cursor_data);
f73620
+
f73620
+  if (!sprite)
f73620
+    return FALSE;
f73620
+
f73620
+  meta_cursor_sprite_set_texture (sprite,
f73620
+                                  COGL_TEXTURE (texture),
f73620
+                                  cursor_image->xhot,
f73620
+                                  cursor_image->yhot);
f73620
+  cogl_object_unref (texture);
f73620
+  XFree (cursor_image);
f73620
+
f73620
+  return TRUE;
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_screen_cast_xfixes_init_initable_iface (GInitableIface *iface)
f73620
+{
f73620
+  iface->init = meta_cursor_sprite_xfixes_initable_init;
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_xfixes_init (MetaCursorSpriteXfixes *sprite_xfixes)
f73620
+{
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_xfixes_class_init (MetaCursorSpriteXfixesClass *klass)
f73620
+{
f73620
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
f73620
+  MetaCursorSpriteClass *cursor_sprite_class = META_CURSOR_SPRITE_CLASS (klass);
f73620
+
f73620
+  object_class->get_property = meta_cursor_sprite_xfixes_get_property;
f73620
+  object_class->set_property = meta_cursor_sprite_xfixes_set_property;
f73620
+
f73620
+  cursor_sprite_class->realize_texture =
f73620
+    meta_cursor_sprite_xfixes_realize_texture;
f73620
+  cursor_sprite_class->is_animated = meta_cursor_sprite_xfixes_is_animated;
f73620
+
f73620
+  obj_props[PROP_DISPLAY] =
f73620
+    g_param_spec_object ("display",
f73620
+                         "display",
f73620
+                         "MetaDisplay",
f73620
+                         META_TYPE_DISPLAY,
f73620
+                         G_PARAM_READWRITE |
f73620
+                         G_PARAM_CONSTRUCT_ONLY |
f73620
+                         G_PARAM_STATIC_STRINGS);
f73620
+  g_object_class_install_properties (object_class, N_PROPS, obj_props);
f73620
+}
f73620
diff --git a/src/backends/x11/cm/meta-cursor-sprite-xfixes.h b/src/backends/x11/cm/meta-cursor-sprite-xfixes.h
f73620
new file mode 100644
f73620
index 000000000..c7073fc2c
f73620
--- /dev/null
f73620
+++ b/src/backends/x11/cm/meta-cursor-sprite-xfixes.h
f73620
@@ -0,0 +1,36 @@
f73620
+/*
f73620
+ * Copyright 2013, 2018 Red Hat, Inc.
f73620
+ *
f73620
+ * This program is free software; you can redistribute it and/or
f73620
+ * modify it under the terms of the GNU General Public License as
f73620
+ * published by the Free Software Foundation; either version 2 of the
f73620
+ * License, or (at your option) any later version.
f73620
+ *
f73620
+ * This program is distributed in the hope that it will be useful, but
f73620
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
f73620
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f73620
+ * General Public License for more details.
f73620
+ *
f73620
+ * You should have received a copy of the GNU General Public License
f73620
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
f73620
+ *
f73620
+ */
f73620
+
f73620
+#ifndef META_CURSOR_SPRITE_XFIXES_H
f73620
+#define META_CURSOR_SPRITE_XFIXES_H
f73620
+
f73620
+#include <glib-object.h>
f73620
+
f73620
+#include "backends/meta-cursor.h"
f73620
+#include "meta/types.h"
f73620
+
f73620
+#define META_TYPE_CURSOR_SPRITE_XFIXES (meta_cursor_sprite_xfixes_get_type ())
f73620
+G_DECLARE_FINAL_TYPE (MetaCursorSpriteXfixes,
f73620
+                      meta_cursor_sprite_xfixes,
f73620
+                      META, CURSOR_SPRITE_XFIXES,
f73620
+                      MetaCursorSprite)
f73620
+
f73620
+MetaCursorSpriteXfixes * meta_cursor_sprite_xfixes_new (MetaDisplay  *display,
f73620
+                                                        GError      **error);
f73620
+
f73620
+#endif /* META_CURSOR_SPRITE_XFIXES_H */
f73620
diff --git a/src/backends/x11/meta-cursor-renderer-x11.c b/src/backends/x11/meta-cursor-renderer-x11.c
f73620
index 82109f1f3..bb3100a91 100644
f73620
--- a/src/backends/x11/meta-cursor-renderer-x11.c
f73620
+++ b/src/backends/x11/meta-cursor-renderer-x11.c
f73620
@@ -30,6 +30,7 @@
f73620
 
f73620
 #include "meta-backend-x11.h"
f73620
 #include "meta-stage-private.h"
f73620
+#include "backends/meta-cursor-sprite-xcursor.h"
f73620
 
f73620
 struct _MetaCursorRendererX11Private
f73620
 {
f73620
@@ -59,13 +60,18 @@ meta_cursor_renderer_x11_update_cursor (MetaCursorRenderer *renderer,
f73620
 
f73620
   gboolean has_server_cursor = FALSE;
f73620
 
f73620
-  if (cursor_sprite)
f73620
+  if (cursor_sprite && META_IS_CURSOR_SPRITE_XCURSOR (cursor_sprite))
f73620
     {
f73620
-      MetaCursor cursor = meta_cursor_sprite_get_meta_cursor (cursor_sprite);
f73620
+      MetaCursorSpriteXcursor *sprite_xcursor =
f73620
+        META_CURSOR_SPRITE_XCURSOR (cursor_sprite);
f73620
+      MetaCursor cursor;
f73620
 
f73620
+      cursor = meta_cursor_sprite_xcursor_get_cursor (sprite_xcursor);
f73620
       if (cursor != META_CURSOR_NONE)
f73620
         {
f73620
-          Cursor xcursor = meta_cursor_create_x_cursor (xdisplay, cursor);
f73620
+          Cursor xcursor;
f73620
+
f73620
+          xcursor = meta_create_x_cursor (xdisplay, cursor);
f73620
           XDefineCursor (xdisplay, xwindow, xcursor);
f73620
           XFlush (xdisplay);
f73620
           XFreeCursor (xdisplay, xcursor);
f73620
diff --git a/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c b/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c
f73620
index da1a56038..0daae683c 100644
f73620
--- a/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c
f73620
+++ b/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c
f73620
@@ -26,6 +26,8 @@
f73620
 
f73620
 #include "backends/x11/nested/meta-cursor-renderer-x11-nested.h"
f73620
 
f73620
+#include <X11/Xcursor/Xcursor.h>
f73620
+
f73620
 #include "backends/x11/meta-backend-x11.h"
f73620
 
f73620
 struct _MetaCursorRendererX11Nested
f73620
diff --git a/src/core/display.c b/src/core/display.c
f73620
index d6da84b30..e7dd4534b 100644
f73620
--- a/src/core/display.c
f73620
+++ b/src/core/display.c
f73620
@@ -3018,7 +3018,7 @@ Cursor
f73620
 meta_display_create_x_cursor (MetaDisplay *display,
f73620
                               MetaCursor   cursor)
f73620
 {
f73620
-  return meta_cursor_create_x_cursor (display->xdisplay, cursor);
f73620
+  return meta_create_x_cursor (display->xdisplay, cursor);
f73620
 }
f73620
 
f73620
 MetaGestureTracker *
f73620
diff --git a/src/core/screen.c b/src/core/screen.c
f73620
index c14bba0cf..048104150 100644
f73620
--- a/src/core/screen.c
f73620
+++ b/src/core/screen.c
f73620
@@ -60,6 +60,7 @@
f73620
 #include "x11/xprops.h"
f73620
 
f73620
 #include "backends/x11/meta-backend-x11.h"
f73620
+#include "backends/meta-cursor-sprite-xcursor.h"
f73620
 
f73620
 static char* get_screen_name (MetaDisplay *display,
f73620
                               int          number);
f73620
@@ -1323,12 +1324,13 @@ find_highest_logical_monitor_scale (MetaBackend      *backend,
f73620
 }
f73620
 
f73620
 static void
f73620
-root_cursor_prepare_at (MetaCursorSprite *cursor_sprite,
f73620
-                        int               x,
f73620
-                        int               y,
f73620
-                        MetaScreen       *screen)
f73620
+root_cursor_prepare_at (MetaCursorSpriteXcursor *sprite_xcursor,
f73620
+                        int                      x,
f73620
+                        int                      y,
f73620
+                        MetaScreen              *screen)
f73620
 {
f73620
   MetaBackend *backend = meta_get_backend ();
f73620
+  MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (sprite_xcursor);
f73620
 
f73620
   if (meta_is_stage_views_scaled ())
f73620
     {
f73620
@@ -1337,7 +1339,7 @@ root_cursor_prepare_at (MetaCursorSprite *cursor_sprite,
f73620
       scale = find_highest_logical_monitor_scale (backend, cursor_sprite);
f73620
       if (scale != 0.0)
f73620
         {
f73620
-          meta_cursor_sprite_set_theme_scale (cursor_sprite, scale);
f73620
+          meta_cursor_sprite_xcursor_set_theme_scale (sprite_xcursor, scale);
f73620
           meta_cursor_sprite_set_texture_scale (cursor_sprite, 1.0 / scale);
f73620
         }
f73620
     }
f73620
@@ -1353,18 +1355,18 @@ root_cursor_prepare_at (MetaCursorSprite *cursor_sprite,
f73620
       /* Reload the cursor texture if the scale has changed. */
f73620
       if (logical_monitor)
f73620
         {
f73620
-          meta_cursor_sprite_set_theme_scale (cursor_sprite,
f73620
-                                              logical_monitor->scale);
f73620
+          meta_cursor_sprite_xcursor_set_theme_scale (sprite_xcursor,
f73620
+                                                      logical_monitor->scale);
f73620
           meta_cursor_sprite_set_texture_scale (cursor_sprite, 1.0);
f73620
         }
f73620
     }
f73620
 }
f73620
 
f73620
 static void
f73620
-manage_root_cursor_sprite_scale (MetaScreen       *screen,
f73620
-                                 MetaCursorSprite *cursor_sprite)
f73620
+manage_root_cursor_sprite_scale (MetaScreen              *screen,
f73620
+                                 MetaCursorSpriteXcursor *sprite_xcursor)
f73620
 {
f73620
-  g_signal_connect_object (cursor_sprite,
f73620
+  g_signal_connect_object (sprite_xcursor,
f73620
                            "prepare-at",
f73620
                            G_CALLBACK (root_cursor_prepare_at),
f73620
                            screen,
f73620
@@ -1377,17 +1379,18 @@ meta_screen_update_cursor (MetaScreen *screen)
f73620
   MetaDisplay *display = screen->display;
f73620
   MetaCursor cursor = screen->current_cursor;
f73620
   Cursor xcursor;
f73620
-  MetaCursorSprite *cursor_sprite;
f73620
+  MetaCursorSpriteXcursor *sprite_xcursor;
f73620
   MetaBackend *backend = meta_get_backend ();
f73620
   MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
f73620
 
f73620
-  cursor_sprite = meta_cursor_sprite_from_theme (cursor);
f73620
+  sprite_xcursor = meta_cursor_sprite_xcursor_new (cursor);
f73620
 
f73620
   if (meta_is_wayland_compositor ())
f73620
-    manage_root_cursor_sprite_scale (screen, cursor_sprite);
f73620
+    manage_root_cursor_sprite_scale (screen, sprite_xcursor);
f73620
 
f73620
-  meta_cursor_tracker_set_root_cursor (cursor_tracker, cursor_sprite);
f73620
-  g_object_unref (cursor_sprite);
f73620
+  meta_cursor_tracker_set_root_cursor (cursor_tracker,
f73620
+                                       META_CURSOR_SPRITE (sprite_xcursor));
f73620
+  g_object_unref (sprite_xcursor);
f73620
 
f73620
   /* Set a cursor for X11 applications that don't specify their own */
f73620
   xcursor = meta_display_create_x_cursor (display, cursor);
f73620
diff --git a/src/wayland/meta-cursor-sprite-wayland.c b/src/wayland/meta-cursor-sprite-wayland.c
f73620
new file mode 100644
f73620
index 000000000..7c14960ff
f73620
--- /dev/null
f73620
+++ b/src/wayland/meta-cursor-sprite-wayland.c
f73620
@@ -0,0 +1,75 @@
f73620
+/*
f73620
+ * Copyright 2015, 2018 Red Hat, Inc.
f73620
+ *
f73620
+ * This program is free software; you can redistribute it and/or
f73620
+ * modify it under the terms of the GNU General Public License as
f73620
+ * published by the Free Software Foundation; either version 2 of the
f73620
+ * License, or (at your option) any later version.
f73620
+ *
f73620
+ * This program is distributed in the hope that it will be useful, but
f73620
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
f73620
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f73620
+ * General Public License for more details.
f73620
+ *
f73620
+ * You should have received a copy of the GNU General Public License
f73620
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
f73620
+ *
f73620
+ */
f73620
+
f73620
+#include "config.h"
f73620
+
f73620
+#include "wayland/meta-cursor-sprite-wayland.h"
f73620
+
f73620
+struct _MetaCursorSpriteWayland
f73620
+{
f73620
+  MetaCursorSprite parent;
f73620
+
f73620
+  MetaWaylandSurface *surface;
f73620
+};
f73620
+
f73620
+G_DEFINE_TYPE (MetaCursorSpriteWayland,
f73620
+               meta_cursor_sprite_wayland,
f73620
+               META_TYPE_CURSOR_SPRITE)
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_wayland_realize_texture (MetaCursorSprite *sprite)
f73620
+{
f73620
+}
f73620
+
f73620
+static gboolean
f73620
+meta_cursor_sprite_wayland_is_animated (MetaCursorSprite *sprite)
f73620
+{
f73620
+  return FALSE;
f73620
+}
f73620
+
f73620
+MetaCursorSpriteWayland *
f73620
+meta_cursor_sprite_wayland_new (MetaWaylandSurface *surface)
f73620
+{
f73620
+  MetaCursorSpriteWayland *sprite_wayland;
f73620
+
f73620
+  sprite_wayland = g_object_new (META_TYPE_CURSOR_SPRITE_WAYLAND, NULL);
f73620
+  sprite_wayland->surface = surface;
f73620
+
f73620
+  return sprite_wayland;
f73620
+}
f73620
+
f73620
+MetaWaylandBuffer *
f73620
+meta_cursor_sprite_wayland_get_buffer (MetaCursorSpriteWayland *sprite_wayland)
f73620
+{
f73620
+  return meta_wayland_surface_get_buffer (sprite_wayland->surface);
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_wayland_init (MetaCursorSpriteWayland *sprite_wayland)
f73620
+{
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_cursor_sprite_wayland_class_init (MetaCursorSpriteWaylandClass *klass)
f73620
+{
f73620
+  MetaCursorSpriteClass *cursor_sprite_class = META_CURSOR_SPRITE_CLASS (klass);
f73620
+
f73620
+  cursor_sprite_class->realize_texture =
f73620
+    meta_cursor_sprite_wayland_realize_texture;
f73620
+  cursor_sprite_class->is_animated = meta_cursor_sprite_wayland_is_animated;
f73620
+}
f73620
diff --git a/src/wayland/meta-cursor-sprite-wayland.h b/src/wayland/meta-cursor-sprite-wayland.h
f73620
new file mode 100644
f73620
index 000000000..107698f3f
f73620
--- /dev/null
f73620
+++ b/src/wayland/meta-cursor-sprite-wayland.h
f73620
@@ -0,0 +1,35 @@
f73620
+/*
f73620
+ * Copyright 2013, 2018 Red Hat, Inc.
f73620
+ *
f73620
+ * This program is free software; you can redistribute it and/or
f73620
+ * modify it under the terms of the GNU General Public License as
f73620
+ * published by the Free Software Foundation; either version 2 of the
f73620
+ * License, or (at your option) any later version.
f73620
+ *
f73620
+ * This program is distributed in the hope that it will be useful, but
f73620
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
f73620
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f73620
+ * General Public License for more details.
f73620
+ *
f73620
+ * You should have received a copy of the GNU General Public License
f73620
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
f73620
+ *
f73620
+ */
f73620
+
f73620
+#ifndef META_CURSOR_SPRITE_WAYLAND_H
f73620
+#define META_CURSOR_SPRITE_WAYLAND_H
f73620
+
f73620
+#include <glib-object.h>
f73620
+
f73620
+#include "backends/meta-cursor.h"
f73620
+#include "wayland/meta-wayland-surface.h"
f73620
+
f73620
+#define META_TYPE_CURSOR_SPRITE_WAYLAND meta_cursor_sprite_wayland_get_type ()
f73620
+G_DECLARE_FINAL_TYPE (MetaCursorSpriteWayland, meta_cursor_sprite_wayland,
f73620
+                      META, CURSOR_SPRITE_WAYLAND, MetaCursorSprite)
f73620
+
f73620
+MetaCursorSpriteWayland * meta_cursor_sprite_wayland_new (MetaWaylandSurface *surface);
f73620
+
f73620
+MetaWaylandBuffer * meta_cursor_sprite_wayland_get_buffer (MetaCursorSpriteWayland *sprite_wayland);
f73620
+
f73620
+#endif /* META_CURSOR_SPRITE_WAYLAND_H */
f73620
diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c
f73620
index 55564492a..c759eefc1 100644
f73620
--- a/src/wayland/meta-wayland-buffer.c
f73620
+++ b/src/wayland/meta-wayland-buffer.c
f73620
@@ -88,6 +88,12 @@ meta_wayland_buffer_from_resource (struct wl_resource *resource)
f73620
   return buffer;
f73620
 }
f73620
 
f73620
+struct wl_resource *
f73620
+meta_wayland_buffer_get_resource (MetaWaylandBuffer *buffer)
f73620
+{
f73620
+  return buffer->resource;
f73620
+}
f73620
+
f73620
 static gboolean
f73620
 meta_wayland_buffer_is_realized (MetaWaylandBuffer *buffer)
f73620
 {
f73620
diff --git a/src/wayland/meta-wayland-buffer.h b/src/wayland/meta-wayland-buffer.h
f73620
index 5345033c2..e00a41e09 100644
f73620
--- a/src/wayland/meta-wayland-buffer.h
f73620
+++ b/src/wayland/meta-wayland-buffer.h
f73620
@@ -68,6 +68,7 @@ G_DECLARE_FINAL_TYPE (MetaWaylandBuffer, meta_wayland_buffer,
f73620
                       META, WAYLAND_BUFFER, GObject);
f73620
 
f73620
 MetaWaylandBuffer *     meta_wayland_buffer_from_resource       (struct wl_resource    *resource);
f73620
+struct wl_resource *    meta_wayland_buffer_get_resource        (MetaWaylandBuffer     *buffer);
f73620
 gboolean                meta_wayland_buffer_attach              (MetaWaylandBuffer     *buffer,
f73620
                                                                  GError               **error);
f73620
 CoglTexture *           meta_wayland_buffer_get_texture         (MetaWaylandBuffer     *buffer);
f73620
diff --git a/src/wayland/meta-wayland-surface-role-cursor.c b/src/wayland/meta-wayland-cursor-surface.c
f73620
similarity index 52%
f73620
rename from src/wayland/meta-wayland-surface-role-cursor.c
f73620
rename to src/wayland/meta-wayland-cursor-surface.c
f73620
index d118a8917..d08af9e8c 100644
f73620
--- a/src/wayland/meta-wayland-surface-role-cursor.c
f73620
+++ b/src/wayland/meta-wayland-cursor-surface.c
f73620
@@ -23,7 +23,7 @@
f73620
 
f73620
 #include <cogl/cogl.h>
f73620
 #include <cogl/cogl-wayland-server.h>
f73620
-#include "meta-wayland-surface-role-cursor.h"
f73620
+#include "meta-wayland-cursor-surface.h"
f73620
 #include "meta-wayland-buffer.h"
f73620
 #include "meta-xwayland.h"
f73620
 #include "screen-private.h"
f73620
@@ -31,35 +31,38 @@
f73620
 #include "backends/meta-backend-private.h"
f73620
 #include "backends/meta-logical-monitor.h"
f73620
 #include "core/boxes-private.h"
f73620
+#include "wayland/meta-cursor-sprite-wayland.h"
f73620
 
f73620
-typedef struct _MetaWaylandSurfaceRoleCursorPrivate MetaWaylandSurfaceRoleCursorPrivate;
f73620
+typedef struct _MetaWaylandCursorSurfacePrivate MetaWaylandCursorSurfacePrivate;
f73620
 
f73620
-struct _MetaWaylandSurfaceRoleCursorPrivate
f73620
+struct _MetaWaylandCursorSurfacePrivate
f73620
 {
f73620
   int hot_x;
f73620
   int hot_y;
f73620
-  MetaCursorSprite *cursor_sprite;
f73620
+  MetaCursorSpriteWayland *cursor_sprite;
f73620
   MetaCursorRenderer *cursor_renderer;
f73620
   MetaWaylandBuffer *buffer;
f73620
   struct wl_list frame_callbacks;
f73620
   gulong cursor_painted_handler_id;
f73620
 };
f73620
 
f73620
-G_DEFINE_TYPE_WITH_PRIVATE (MetaWaylandSurfaceRoleCursor,
f73620
-                            meta_wayland_surface_role_cursor,
f73620
+G_DEFINE_TYPE_WITH_PRIVATE (MetaWaylandCursorSurface,
f73620
+                            meta_wayland_cursor_surface,
f73620
                             META_TYPE_WAYLAND_SURFACE_ROLE)
f73620
 
f73620
 static void
f73620
-update_cursor_sprite_texture (MetaWaylandSurfaceRoleCursor *cursor_role)
f73620
+update_cursor_sprite_texture (MetaWaylandCursorSurface *cursor_surface)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv = meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
-  MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (cursor_role));
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
+  MetaWaylandSurface *surface =
f73620
+    meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (cursor_surface));
f73620
   MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
f73620
-  MetaCursorSprite *cursor_sprite = priv->cursor_sprite;
f73620
+  MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (priv->cursor_sprite);
f73620
 
f73620
   g_return_if_fail (!buffer || buffer->texture);
f73620
 
f73620
-  if (!priv->cursor_renderer || !cursor_sprite)
f73620
+  if (!priv->cursor_renderer)
f73620
     return;
f73620
 
f73620
   if (buffer)
f73620
@@ -68,20 +71,6 @@ update_cursor_sprite_texture (MetaWaylandSurfaceRoleCursor *cursor_role)
f73620
                                       buffer->texture,
f73620
                                       priv->hot_x * surface->scale,
f73620
                                       priv->hot_y * surface->scale);
f73620
-
f73620
-      if (priv->buffer)
f73620
-        {
f73620
-          struct wl_resource *buffer_resource;
f73620
-
f73620
-          g_assert (priv->buffer == buffer);
f73620
-          buffer_resource = buffer->resource;
f73620
-          meta_cursor_renderer_realize_cursor_from_wl_buffer (priv->cursor_renderer,
f73620
-                                                              cursor_sprite,
f73620
-                                                              buffer_resource);
f73620
-
f73620
-          meta_wayland_surface_unref_buffer_use_count (surface);
f73620
-          g_clear_object (&priv->buffer);
f73620
-        }
f73620
     }
f73620
   else
f73620
     {
f73620
@@ -92,12 +81,12 @@ update_cursor_sprite_texture (MetaWaylandSurfaceRoleCursor *cursor_role)
f73620
 }
f73620
 
f73620
 static void
f73620
-cursor_sprite_prepare_at (MetaCursorSprite             *cursor_sprite,
f73620
-                          int                           x,
f73620
-                          int                           y,
f73620
-                          MetaWaylandSurfaceRoleCursor *cursor_role)
f73620
+cursor_sprite_prepare_at (MetaCursorSprite         *cursor_sprite,
f73620
+                          int                       x,
f73620
+                          int                       y,
f73620
+                          MetaWaylandCursorSurface *cursor_surface)
f73620
 {
f73620
-  MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_role);
f73620
+  MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_surface);
f73620
   MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role);
f73620
 
f73620
   if (!meta_xwayland_is_xwayland_surface (surface))
f73620
@@ -126,14 +115,14 @@ cursor_sprite_prepare_at (MetaCursorSprite             *cursor_sprite,
f73620
 }
f73620
 
f73620
 static void
f73620
-cursor_surface_role_assigned (MetaWaylandSurfaceRole *surface_role)
f73620
+meta_wayland_cursor_surface_assigned (MetaWaylandSurfaceRole *surface_role)
f73620
 {
f73620
   MetaWaylandSurface *surface =
f73620
     meta_wayland_surface_role_get_surface (surface_role);
f73620
-  MetaWaylandSurfaceRoleCursor *cursor_role =
f73620
-    META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role);
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurface *cursor_surface =
f73620
+    META_WAYLAND_CURSOR_SURFACE (surface_role);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
 
f73620
   wl_list_insert_list (&priv->frame_callbacks,
f73620
                        &surface->pending_frame_callback_list);
f73620
@@ -141,13 +130,13 @@ cursor_surface_role_assigned (MetaWaylandSurfaceRole *surface_role)
f73620
 }
f73620
 
f73620
 static void
f73620
-cursor_surface_role_pre_commit (MetaWaylandSurfaceRole  *surface_role,
f73620
-                                MetaWaylandPendingState *pending)
f73620
+meta_wayland_cursor_surface_pre_commit (MetaWaylandSurfaceRole  *surface_role,
f73620
+                                        MetaWaylandPendingState *pending)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursor *cursor_role =
f73620
-    META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role);
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurface *cursor_surface =
f73620
+    META_WAYLAND_CURSOR_SURFACE (surface_role);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
   MetaWaylandSurface *surface =
f73620
     meta_wayland_surface_role_get_surface (surface_role);
f73620
 
f73620
@@ -159,13 +148,13 @@ cursor_surface_role_pre_commit (MetaWaylandSurfaceRole  *surface_role,
f73620
 }
f73620
 
f73620
 static void
f73620
-cursor_surface_role_commit (MetaWaylandSurfaceRole  *surface_role,
f73620
-                            MetaWaylandPendingState *pending)
f73620
+meta_wayland_cursor_surface_commit (MetaWaylandSurfaceRole  *surface_role,
f73620
+                                    MetaWaylandPendingState *pending)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursor *cursor_role =
f73620
-    META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role);
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurface *cursor_surface =
f73620
+    META_WAYLAND_CURSOR_SURFACE (surface_role);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
   MetaWaylandSurface *surface =
f73620
     meta_wayland_surface_role_get_surface (surface_role);
f73620
   MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
f73620
@@ -182,19 +171,19 @@ cursor_surface_role_commit (MetaWaylandSurfaceRole  *surface_role,
f73620
   wl_list_init (&pending->frame_callback_list);
f73620
 
f73620
   if (pending->newly_attached)
f73620
-    update_cursor_sprite_texture (META_WAYLAND_SURFACE_ROLE_CURSOR (surface_role));
f73620
+    update_cursor_sprite_texture (META_WAYLAND_CURSOR_SURFACE (surface_role));
f73620
 }
f73620
 
f73620
 static gboolean
f73620
-cursor_surface_role_is_on_logical_monitor (MetaWaylandSurfaceRole *role,
f73620
-                                           MetaLogicalMonitor     *logical_monitor)
f73620
+meta_wayland_cursor_surface_is_on_logical_monitor (MetaWaylandSurfaceRole *role,
f73620
+                                                   MetaLogicalMonitor     *logical_monitor)
f73620
 {
f73620
   MetaWaylandSurface *surface =
f73620
     meta_wayland_surface_role_get_surface (role);
f73620
-  MetaWaylandSurfaceRoleCursor *cursor_role =
f73620
-    META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurface *cursor_surface =
f73620
+    META_WAYLAND_CURSOR_SURFACE (surface->role);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
   ClutterPoint point;
f73620
   ClutterRect logical_monitor_rect;
f73620
 
f73620
@@ -207,12 +196,12 @@ cursor_surface_role_is_on_logical_monitor (MetaWaylandSurfaceRole *role,
f73620
 }
f73620
 
f73620
 static void
f73620
-cursor_surface_role_dispose (GObject *object)
f73620
+meta_wayland_cursor_surface_dispose (GObject *object)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursor *cursor_role =
f73620
-    META_WAYLAND_SURFACE_ROLE_CURSOR (object);
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurface *cursor_surface =
f73620
+    META_WAYLAND_CURSOR_SURFACE (object);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
   MetaWaylandSurface *surface =
f73620
     meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (object));
f73620
   MetaWaylandFrameCallback *cb, *next;
f73620
@@ -221,7 +210,7 @@ cursor_surface_role_dispose (GObject *object)
f73620
     wl_resource_destroy (cb->resource);
f73620
 
f73620
   g_signal_handlers_disconnect_by_func (priv->cursor_sprite,
f73620
-                                        cursor_sprite_prepare_at, cursor_role);
f73620
+                                        cursor_sprite_prepare_at, cursor_surface);
f73620
 
f73620
   g_clear_object (&priv->cursor_renderer);
f73620
   g_clear_object (&priv->cursor_sprite);
f73620
@@ -232,18 +221,18 @@ cursor_surface_role_dispose (GObject *object)
f73620
       g_clear_object (&priv->buffer);
f73620
     }
f73620
 
f73620
-  G_OBJECT_CLASS (meta_wayland_surface_role_cursor_parent_class)->dispose (object);
f73620
+  G_OBJECT_CLASS (meta_wayland_cursor_surface_parent_class)->dispose (object);
f73620
 }
f73620
 
f73620
 static void
f73620
-cursor_surface_role_constructed (GObject *object)
f73620
+meta_wayland_cursor_surface_constructed (GObject *object)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursor *cursor_role =
f73620
-    META_WAYLAND_SURFACE_ROLE_CURSOR (object);
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurface *cursor_surface =
f73620
+    META_WAYLAND_CURSOR_SURFACE (object);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
   MetaWaylandSurfaceRole *surface_role =
f73620
-    META_WAYLAND_SURFACE_ROLE (cursor_role);
f73620
+    META_WAYLAND_SURFACE_ROLE (cursor_surface);
f73620
   MetaWaylandSurface *surface =
f73620
     meta_wayland_surface_role_get_surface (surface_role);
f73620
   MetaWaylandBuffer *buffer;
f73620
@@ -257,55 +246,57 @@ cursor_surface_role_constructed (GObject *object)
f73620
       g_set_object (&priv->buffer, buffer);
f73620
       meta_wayland_surface_ref_buffer_use_count (surface);
f73620
     }
f73620
-}
f73620
 
f73620
-static void
f73620
-meta_wayland_surface_role_cursor_init (MetaWaylandSurfaceRoleCursor *role)
f73620
-{
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (role);
f73620
-
f73620
-  priv->cursor_sprite = meta_cursor_sprite_new ();
f73620
+  priv->cursor_sprite = meta_cursor_sprite_wayland_new (surface);
f73620
   g_signal_connect_object (priv->cursor_sprite,
f73620
                            "prepare-at",
f73620
                            G_CALLBACK (cursor_sprite_prepare_at),
f73620
-                           role,
f73620
+                           cursor_surface,
f73620
                            0);
f73620
+}
f73620
+
f73620
+static void
f73620
+meta_wayland_cursor_surface_init (MetaWaylandCursorSurface *role)
f73620
+{
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (role);
f73620
+
f73620
   wl_list_init (&priv->frame_callbacks);
f73620
 }
f73620
 
f73620
 static void
f73620
-meta_wayland_surface_role_cursor_class_init (MetaWaylandSurfaceRoleCursorClass *klass)
f73620
+meta_wayland_cursor_surface_class_init (MetaWaylandCursorSurfaceClass *klass)
f73620
 {
f73620
   MetaWaylandSurfaceRoleClass *surface_role_class =
f73620
     META_WAYLAND_SURFACE_ROLE_CLASS (klass);
f73620
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
f73620
 
f73620
-  surface_role_class->assigned = cursor_surface_role_assigned;
f73620
-  surface_role_class->pre_commit = cursor_surface_role_pre_commit;
f73620
-  surface_role_class->commit = cursor_surface_role_commit;
f73620
-  surface_role_class->is_on_logical_monitor = cursor_surface_role_is_on_logical_monitor;
f73620
+  surface_role_class->assigned = meta_wayland_cursor_surface_assigned;
f73620
+  surface_role_class->pre_commit = meta_wayland_cursor_surface_pre_commit;
f73620
+  surface_role_class->commit = meta_wayland_cursor_surface_commit;
f73620
+  surface_role_class->is_on_logical_monitor =
f73620
+    meta_wayland_cursor_surface_is_on_logical_monitor;
f73620
 
f73620
-  object_class->constructed = cursor_surface_role_constructed;
f73620
-  object_class->dispose = cursor_surface_role_dispose;
f73620
+  object_class->constructed = meta_wayland_cursor_surface_constructed;
f73620
+  object_class->dispose = meta_wayland_cursor_surface_dispose;
f73620
 }
f73620
 
f73620
 MetaCursorSprite *
f73620
-meta_wayland_surface_role_cursor_get_sprite (MetaWaylandSurfaceRoleCursor *cursor_role)
f73620
+meta_wayland_cursor_surface_get_sprite (MetaWaylandCursorSurface *cursor_surface)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
 
f73620
-  return priv->cursor_sprite;
f73620
+  return META_CURSOR_SPRITE (priv->cursor_sprite);
f73620
 }
f73620
 
f73620
 void
f73620
-meta_wayland_surface_role_cursor_set_hotspot (MetaWaylandSurfaceRoleCursor *cursor_role,
f73620
-                                              gint                          hotspot_x,
f73620
-                                              gint                          hotspot_y)
f73620
+meta_wayland_cursor_surface_set_hotspot (MetaWaylandCursorSurface *cursor_surface,
f73620
+                                         int                       hotspot_x,
f73620
+                                         int                       hotspot_y)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
 
f73620
   if (priv->hot_x == hotspot_x &&
f73620
       priv->hot_y == hotspot_y)
f73620
@@ -313,16 +304,16 @@ meta_wayland_surface_role_cursor_set_hotspot (MetaWaylandSurfaceRoleCursor *curs
f73620
 
f73620
   priv->hot_x = hotspot_x;
f73620
   priv->hot_y = hotspot_y;
f73620
-  update_cursor_sprite_texture (cursor_role);
f73620
+  update_cursor_sprite_texture (cursor_surface);
f73620
 }
f73620
 
f73620
 void
f73620
-meta_wayland_surface_role_cursor_get_hotspot (MetaWaylandSurfaceRoleCursor *cursor_role,
f73620
-                                              gint                         *hotspot_x,
f73620
-                                              gint                         *hotspot_y)
f73620
+meta_wayland_cursor_surface_get_hotspot (MetaWaylandCursorSurface *cursor_surface,
f73620
+                                         int                      *hotspot_x,
f73620
+                                         int                      *hotspot_y)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
 
f73620
   if (hotspot_x)
f73620
     *hotspot_x = priv->hot_x;
f73620
@@ -331,15 +322,15 @@ meta_wayland_surface_role_cursor_get_hotspot (MetaWaylandSurfaceRoleCursor *curs
f73620
 }
f73620
 
f73620
 static void
f73620
-on_cursor_painted (MetaCursorRenderer           *renderer,
f73620
-                   MetaCursorSprite             *displayed_sprite,
f73620
-                   MetaWaylandSurfaceRoleCursor *cursor_role)
f73620
+on_cursor_painted (MetaCursorRenderer       *renderer,
f73620
+                   MetaCursorSprite         *displayed_sprite,
f73620
+                   MetaWaylandCursorSurface *cursor_surface)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
   guint32 time = (guint32) (g_get_monotonic_time () / 1000);
f73620
 
f73620
-  if (displayed_sprite != priv->cursor_sprite)
f73620
+  if (displayed_sprite != META_CURSOR_SPRITE (priv->cursor_sprite))
f73620
     return;
f73620
 
f73620
   while (!wl_list_empty (&priv->frame_callbacks))
f73620
@@ -353,11 +344,11 @@ on_cursor_painted (MetaCursorRenderer           *renderer,
f73620
 }
f73620
 
f73620
 void
f73620
-meta_wayland_surface_role_cursor_set_renderer (MetaWaylandSurfaceRoleCursor *cursor_role,
f73620
-                                               MetaCursorRenderer           *renderer)
f73620
+meta_wayland_cursor_surface_set_renderer (MetaWaylandCursorSurface *cursor_surface,
f73620
+                                          MetaCursorRenderer       *renderer)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
 
f73620
   if (priv->cursor_renderer == renderer)
f73620
     return;
f73620
@@ -373,19 +364,19 @@ meta_wayland_surface_role_cursor_set_renderer (MetaWaylandSurfaceRoleCursor *cur
f73620
     {
f73620
       priv->cursor_painted_handler_id =
f73620
         g_signal_connect_object (renderer, "cursor-painted",
f73620
-                                 G_CALLBACK (on_cursor_painted), cursor_role, 0);
f73620
+                                 G_CALLBACK (on_cursor_painted), cursor_surface, 0);
f73620
       g_object_ref (renderer);
f73620
     }
f73620
 
f73620
   priv->cursor_renderer = renderer;
f73620
-  update_cursor_sprite_texture (cursor_role);
f73620
+  update_cursor_sprite_texture (cursor_surface);
f73620
 }
f73620
 
f73620
 MetaCursorRenderer *
f73620
-meta_wayland_surface_role_cursor_get_renderer (MetaWaylandSurfaceRoleCursor *cursor_role)
f73620
+meta_wayland_cursor_surface_get_renderer (MetaWaylandCursorSurface *cursor_surface)
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursorPrivate *priv =
f73620
-    meta_wayland_surface_role_cursor_get_instance_private (cursor_role);
f73620
+  MetaWaylandCursorSurfacePrivate *priv =
f73620
+    meta_wayland_cursor_surface_get_instance_private (cursor_surface);
f73620
 
f73620
   return priv->cursor_renderer;
f73620
 }
f73620
diff --git a/src/wayland/meta-wayland-cursor-surface.h b/src/wayland/meta-wayland-cursor-surface.h
f73620
new file mode 100644
f73620
index 000000000..2461a85b3
f73620
--- /dev/null
f73620
+++ b/src/wayland/meta-wayland-cursor-surface.h
f73620
@@ -0,0 +1,52 @@
f73620
+/*
f73620
+ * Wayland Support
f73620
+ *
f73620
+ * Copyright (C) 2015 Red Hat, Inc.
f73620
+ *
f73620
+ * This program is free software; you can redistribute it and/or
f73620
+ * modify it under the terms of the GNU General Public License as
f73620
+ * published by the Free Software Foundation; either version 2 of the
f73620
+ * License, or (at your option) any later version.
f73620
+ *
f73620
+ * This program is distributed in the hope that it will be useful, but
f73620
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
f73620
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f73620
+ * General Public License for more details.
f73620
+ *
f73620
+ * You should have received a copy of the GNU General Public License
f73620
+ * along with this program; if not, write to the Free Software
f73620
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
f73620
+ * 02111-1307, USA.
f73620
+ */
f73620
+
f73620
+#ifndef META_WAYLAND_CURSOR_SURFACE_H
f73620
+#define META_WAYLAND_CURSOR_SURFACE_H
f73620
+
f73620
+#include "meta-wayland-surface.h"
f73620
+#include "backends/meta-cursor-renderer.h"
f73620
+
f73620
+struct _MetaWaylandCursorSurfaceClass
f73620
+{
f73620
+  MetaWaylandSurfaceRoleClass parent_class;
f73620
+};
f73620
+
f73620
+#define META_TYPE_WAYLAND_CURSOR_SURFACE (meta_wayland_cursor_surface_get_type ())
f73620
+G_DECLARE_DERIVABLE_TYPE (MetaWaylandCursorSurface,
f73620
+                          meta_wayland_cursor_surface,
f73620
+                          META, WAYLAND_CURSOR_SURFACE,
f73620
+                          MetaWaylandSurfaceRole);
f73620
+
f73620
+MetaCursorSprite *   meta_wayland_cursor_surface_get_sprite   (MetaWaylandCursorSurface *cursor_surface);
f73620
+
f73620
+void                 meta_wayland_cursor_surface_set_hotspot  (MetaWaylandCursorSurface *cursor_surface,
f73620
+                                                               int                       hotspot_x,
f73620
+                                                               int                       hotspot_y);
f73620
+void                 meta_wayland_cursor_surface_get_hotspot  (MetaWaylandCursorSurface *cursor_surface,
f73620
+                                                               int                       *hotspot_x,
f73620
+                                                               int                       *hotspot_y);
f73620
+void                 meta_wayland_cursor_surface_set_renderer (MetaWaylandCursorSurface *cursor_surface,
f73620
+                                                               MetaCursorRenderer       *renderer);
f73620
+MetaCursorRenderer * meta_wayland_cursor_surface_get_renderer (MetaWaylandCursorSurface *cursor_surface);
f73620
+
f73620
+
f73620
+#endif /* META_WAYLAND_CURSOR_SURFACE_H */
f73620
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
f73620
index d5c90c169..e8138576e 100644
f73620
--- a/src/wayland/meta-wayland-pointer.c
f73620
+++ b/src/wayland/meta-wayland-pointer.c
f73620
@@ -55,7 +55,7 @@
f73620
 #include "meta-wayland-seat.h"
f73620
 #include "meta-wayland-surface.h"
f73620
 #include "meta-wayland-buffer.h"
f73620
-#include "meta-wayland-surface-role-cursor.h"
f73620
+#include "meta-wayland-cursor-surface.h"
f73620
 #include "meta-xwayland.h"
f73620
 #include "meta-cursor.h"
f73620
 #include "meta-cursor-tracker-private.h"
f73620
@@ -1025,10 +1025,10 @@ meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
f73620
 
f73620
       if (pointer->cursor_surface)
f73620
         {
f73620
-          MetaWaylandSurfaceRoleCursor *cursor_role =
f73620
-            META_WAYLAND_SURFACE_ROLE_CURSOR (pointer->cursor_surface->role);
f73620
+          MetaWaylandCursorSurface *cursor_surface =
f73620
+            META_WAYLAND_CURSOR_SURFACE (pointer->cursor_surface->role);
f73620
 
f73620
-          cursor_sprite = meta_wayland_surface_role_cursor_get_sprite (cursor_role);
f73620
+          cursor_sprite = meta_wayland_cursor_surface_get_sprite (cursor_surface);
f73620
         }
f73620
 
f73620
       meta_cursor_tracker_set_window_cursor (cursor_tracker, cursor_sprite);
f73620
@@ -1102,7 +1102,7 @@ pointer_set_cursor (struct wl_client *client,
f73620
 
f73620
   if (surface &&
f73620
       !meta_wayland_surface_assign_role (surface,
f73620
-                                         META_TYPE_WAYLAND_SURFACE_ROLE_CURSOR,
f73620
+                                         META_TYPE_WAYLAND_CURSOR_SURFACE,
f73620
                                          NULL))
f73620
     {
f73620
       wl_resource_post_error (resource, WL_POINTER_ERROR_ROLE,
f73620
@@ -1115,13 +1115,13 @@ pointer_set_cursor (struct wl_client *client,
f73620
     {
f73620
       MetaCursorRenderer *cursor_renderer =
f73620
         meta_backend_get_cursor_renderer (meta_get_backend ());
f73620
-      MetaWaylandSurfaceRoleCursor *cursor_role;
f73620
+      MetaWaylandCursorSurface *cursor_surface;
f73620
 
f73620
-      cursor_role = META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
f73620
-      meta_wayland_surface_role_cursor_set_renderer (cursor_role,
f73620
-                                                     cursor_renderer);
f73620
-      meta_wayland_surface_role_cursor_set_hotspot (cursor_role,
f73620
-                                                    hot_x, hot_y);
f73620
+      cursor_surface = META_WAYLAND_CURSOR_SURFACE (surface->role);
f73620
+      meta_wayland_cursor_surface_set_renderer (cursor_surface,
f73620
+                                                cursor_renderer);
f73620
+      meta_wayland_cursor_surface_set_hotspot (cursor_surface,
f73620
+                                               hot_x, hot_y);
f73620
     }
f73620
 
f73620
   meta_wayland_pointer_set_cursor_surface (pointer, surface);
f73620
diff --git a/src/wayland/meta-wayland-surface-role-cursor.h b/src/wayland/meta-wayland-surface-role-cursor.h
f73620
deleted file mode 100644
f73620
index b6d6d4a6a..000000000
f73620
--- a/src/wayland/meta-wayland-surface-role-cursor.h
f73620
+++ /dev/null
f73620
@@ -1,52 +0,0 @@
f73620
-/*
f73620
- * Wayland Support
f73620
- *
f73620
- * Copyright (C) 2015 Red Hat, Inc.
f73620
- *
f73620
- * This program is free software; you can redistribute it and/or
f73620
- * modify it under the terms of the GNU General Public License as
f73620
- * published by the Free Software Foundation; either version 2 of the
f73620
- * License, or (at your option) any later version.
f73620
- *
f73620
- * This program is distributed in the hope that it will be useful, but
f73620
- * WITHOUT ANY WARRANTY; without even the implied warranty of
f73620
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f73620
- * General Public License for more details.
f73620
- *
f73620
- * You should have received a copy of the GNU General Public License
f73620
- * along with this program; if not, write to the Free Software
f73620
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
f73620
- * 02111-1307, USA.
f73620
- */
f73620
-
f73620
-#ifndef META_WAYLAND_SURFACE_ROLE_CURSOR_H
f73620
-#define META_WAYLAND_SURFACE_ROLE_CURSOR_H
f73620
-
f73620
-#include "meta-wayland-surface.h"
f73620
-#include "backends/meta-cursor-renderer.h"
f73620
-
f73620
-struct _MetaWaylandSurfaceRoleCursorClass
f73620
-{
f73620
-  MetaWaylandSurfaceRoleClass parent_class;
f73620
-};
f73620
-
f73620
-#define META_TYPE_WAYLAND_SURFACE_ROLE_CURSOR (meta_wayland_surface_role_cursor_get_type ())
f73620
-G_DECLARE_DERIVABLE_TYPE (MetaWaylandSurfaceRoleCursor,
f73620
-                          meta_wayland_surface_role_cursor,
f73620
-                          META, WAYLAND_SURFACE_ROLE_CURSOR,
f73620
-                          MetaWaylandSurfaceRole);
f73620
-
f73620
-MetaCursorSprite *   meta_wayland_surface_role_cursor_get_sprite   (MetaWaylandSurfaceRoleCursor *cursor_role);
f73620
-
f73620
-void                 meta_wayland_surface_role_cursor_set_hotspot  (MetaWaylandSurfaceRoleCursor *cursor_role,
f73620
-                                                                    gint                          hotspot_x,
f73620
-                                                                    gint                          hotspot_y);
f73620
-void                 meta_wayland_surface_role_cursor_get_hotspot  (MetaWaylandSurfaceRoleCursor *cursor_role,
f73620
-                                                                    gint                         *hotspot_x,
f73620
-                                                                    gint                         *hotspot_y);
f73620
-void                 meta_wayland_surface_role_cursor_set_renderer (MetaWaylandSurfaceRoleCursor *cursor_role,
f73620
-                                                                    MetaCursorRenderer           *renderer);
f73620
-MetaCursorRenderer * meta_wayland_surface_role_cursor_get_renderer (MetaWaylandSurfaceRoleCursor *cursor_role);
f73620
-
f73620
-
f73620
-#endif /* META_WAYLAND_SURFACE_ROLE_CURSOR_H */
f73620
diff --git a/src/wayland/meta-wayland-surface-role-tablet-cursor.c b/src/wayland/meta-wayland-tablet-cursor-surface.c
f73620
similarity index 63%
f73620
rename from src/wayland/meta-wayland-surface-role-tablet-cursor.c
f73620
rename to src/wayland/meta-wayland-tablet-cursor-surface.c
f73620
index 075a5e4f6..808bf2820 100644
f73620
--- a/src/wayland/meta-wayland-surface-role-tablet-cursor.c
f73620
+++ b/src/wayland/meta-wayland-tablet-cursor-surface.c
f73620
@@ -20,23 +20,24 @@
f73620
  */
f73620
 
f73620
 #include "config.h"
f73620
-#include "meta-wayland-surface-role-tablet-cursor.h"
f73620
 
f73620
-struct _MetaWaylandSurfaceRoleTabletCursor
f73620
+#include "meta-wayland-tablet-cursor-surface.h"
f73620
+
f73620
+struct _MetaWaylandTabletCursorSurface
f73620
 {
f73620
-  MetaWaylandSurfaceRoleCursor parent;
f73620
+  MetaWaylandCursorSurface parent;
f73620
 };
f73620
 
f73620
-G_DEFINE_TYPE (MetaWaylandSurfaceRoleTabletCursor,
f73620
-               meta_wayland_surface_role_tablet_cursor,
f73620
-               META_TYPE_WAYLAND_SURFACE_ROLE_CURSOR)
f73620
+G_DEFINE_TYPE (MetaWaylandTabletCursorSurface,
f73620
+               meta_wayland_tablet_cursor_surface,
f73620
+               META_TYPE_WAYLAND_CURSOR_SURFACE)
f73620
 
f73620
 static void
f73620
-meta_wayland_surface_role_tablet_cursor_init (MetaWaylandSurfaceRoleTabletCursor *role)
f73620
+meta_wayland_tablet_cursor_surface_init (MetaWaylandTabletCursorSurface *role)
f73620
 {
f73620
 }
f73620
 
f73620
 static void
f73620
-meta_wayland_surface_role_tablet_cursor_class_init (MetaWaylandSurfaceRoleTabletCursorClass *klass)
f73620
+meta_wayland_tablet_cursor_surface_class_init (MetaWaylandTabletCursorSurfaceClass *klass)
f73620
 {
f73620
 }
f73620
diff --git a/src/wayland/meta-wayland-surface-role-tablet-cursor.h b/src/wayland/meta-wayland-tablet-cursor-surface.h
f73620
similarity index 59%
f73620
rename from src/wayland/meta-wayland-surface-role-tablet-cursor.h
f73620
rename to src/wayland/meta-wayland-tablet-cursor-surface.h
f73620
index 69fc6cf0f..5c5c198f5 100644
f73620
--- a/src/wayland/meta-wayland-surface-role-tablet-cursor.h
f73620
+++ b/src/wayland/meta-wayland-tablet-cursor-surface.h
f73620
@@ -19,15 +19,15 @@
f73620
  * 02111-1307, USA.
f73620
  */
f73620
 
f73620
-#ifndef META_WAYLAND_SURFACE_ROLE_TABLET_CURSOR_H
f73620
-#define META_WAYLAND_SURFACE_ROLE_TABLET_CURSOR_H
f73620
+#ifndef META_WAYLAND_TABLET_CURSOR_SURFACE_H
f73620
+#define META_WAYLAND_TABLET_CURSOR_SURFACE_H
f73620
 
f73620
-#include "meta-wayland-surface-role-cursor.h"
f73620
+#include "meta-wayland-cursor-surface.h"
f73620
 
f73620
-#define META_TYPE_WAYLAND_SURFACE_ROLE_TABLET_CURSOR (meta_wayland_surface_role_tablet_cursor_get_type ())
f73620
-G_DECLARE_FINAL_TYPE (MetaWaylandSurfaceRoleTabletCursor,
f73620
-                      meta_wayland_surface_role_tablet_cursor,
f73620
-                      META, WAYLAND_SURFACE_ROLE_TABLET_CURSOR,
f73620
-                      MetaWaylandSurfaceRoleCursor);
f73620
+#define META_TYPE_WAYLAND_TABLET_CURSOR_SURFACE (meta_wayland_tablet_cursor_surface_get_type ())
f73620
+G_DECLARE_FINAL_TYPE (MetaWaylandTabletCursorSurface,
f73620
+                      meta_wayland_tablet_cursor_surface,
f73620
+                      META, WAYLAND_TABLET_CURSOR_SURFACE,
f73620
+                      MetaWaylandCursorSurface)
f73620
 
f73620
-#endif /* META_WAYLAND_SURFACE_ROLE_TABLET_CURSOR_H */
f73620
+#endif /* META_WAYLAND_TABLET_CURSOR_SURFACE_H */
f73620
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
f73620
index 4b57d4156..d373f8d25 100644
f73620
--- a/src/wayland/meta-wayland-tablet-tool.c
f73620
+++ b/src/wayland/meta-wayland-tablet-tool.c
f73620
@@ -31,7 +31,7 @@
f73620
 #include <wayland-server.h>
f73620
 #include "tablet-unstable-v2-server-protocol.h"
f73620
 #include "meta-wayland-private.h"
f73620
-#include "meta-wayland-surface-role-tablet-cursor.h"
f73620
+#include "meta-wayland-tablet-cursor-surface.h"
f73620
 #include "meta-surface-actor-wayland.h"
f73620
 #include "meta-wayland-tablet.h"
f73620
 #include "meta-wayland-tablet-seat.h"
f73620
@@ -90,16 +90,16 @@ meta_wayland_tablet_tool_update_cursor_surface (MetaWaylandTabletTool *tool)
f73620
       if (tool->cursor_surface &&
f73620
           meta_wayland_surface_get_buffer (tool->cursor_surface))
f73620
         {
f73620
-          MetaWaylandSurfaceRoleCursor *cursor_role =
f73620
-            META_WAYLAND_SURFACE_ROLE_CURSOR (tool->cursor_surface->role);
f73620
+          MetaWaylandCursorSurface *cursor_surface =
f73620
+            META_WAYLAND_CURSOR_SURFACE (tool->cursor_surface->role);
f73620
 
f73620
-          cursor = meta_wayland_surface_role_cursor_get_sprite (cursor_role);
f73620
+          cursor = meta_wayland_cursor_surface_get_sprite (cursor_surface);
f73620
         }
f73620
       else
f73620
         cursor = NULL;
f73620
     }
f73620
   else if (tool->current_tablet)
f73620
-    cursor = tool->default_sprite;
f73620
+    cursor = META_CURSOR_SPRITE (tool->default_sprite);
f73620
   else
f73620
     cursor = NULL;
f73620
 
f73620
@@ -382,10 +382,10 @@ tablet_tool_handle_cursor_surface_destroy (struct wl_listener *listener,
f73620
 }
f73620
 
f73620
 static void
f73620
-tool_cursor_prepare_at (MetaCursorSprite      *cursor_sprite,
f73620
-                        int                    x,
f73620
-                        int                    y,
f73620
-                        MetaWaylandTabletTool *tool)
f73620
+tool_cursor_prepare_at (MetaCursorSpriteXcursor *sprite_xcursor,
f73620
+                        int                      x,
f73620
+                        int                      y,
f73620
+                        MetaWaylandTabletTool   *tool)
f73620
 {
f73620
   MetaBackend *backend = meta_get_backend ();
f73620
   MetaMonitorManager *monitor_manager =
f73620
@@ -397,7 +397,8 @@ tool_cursor_prepare_at (MetaCursorSprite      *cursor_sprite,
f73620
 
f73620
   /* Reload the cursor texture if the scale has changed. */
f73620
   if (logical_monitor)
f73620
-    meta_cursor_sprite_set_theme_scale (cursor_sprite, logical_monitor->scale);
f73620
+    meta_cursor_sprite_xcursor_set_theme_scale (sprite_xcursor,
f73620
+                                                logical_monitor->scale);
f73620
 }
f73620
 
f73620
 MetaWaylandTabletTool *
f73620
@@ -417,7 +418,7 @@ meta_wayland_tablet_tool_new (MetaWaylandTabletSeat  *seat,
f73620
   tool->focus_surface_destroy_listener.notify = tablet_tool_handle_focus_surface_destroy;
f73620
   tool->cursor_surface_destroy_listener.notify = tablet_tool_handle_cursor_surface_destroy;
f73620
 
f73620
-  tool->default_sprite = meta_cursor_sprite_from_theme (META_CURSOR_CROSSHAIR);
f73620
+  tool->default_sprite = meta_cursor_sprite_xcursor_new (META_CURSOR_CROSSHAIR);
f73620
   tool->prepare_at_signal_id =
f73620
     g_signal_connect (tool->default_sprite, "prepare-at",
f73620
                       G_CALLBACK (tool_cursor_prepare_at), tool);
f73620
@@ -471,7 +472,7 @@ tool_set_cursor (struct wl_client   *client,
f73620
 
f73620
   if (surface &&
f73620
       !meta_wayland_surface_assign_role (surface,
f73620
-                                         META_TYPE_WAYLAND_SURFACE_ROLE_TABLET_CURSOR,
f73620
+                                         META_TYPE_WAYLAND_TABLET_CURSOR_SURFACE,
f73620
                                          NULL))
f73620
     {
f73620
       wl_resource_post_error (resource, WL_POINTER_ERROR_ROLE,
f73620
@@ -482,13 +483,13 @@ tool_set_cursor (struct wl_client   *client,
f73620
 
f73620
   if (surface)
f73620
     {
f73620
-      MetaWaylandSurfaceRoleCursor *cursor_role;
f73620
+      MetaWaylandCursorSurface *cursor_surface;
f73620
 
f73620
-      cursor_role = META_WAYLAND_SURFACE_ROLE_CURSOR (surface->role);
f73620
-      meta_wayland_surface_role_cursor_set_renderer (cursor_role,
f73620
-                                                     tool->cursor_renderer);
f73620
-      meta_wayland_surface_role_cursor_set_hotspot (cursor_role,
f73620
-                                                    hotspot_x, hotspot_y);
f73620
+      cursor_surface = META_WAYLAND_CURSOR_SURFACE (surface->role);
f73620
+      meta_wayland_cursor_surface_set_renderer (cursor_surface,
f73620
+                                                tool->cursor_renderer);
f73620
+      meta_wayland_cursor_surface_set_hotspot (cursor_surface,
f73620
+                                               hotspot_x, hotspot_y);
f73620
     }
f73620
 
f73620
   meta_wayland_tablet_tool_set_cursor_surface (tool, surface);
f73620
diff --git a/src/wayland/meta-wayland-tablet-tool.h b/src/wayland/meta-wayland-tablet-tool.h
f73620
index 8cd930086..011972fc2 100644
f73620
--- a/src/wayland/meta-wayland-tablet-tool.h
f73620
+++ b/src/wayland/meta-wayland-tablet-tool.h
f73620
@@ -28,6 +28,7 @@
f73620
 
f73620
 #include "meta-wayland-types.h"
f73620
 #include "meta-cursor-renderer.h"
f73620
+#include "backends/meta-cursor-sprite-xcursor.h"
f73620
 
f73620
 struct _MetaWaylandTabletTool
f73620
 {
f73620
@@ -43,7 +44,7 @@ struct _MetaWaylandTabletTool
f73620
   MetaWaylandSurface *cursor_surface;
f73620
   struct wl_listener cursor_surface_destroy_listener;
f73620
   MetaCursorRenderer *cursor_renderer;
f73620
-  MetaCursorSprite *default_sprite;
f73620
+  MetaCursorSpriteXcursor *default_sprite;
f73620
   guint prepare_at_signal_id;
f73620
 
f73620
   MetaWaylandSurface *current;