cursor-shape: add 'dnd-ask' and 'all-resize'

These (non-css) cursor shapes were added to the cursor-shape-v1
protocol in wayland-protocols 1.42.

We don't need (or use them at all) internally, but add them to the
list we use to translate from shape names to shape enums. This allows
users to set a custom shape (via OSC-22), while still using server
side cursors (i.e. no need to fallback to client-side cursors).

If we try to set a shape not implemented by the server, we get a
protocol error and foot exits. This is bad.

So, make sure we don't do that:

1. First, we need to explicitly bind v2 if implemented by the server
2. Track the bound version number in the wayland struct
3. When matching shape enum, skip shapes not supported in the
   currently bound version of the cursor-shape protocol
This commit is contained in:
Daniel Eklöf 2025-05-21 15:25:28 +02:00
parent d266599881
commit 664cdcc65c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 39 additions and 6 deletions

View file

@ -90,6 +90,7 @@
* `16-bit` to `tweak.surface-bit-depth`. Makes foot use 16-bit image * `16-bit` to `tweak.surface-bit-depth`. Makes foot use 16-bit image
buffers. They provide the necessary color precision required by buffers. They provide the necessary color precision required by
`gamma-correct-blending=yes`. `gamma-correct-blending=yes`.
* New cursor shapes, from `cursor-shape-v1` version 2.
[2025]: https://codeberg.org/dnkl/foot/issues/2025 [2025]: https://codeberg.org/dnkl/foot/issues/2025
[1975]: https://codeberg.org/dnkl/foot/issues/1975 [1975]: https://codeberg.org/dnkl/foot/issues/1975

View file

@ -54,7 +54,7 @@ cursor_shape_to_server_shape(enum cursor_shape shape)
} }
enum wp_cursor_shape_device_v1_shape enum wp_cursor_shape_device_v1_shape
cursor_string_to_server_shape(const char *xcursor) cursor_string_to_server_shape(const char *xcursor, int bound_version)
{ {
if (xcursor == NULL) if (xcursor == NULL)
return 0; return 0;
@ -94,9 +94,29 @@ cursor_string_to_server_shape(const char *xcursor)
[WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_SCROLL] = {"all-scroll", "fleur"}, [WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_SCROLL] = {"all-scroll", "fleur"},
[WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ZOOM_IN] = {"zoom-in"}, [WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ZOOM_IN] = {"zoom-in"},
[WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ZOOM_OUT] = {"zoom-out"}, [WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ZOOM_OUT] = {"zoom-out"},
#if defined(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DND_ASK_SINCE_VERSION) /* 1.42 */
[WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DND_ASK] = {"dnd-ask"},
#endif
#if defined(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_RESIZE_SINCE_VERSION) /* 1.42 */
[WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_RESIZE] = {"all-resize"},
#endif
}; };
for (size_t i = 0; i < ALEN(table); i++) { for (size_t i = 0; i < ALEN(table); i++) {
#if defined(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DND_ASK_SINCE_VERSION)
if (i == WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DND_ASK &&
bound_version < WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DND_ASK_SINCE_VERSION)
{
continue;
}
#endif
#if defined(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_RESIZE_SINCE_VERSION)
if (i == WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_RESIZE &&
bound_version < WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_RESIZE_SINCE_VERSION)
{
continue;
}
#endif
for (size_t j = 0; j < ALEN(table[i]); j++) { for (size_t j = 0; j < ALEN(table[i]); j++) {
if (table[i][j] != NULL && streq(xcursor, table[i][j])) { if (table[i][j] != NULL && streq(xcursor, table[i][j])) {
return i; return i;

View file

@ -26,4 +26,4 @@ const char *const *cursor_shape_to_string(enum cursor_shape shape);
enum wp_cursor_shape_device_v1_shape cursor_shape_to_server_shape( enum wp_cursor_shape_device_v1_shape cursor_shape_to_server_shape(
enum cursor_shape shape); enum cursor_shape shape);
enum wp_cursor_shape_device_v1_shape cursor_string_to_server_shape( enum wp_cursor_shape_device_v1_shape cursor_string_to_server_shape(
const char *xcursor); const char *xcursor, int bound_version);

View file

@ -4929,8 +4929,9 @@ render_xcursor_update(struct seat *seat)
const enum wp_cursor_shape_device_v1_shape custom_shape = const enum wp_cursor_shape_device_v1_shape custom_shape =
(shape == CURSOR_SHAPE_CUSTOM && xcursor != NULL (shape == CURSOR_SHAPE_CUSTOM && xcursor != NULL
? cursor_string_to_server_shape(xcursor) ? cursor_string_to_server_shape(
: 0); xcursor, seat->wayl->shape_manager_version)
: 0);
if (shape != CURSOR_SHAPE_CUSTOM || custom_shape != 0) { if (shape != CURSOR_SHAPE_CUSTOM || custom_shape != 0) {
xassert(custom_shape == 0 || shape == CURSOR_SHAPE_CUSTOM); xassert(custom_shape == 0 || shape == CURSOR_SHAPE_CUSTOM);

View file

@ -3571,7 +3571,9 @@ term_xcursor_update_for_seat(struct terminal *term, struct seat *seat)
if (seat->pointer.hidden) if (seat->pointer.hidden)
shape = CURSOR_SHAPE_HIDDEN; shape = CURSOR_SHAPE_HIDDEN;
else if (cursor_string_to_server_shape(term->mouse_user_cursor) != 0 || else if (cursor_string_to_server_shape(
term->mouse_user_cursor,
term->wl->shape_manager_version) != 0 ||
render_xcursor_is_valid(seat, term->mouse_user_cursor)) render_xcursor_is_valid(seat, term->mouse_user_cursor))
{ {
shape = CURSOR_SHAPE_CUSTOM; shape = CURSOR_SHAPE_CUSTOM;

View file

@ -1480,8 +1480,16 @@ handle_global(void *data, struct wl_registry *registry,
if (!verify_iface_version(interface, version, required)) if (!verify_iface_version(interface, version, required))
return; return;
#if defined(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DND_ASK_SINCE_VERSION) /* 1.42 */
const uint32_t preferred = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DND_ASK_SINCE_VERSION;
#else
const uint32_t preferred = required;
#endif
wayl->shape_manager_version = min(required, preferred);
wayl->cursor_shape_manager = wl_registry_bind( wayl->cursor_shape_manager = wl_registry_bind(
wayl->registry, name, &wp_cursor_shape_manager_v1_interface, required); wayl->registry, name, &wp_cursor_shape_manager_v1_interface,
min(required, preferred));
} }
else if (streq(interface, wp_single_pixel_buffer_manager_v1_interface.name)) { else if (streq(interface, wp_single_pixel_buffer_manager_v1_interface.name)) {

View file

@ -460,6 +460,7 @@ struct wayland {
struct wp_fractional_scale_manager_v1 *fractional_scale_manager; struct wp_fractional_scale_manager_v1 *fractional_scale_manager;
struct wp_cursor_shape_manager_v1 *cursor_shape_manager; struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
int shape_manager_version;
struct wp_single_pixel_buffer_manager_v1 *single_pixel_manager; struct wp_single_pixel_buffer_manager_v1 *single_pixel_manager;