[mutter/wayland] display: Deduplicate cursor loading code



commit a6bf340ff838267bf3d786b0f6716579d018ac3d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Oct 7 13:25:10 2013 -0400

    display: Deduplicate cursor loading code
    
    Rather than do the cursor -> name translation ourselves in two different
    places, use the facilities in libXcursor to do it for us. Put the shared
    piece of code in meta-cursor-tracker, and use it for both server-side and
    client-side cursor loading.

 src/core/display.c             |   80 ------------------------------
 src/core/meta-cursor-tracker.c |  107 +++++++++++++++++++++++++++++----------
 2 files changed, 79 insertions(+), 108 deletions(-)
---
diff --git a/src/core/display.c b/src/core/display.c
index 6f47023..9a0d809 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -51,7 +51,6 @@
 #include <meta/compositor.h>
 #include <meta/compositor-mutter.h>
 #include <X11/Xatom.h>
-#include <X11/cursorfont.h>
 #include "mutter-enum-types.h"
 #include "meta-idle-monitor-private.h"
 
@@ -3959,85 +3958,6 @@ meta_display_xwindow_is_a_no_focus_window (MetaDisplay *display,
   return is_a_no_focus_window;
 }
 
-Cursor
-meta_display_create_x_cursor (MetaDisplay *display,
-                              MetaCursor cursor)
-{
-  Cursor xcursor;
-  guint glyph = XC_num_glyphs;
-  const char *name = NULL;
-
-  switch (cursor)
-    {
-    case META_CURSOR_DEFAULT:
-      glyph = XC_left_ptr;
-      break;
-    case META_CURSOR_NORTH_RESIZE:
-      glyph = XC_top_side;
-      break;
-    case META_CURSOR_SOUTH_RESIZE:
-      glyph = XC_bottom_side;
-      break;
-    case META_CURSOR_WEST_RESIZE:
-      glyph = XC_left_side;
-      break;
-    case META_CURSOR_EAST_RESIZE:
-      glyph = XC_right_side;
-      break;
-    case META_CURSOR_SE_RESIZE:
-      glyph = XC_bottom_right_corner;
-      break;
-    case META_CURSOR_SW_RESIZE:
-      glyph = XC_bottom_left_corner;
-      break;
-    case META_CURSOR_NE_RESIZE:
-      glyph = XC_top_right_corner;
-      break;
-    case META_CURSOR_NW_RESIZE:
-      glyph = XC_top_left_corner;
-      break;
-    case META_CURSOR_MOVE_OR_RESIZE_WINDOW:
-      glyph = XC_fleur;
-      break;
-    case META_CURSOR_BUSY:
-      glyph = XC_watch;
-      break;
-    case META_CURSOR_DND_IN_DRAG:
-      name = "dnd-none";
-      break;
-    case META_CURSOR_DND_MOVE:
-      name = "dnd-move";
-      break;
-    case META_CURSOR_DND_COPY:
-      name = "dnd-copy";
-      break;
-    case META_CURSOR_DND_UNSUPPORTED_TARGET:
-      name = "dnd-none";
-      break;
-    case META_CURSOR_POINTING_HAND:
-      glyph = XC_hand2;
-      break;
-    case META_CURSOR_CROSSHAIR:
-      glyph = XC_crosshair;
-      break;
-    case META_CURSOR_IBEAM:
-      glyph = XC_xterm;
-      break;
-
-    default:
-      g_assert_not_reached ();
-      glyph = 0; /* silence compiler */
-      break;
-    }
-
-  if (name != NULL)
-    xcursor = XcursorLibraryLoadCursor (display->xdisplay, name);
-  else
-    xcursor = XCreateFontCursor (display->xdisplay, glyph);
-
-  return xcursor;
-}
-
 static Cursor
 xcursor_for_op (MetaDisplay *display,
                 MetaGrabOp   op)
diff --git a/src/core/meta-cursor-tracker.c b/src/core/meta-cursor-tracker.c
index aa8c65d..5898df2 100644
--- a/src/core/meta-cursor-tracker.c
+++ b/src/core/meta-cursor-tracker.c
@@ -42,6 +42,7 @@
 
 #include <gdk/gdk.h>
 
+#include <X11/cursorfont.h>
 #include <X11/extensions/Xfixes.h>
 #include <X11/Xcursor/Xcursor.h>
 
@@ -128,76 +129,130 @@ meta_cursor_reference_unref (MetaCursorReference *self)
     }
 }
 
