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.
This commit is contained in:
Daniel Eklöf 2024-02-29 07:54:27 +01:00
parent 6fd533ce13
commit d3b348a5b1
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 53 additions and 46 deletions

View file

@ -4625,38 +4625,48 @@ 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
: 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);
if (seat->pointer.cursor == NULL) {
seat->pointer.cursor = wl_cursor_theme_get_cursor(
seat->pointer.theme, fallback);
if (seat->pointer.cursor == NULL) {
LOG_ERR("failed to load xcursor pointer "
"'%s', and fallback '%s'", xcursor, fallback);
return false;
}
}
if (shape == CURSOR_SHAPE_CUSTOM) {
free(seat->pointer.last_custom_xcursor);
seat->pointer.last_custom_xcursor = xstrdup(term->mouse_user_cursor);
}
} else {
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);
xassert(xcursors[0] != NULL);
seat->pointer.cursor = NULL;
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 (seat->pointer.cursor == NULL) {
LOG_ERR(
"failed to load xcursor pointer '%s', and all of its fallbacks",
xcursors[0]);
return false;
}
} else {
/* Server-side cursors - no need to load anything */
}
if (shape == CURSOR_SHAPE_CUSTOM) {
free(seat->pointer.last_custom_xcursor);
seat->pointer.last_custom_xcursor =
xstrdup(term->mouse_user_cursor);
}
/* FDM hook takes care of actual rendering */
seat->pointer.shape = shape;
seat->pointer.xcursor_pending = true;