From dbedcdb418f49090df6e7359e6d3e58c97db1a74 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 1 Nov 2023 11:40:13 +0100 Subject: [PATCH] xcursor: add fallbacks for legacy names Some XCursor themes still use the legacy names instead of the newer cursor naming spec [1]. Fall back to the legacy name if the standard one could not be found. [1]: https://www.freedesktop.org/wiki/Specifications/cursor-spec/ Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3746 --- xcursor/wlr_xcursor.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/xcursor/wlr_xcursor.c b/xcursor/wlr_xcursor.c index 597a0b13..6c6e11df 100644 --- a/xcursor/wlr_xcursor.c +++ b/xcursor/wlr_xcursor.c @@ -239,7 +239,7 @@ void wlr_xcursor_theme_destroy(struct wlr_xcursor_theme *theme) { free(theme); } -struct wlr_xcursor *wlr_xcursor_theme_get_cursor(struct wlr_xcursor_theme *theme, +static struct wlr_xcursor *xcursor_theme_get_cursor(struct wlr_xcursor_theme *theme, const char *name) { for (unsigned int i = 0; i < theme->cursor_count; i++) { if (strcmp(name, theme->cursors[i]->name) == 0) { @@ -250,6 +250,47 @@ struct wlr_xcursor *wlr_xcursor_theme_get_cursor(struct wlr_xcursor_theme *theme return NULL; } +struct wlr_xcursor *wlr_xcursor_theme_get_cursor(struct wlr_xcursor_theme *theme, + const char *name) { + struct wlr_xcursor *xcursor = xcursor_theme_get_cursor(theme, name); + if (xcursor) { + return xcursor; + } + + // Try the legacy name as a fallback + const char *fallback; + if (strcmp(name, "default") == 0) { + fallback = "left_ptr"; + } else if (strcmp(name, "text") == 0) { + fallback = "xterm"; + } else if (strcmp(name, "pointer") == 0) { + fallback = "hand1"; + } else if (strcmp(name, "wait") == 0) { + fallback = "watch"; + } else if (strcmp(name, "all-scroll") == 0) { + fallback = "grabbing"; + } else if (strcmp(name, "sw-resize") == 0) { + fallback = "bottom_left_corner"; + } else if (strcmp(name, "se-resize") == 0) { + fallback = "bottom_right_corner"; + } else if (strcmp(name, "s-resize") == 0) { + fallback = "bottom_side"; + } else if (strcmp(name, "w-resize") == 0) { + fallback = "left_side"; + } else if (strcmp(name, "e-resize") == 0) { + fallback = "right_side"; + } else if (strcmp(name, "nw-resize") == 0) { + fallback = "top_left_corner"; + } else if (strcmp(name, "ne-resize") == 0) { + fallback = "top_right_corner"; + } else if (strcmp(name, "n-resize") == 0) { + fallback = "top_side"; + } else { + return NULL; + } + return xcursor_theme_get_cursor(theme, fallback); +} + static int xcursor_frame_and_duration(struct wlr_xcursor *cursor, uint32_t time, uint32_t *duration) { if (cursor->image_count == 1) {