]> git.mdlowis.com Git - proto/labwc.git/commitdiff
cursor: Handle missing cursor theme
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sat, 10 Sep 2022 21:53:35 +0000 (23:53 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 11 Sep 2022 20:20:00 +0000 (21:20 +0100)
Temporary fix for #246

This should be reverted once wlroots MR !3651 is merged.

include/labwc.h
src/cursor.c

index 6032d472c163370df3c9b446446d878b003ffa79..0466e9a103105329319498406f294ac1bfbff792 100644 (file)
@@ -79,6 +79,7 @@ struct seat {
        struct server *server;
        struct wlr_keyboard_group *keyboard_group;
 
+       bool cursor_requires_fallback;
        struct wlr_cursor *cursor;
        struct wlr_xcursor_manager *xcursor_manager;
 
index c8aa7da4d31fbb117977a3991b1e701793e00b74..d535ba05ede8ae41b94d0a810e546f4a1fbbf8f2 100644 (file)
 /* Used to prevent setting the same cursor image twice */
 static char *last_cursor_image = NULL;
 
+
+static const struct cursor_alias {
+       const char *name, *alias;
+} cursor_aliases[] = {
+       { "default",    "left_ptr" },
+       { "text",       "xterm" },
+       { "grab",       "grabbing" },
+       { "pointer",    "hand1" },
+       { "wait",       "watch" },
+       { "all-scroll", "grabbing" },
+       /* Resize edges */
+       { "nw-resize",  "top_left_corner" },
+       { "n-resize",   "top_side" },
+       { "ne-resize",  "top_right_corner" },
+       { "e-resize",   "right_side" },
+       { "se-resize",  "bottom_right_corner" },
+       { "s-resize",   "bottom_side" },
+       { "sw-resize",  "bottom_left_corner" },
+       { "w-resize",   "left_side" },
+};
+
 static bool
 is_surface(enum ssd_part_type view_area)
 {
@@ -203,12 +224,34 @@ process_cursor_resize(struct server *server, uint32_t time)
        view_move_resize(view, new_view_geo);
 }
 
+static const char *
+cursor_name_fallback(struct wlr_xcursor_manager *manager, const char *name)
+{
+       if (wlr_xcursor_manager_get_xcursor(manager, name, 1)) {
+               return name;
+       }
+       for (size_t i = 0; i < sizeof(cursor_aliases) / sizeof(cursor_aliases[0]); i++) {
+               if (!strcmp(cursor_aliases[i].name, name)) {
+                       return cursor_aliases[i].alias;
+               }
+       }
+       return name;
+}
+
 void
 cursor_set(struct seat *seat, const char *cursor_name)
 {
+       /*
+        * Required until wlroots MR !3651 is merged.
+        * Once that happened, the whole commit can be reverted.
+        */
+       if (seat->cursor_requires_fallback) {
+               cursor_name = cursor_name_fallback(seat->xcursor_manager, cursor_name);
+       }
+
+       /* Prevent setting the same cursor image twice */
        if (last_cursor_image) {
                if (!strcmp(last_cursor_image, cursor_name)) {
-                       /* Prevent setting the same cursor image twice */
                        return;
                }
                free(last_cursor_image);
@@ -962,6 +1005,13 @@ cursor_init(struct seat *seat)
        seat->xcursor_manager = wlr_xcursor_manager_create(xcursor_theme, size);
        wlr_xcursor_manager_load(seat->xcursor_manager, 1);
 
+       /* Check if we need to run every cursor_set() through translation */
+       if (strcmp("grab", cursor_name_fallback(seat->xcursor_manager, "grab"))) {
+               seat->cursor_requires_fallback = true;
+               wlr_log(WLR_INFO,
+                       "Cursor theme is missing cursor names, using fallbacks");
+       }
+
        seat->cursor_motion.notify = cursor_motion;
        wl_signal_add(&seat->cursor->events.motion, &seat->cursor_motion);
        seat->cursor_motion_absolute.notify = cursor_motion_absolute;