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



commit 8f5ea43c2b8ae487e6bc098b506ed4f70c403489
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>
    
    (cherry picked from commit 83360a4aede860d0e6ad5a29ab374fd4f26f3882)

 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 599d0e6971..0dabb85597 100644
--- a/src/backends/meta-cursor-sprite-xcursor.c
+++ b/src/backends/meta-cursor-sprite-xcursor.c
@@ -109,9 +109,26 @@ meta_create_x_cursor (Display    *xdisplay,
 static XcursorImages *
 load_cursor_on_client (MetaCursor cursor, int scale)
 {
-  return XcursorLibraryLoadImages (translate_meta_cursor (cursor),
-                                   meta_prefs_get_cursor_theme (),
-                                   meta_prefs_get_cursor_size () * scale);
+  XcursorImages *xcursor_images;
+  int fallback_size;
+
+  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
@@ -246,8 +263,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]