-static const char *
-get_cursor_filename (MetaCursor cursor)
+static void
+translate_meta_cursor (MetaCursor   cursor,
+                       guint       *glyph_out,
+                       const char **name_out)
 {
+  guint glyph = XC_num_glyphs;
+  const char *name = NULL;
+
   switch (cursor)
     {
     case META_CURSOR_DEFAULT:
-      return "left_ptr";
+      glyph = XC_left_ptr;
       break;
     case META_CURSOR_NORTH_RESIZE:
-      return "top_side";
+      glyph = XC_top_side;
       break;
     case META_CURSOR_SOUTH_RESIZE:
-      return "bottom_side";
+      glyph = XC_bottom_side;
       break;
     case META_CURSOR_WEST_RESIZE:
-      return "left_side";
+      glyph = XC_left_side;
       break;
     case META_CURSOR_EAST_RESIZE:
-      return "right_side";
+      glyph = XC_right_side;
       break;
     case META_CURSOR_SE_RESIZE:
-      return "bottom_right_corner";
+      glyph = XC_bottom_right_corner;
       break;
     case META_CURSOR_SW_RESIZE:
-      return "bottom_left_corner";
+      glyph = XC_bottom_left_corner;
       break;
     case META_CURSOR_NE_RESIZE:
-      return "top_right_corner";
+      glyph = XC_top_right_corner;
       break;
     case META_CURSOR_NW_RESIZE:
-      return "top_left_corner";
+      glyph = XC_top_left_corner;
       break;
     case META_CURSOR_MOVE_OR_RESIZE_WINDOW:
-      return "fleur";
+      glyph = XC_fleur;
       break;
     case META_CURSOR_BUSY:
-      return "watch";
+      glyph = XC_watch;
       break;
     case META_CURSOR_DND_IN_DRAG:
-      return "dnd-none";
+      name = "dnd-none";
       break;
     case META_CURSOR_DND_MOVE:
-      return "dnd-copy";
+      name = "dnd-move";
+      break;
+    case META_CURSOR_DND_COPY:
+      name = "dnd-copy";
       break;
     case META_CURSOR_DND_UNSUPPORTED_TARGET:
-      return "dnd-none";
+      name = "dnd-none";
       break;
     case META_CURSOR_POINTING_HAND:
-      return "hand";
+      glyph = XC_hand2;
       break;
     case META_CURSOR_CROSSHAIR:
-      return "crosshair";
+      glyph = XC_crosshair;
       break;
     case META_CURSOR_IBEAM:
-      return "xterm";
+      glyph = XC_xterm;
       break;
 
     default:
       g_assert_not_reached ();
-      return NULL;
+      glyph = 0; /* silence compiler */
+      break;
     }
+
+  *glyph_out = glyph;
+  *name_out = name;
+}
+
+static Cursor
+load_cursor_on_server (MetaDisplay *display,
+                       MetaCursor   cursor)
+{
+  Cursor xcursor;
+  guint glyph;
+  const char *name;
+
+  translate_meta_cursor (cursor, &glyph, &name);
+
+  if (name != NULL)
+    xcursor = XcursorLibraryLoadCursor (display->xdisplay, name);
+  else
+    xcursor = XCreateFontCursor (display->xdisplay, glyph);
+
+  return xcursor;
+}
+
+Cursor
+meta_display_create_x_cursor (MetaDisplay *display,
+                              MetaCursor cursor)
+{
+  return load_cursor_on_server (display, cursor);
+}
+
+static XcursorImage *
+load_cursor_on_client (MetaDisplay *display,
+                       MetaCursor   cursor)
+{
+  XcursorImage *image;
+  guint glyph;
+  const char *name;
+  const char *theme = XcursorGetTheme (display->xdisplay);
+  int size = XcursorGetDefaultSize (display->xdisplay);
+
+  translate_meta_cursor (cursor, &glyph, &name);
+
+  if (name != NULL)
+    image = XcursorLibraryLoadImage (name, theme, size);
+  else
+    image = XcursorShapeLoadImage (glyph, theme, size);
+
+  return image;
 }
 
 static MetaCursorReference *
 meta_cursor_reference_from_theme (MetaCursorTracker  *tracker,
                                   MetaCursor          cursor)
 {
-  const char *theme;
-  const char *filename;
-  int size;
   XcursorImage *image;
   int width, height, rowstride;
   CoglPixelFormat cogl_format;
@@ -206,11 +261,7 @@ meta_cursor_reference_from_theme (MetaCursorTracker  *tracker,
   CoglContext *cogl_context;
   MetaCursorReference *self;
 
-  filename = get_cursor_filename (cursor);
-  theme = XcursorGetTheme (tracker->screen->display->xdisplay);
-  size = XcursorGetDefaultSize (tracker->screen->display->xdisplay);
-
-  image = XcursorLibraryLoadImage (filename, theme, size);
+  image = load_cursor_on_client (tracker->screen->display, cursor);
   if (!image)
     return NULL;
 


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