diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2024-02-29 06:54:27 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2024-03-01 06:04:48 +0000 |
| commit | d3b348a5b183b0e6295dc985b1d5dcd939cb5c6e (patch) | |
| tree | 0ac7d5a3047bf99e90182cf0305db70062566459 /render.c | |
| parent | render: don't try to set a NULL xcursor image (diff) | |
cursor-shape: improve xcursor fallback support, and prefer CSS names
Before this patch, we used legacy X11 xcursor names, and didn't really
have any fallback handling in place (we only tried to fallback to
"xterm", regardless of which cursor shape we were trying to load).
This patch changes two things:
1. Improved fallback support. cursor_shape_to_string() now returns a
list of strings. This allows us to have per-shape fallbacks, and any
number of fallbacks.
2. We prefer CSS xcursor names over legacy X11 names.
Diffstat (limited to 'render.c')
| -rw-r--r-- | render.c | 50 |
1 files changed, 30 insertions, 20 deletions
@@ -4625,36 +4625,46 @@ render_xcursor_set(struct seat *seat, struct terminal *term, return true; } - /* TODO: skip this when using server-side cursors */ - if (shape != CURSOR_SHAPE_HIDDEN) { - const char *const xcursor = shape == CURSOR_SHAPE_CUSTOM - ? term->mouse_user_cursor + if (shape == CURSOR_SHAPE_HIDDEN) { + seat->pointer.cursor = NULL; + free(seat->pointer.last_custom_xcursor); + seat->pointer.last_custom_xcursor = NULL; + } + + else if (seat->pointer.shape_device == NULL) { + const char *const custom_xcursors[] = {term->mouse_user_cursor, NULL}; + const char *const *xcursors = shape == CURSOR_SHAPE_CUSTOM + ? custom_xcursors : cursor_shape_to_string(shape); - const char *const fallback = - cursor_shape_to_string(CURSOR_SHAPE_TEXT_FALLBACK); - seat->pointer.cursor = wl_cursor_theme_get_cursor( - seat->pointer.theme, xcursor); + xassert(xcursors[0] != NULL); - if (seat->pointer.cursor == NULL) { - seat->pointer.cursor = wl_cursor_theme_get_cursor( - seat->pointer.theme, fallback); + seat->pointer.cursor = NULL; - if (seat->pointer.cursor == NULL) { - LOG_ERR("failed to load xcursor pointer " - "'%s', and fallback '%s'", xcursor, fallback); - return false; + for (size_t i = 0; xcursors[i] != NULL; i++) { + seat->pointer.cursor = + wl_cursor_theme_get_cursor(seat->pointer.theme, xcursors[i]); + + if (seat->pointer.cursor != NULL) { + LOG_DBG("loaded xcursor %s", xcursors[i]); + break; } } - if (shape == CURSOR_SHAPE_CUSTOM) { - free(seat->pointer.last_custom_xcursor); - seat->pointer.last_custom_xcursor = xstrdup(term->mouse_user_cursor); + if (seat->pointer.cursor == NULL) { + LOG_ERR( + "failed to load xcursor pointer '%s', and all of its fallbacks", + xcursors[0]); + return false; } } else { - seat->pointer.cursor = NULL; + /* Server-side cursors - no need to load anything */ + } + + if (shape == CURSOR_SHAPE_CUSTOM) { free(seat->pointer.last_custom_xcursor); - seat->pointer.last_custom_xcursor = NULL; + seat->pointer.last_custom_xcursor = + xstrdup(term->mouse_user_cursor); } /* FDM hook takes care of actual rendering */ |
