[mutter] cursor-sprite/xcursor: Fall back to gray square if missing theme



commit 83360a4aede860d0e6ad5a29ab374fd4f26f3882
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Mon Nov 16 11:03:31 2020 +0100

    cursor-sprite/xcursor: Fall back to gray square if missing theme
    
    Instead of aborting with an error, display a half transparent gray
    square instead of cursors and log a warning in the journal, allowing the
    user to fix their system withotu having to rely on switching to a TTY.
    
    It will be immediately obvious the cursor is silly looking, which will
    be a better hint than just aborting.
    
    Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1428
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1563>

 src/backends/meta-cursor-sprite-xcursor.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/src/backends/meta-cursor-sprite-xcursor.c b/src/backends/meta-cursor-sprite-xcursor.c
index c57a5a684c..5284f28eaa 100644
--- a/src/backends/meta-cursor-sprite-xcursor.c
+++ b/src/backends/meta-cursor-sprite-xcursor.c
@@ -155,12 +155,29 @@ meta_create_x_cursor (Display    *xdisplay,
 static XcursorImages *
 load_cursor_on_client (MetaCursor cursor, int scale)
 {
+  XcursorImages *xcursor_images;
+  int fallback_size;
+
   if (cursor == META_CURSOR_BLANK)
     return create_blank_cursor_images ();
 
-  return XcursorLibraryLoadImages (translate_meta_cursor (cursor),
-                                   meta_prefs_get_cursor_theme (),
-                                   meta_prefs_get_cursor_size () * scale);
+  xcursor_images =
+    XcursorLibraryLoadImages (translate_meta_cursor (cursor),
+                              meta_prefs_get_cursor_theme (),
+                              meta_prefs_get_cursor_size () * scale);
+  if (xcursor_images)
+    return xcursor_images;
+
+  g_warning_once ("No cursor theme available, please install a cursor theme");
+
+  fallback_size = 24 * scale;
+  xcursor_images = XcursorImagesCreate (1);
+  xcursor_images->images[0] = XcursorImageCreate (fallback_size, fallback_size);
+  xcursor_images->images[0]->xhot = 0;
+  xcursor_images->images[0]->yhot = 0;
+  memset (xcursor_images->images[0]->pixels, 0xc0,
+          fallback_size * fallback_size * sizeof (int32_t));
+  return xcursor_images;
 }
 
 static void
@@ -295,8 +312,6 @@ load_cursor_from_theme (MetaCursorSprite *sprite)
   sprite_xcursor->xcursor_images =
     load_cursor_on_client (sprite_xcursor->cursor,
                            sprite_xcursor->theme_scale);
-  if (!sprite_xcursor->xcursor_images)
-    g_error ("Could not find cursor. Perhaps set XCURSOR_PATH?");
 
   load_from_current_xcursor_image (sprite_xcursor);
 }


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