From 1cfd1fcd043f2f9422f2c61d327288584a4e3fb0 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 27 Feb 2025 15:21:16 -0500 Subject: [PATCH 1/6] gdk: Touch up cursor name docs Make the table provide usage hints, and line things up more nicely. (cherry picked from commit a948157a6c4e56b8ce7e10e702987f03cd1d13c3) --- docs/reference/gdk/images/all_resize_cursor.png | Bin 0 -> 1788 bytes docs/reference/gdk/images/dnd_ask_cursor.png | Bin 0 -> 1416 bytes docs/reference/gdk/meson.build | 2 ++ gdk/gdkcursor.c | 5 +++++ 4 files changed, 7 insertions(+) create mode 100644 docs/reference/gdk/images/all_resize_cursor.png create mode 100644 docs/reference/gdk/images/dnd_ask_cursor.png diff --git a/docs/reference/gdk/images/all_resize_cursor.png b/docs/reference/gdk/images/all_resize_cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..6a8fbcd22bbc498ef422423e05dfc65dccaf233d GIT binary patch literal 1788 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 literal 0 HcmV?d00001 diff --git a/docs/reference/gdk/meson.build b/docs/reference/gdk/meson.build index 96a993e0668..a2c312e5e31 100644 --- a/docs/reference/gdk/meson.build +++ b/docs/reference/gdk/meson.build @@ -142,6 +142,8 @@ images = [ 'images/X_cursor.png', 'images/zoom_in_cursor.png', 'images/zoom_out_cursor.png', + 'images/dnd_ask_cursor.png', + 'images/all_resize_cursor.png', ] src_dir = [ gdkinc ] diff --git a/gdk/gdkcursor.c b/gdk/gdkcursor.c index 367c531be8c..537003cb107 100644 --- a/gdk/gdkcursor.c +++ b/gdk/gdkcursor.c @@ -285,6 +285,11 @@ gdk_cursor_new_for_display (GdkDisplay *display, * - ![](zoom_in_cursor.png) "zoom-in" * - ![](zoom_out_cursor.png) "zoom-out" * + * Additionally, the following cursor names are supported, which are + * not in the CSS specification: + * - ![](dnd_ask_cursor.png) "dnd-ask" + * - ![](all_resize_cursor.png) "all-resize" + * * * Returns: (nullable): a new #GdkCursor, or %NULL if there is no * cursor with the given name -- GitLab From f44e7b4f67000c170ead47ce0102fb19b91d1cfd Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 27 Feb 2025 19:14:09 -0500 Subject: [PATCH 2/6] x11: Support the all-resize cursor This is an alternative name for the move cursor. (cherry picked from commit 1eaa4eb4051c42242f1eadd2d5e45b45a94d2e8d) --- gdk/x11/gdkcursor-x11.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gdk/x11/gdkcursor-x11.c b/gdk/x11/gdkcursor-x11.c index 5555ea01b2a..7f0bb8d805f 100644 --- a/gdk/x11/gdkcursor-x11.c +++ b/gdk/x11/gdkcursor-x11.c @@ -650,6 +650,7 @@ static const struct { { "nwse-resize", "bd_double_arrow" }, { "zoom-in", "left_ptr" }, { "zoom-out", "left_ptr" }, + { "all-resize", "move" }, /* not CSS, but we want to guarantee it anyway */ { NULL, NULL } }; -- GitLab From cc14115d09144738a744f0d0a41cb1a77107c847 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 27 Feb 2025 15:21:49 -0500 Subject: [PATCH 3/6] wayland: Support the all-resize cursor Add all-resize to the list of names that we want to guarantee. We use move as the fallback for it. The idea is that all-resize will be visually compatible with resize cursors, and move will be visually compatible with dnd cursors. And it is nice to have two distinct names, so the metaphors can be changed without clashing. (cherry picked from commit 79ba34f1aa82de7d06c19109582f7df5f144a6c1) --- gdk/wayland/gdkcursor-wayland.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gdk/wayland/gdkcursor-wayland.c b/gdk/wayland/gdkcursor-wayland.c index 7e02be9be48..6a5e2cf53dd 100644 --- a/gdk/wayland/gdkcursor-wayland.c +++ b/gdk/wayland/gdkcursor-wayland.c @@ -122,6 +122,7 @@ static const struct { { "nwse-resize", "bd_double_arrow" }, { "zoom-in", "left_ptr" }, { "zoom-out", "left_ptr" }, + { "all-resize", "move" }, /* not CSS, but we want to guarantee it anyway */ { NULL, NULL } }; -- GitLab From b281c8035fdccd68e2be9b2421b4538f7a0a6825 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 27 Feb 2025 15:25:29 -0500 Subject: [PATCH 4/6] wayland: Support the cursor-shape protocol If present, use the cursor-shape protocol instead of manually updating a pointer surface. This commit supports both v1 of the protocol and the (still unmerged) v2 additions to the enumeration. This was tested with both kwin and mutter. (cherry picked from commit a63d6d1dc7a8ebdf61c682196f89917846cbe8ac) --- gdk/wayland/gdkcursor-wayland.c | 7 + gdk/wayland/gdkdevice-wayland.c | 131 ++++++++++++++++-- gdk/wayland/gdkdisplay-wayland.c | 6 + gdk/wayland/gdkdisplay-wayland.h | 2 + gdk/wayland/gdkprivate-wayland.h | 2 + gdk/wayland/meson.build | 1 + gdk/wayland/protocol/cursor-shape-v1.xml | 163 +++++++++++++++++++++++ 7 files changed, 303 insertions(+), 9 deletions(-) create mode 100644 gdk/wayland/protocol/cursor-shape-v1.xml diff --git a/gdk/wayland/gdkcursor-wayland.c b/gdk/wayland/gdkcursor-wayland.c index 6a5e2cf53dd..37e169a1daf 100644 --- a/gdk/wayland/gdkcursor-wayland.c +++ b/gdk/wayland/gdkcursor-wayland.c @@ -211,6 +211,13 @@ gdk_wayland_cursor_get_surface (GdkCursor *cursor, return NULL; } +const char * +_gdk_wayland_cursor_get_name (GdkCursor *cursor) +{ + GdkWaylandCursor *wayland_cursor = GDK_WAYLAND_CURSOR (cursor); + return wayland_cursor->name; +} + struct wl_buffer * _gdk_wayland_cursor_get_buffer (GdkCursor *cursor, guint image_index, diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index 0fc3ec3e15c..52c3e4fa95c 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -35,6 +35,7 @@ #include "gdkseatprivate.h" #include "pointer-gestures-unstable-v1-client-protocol.h" #include "tablet-unstable-v2-client-protocol.h" +#include "cursor-shape-v1-client-protocol.h" #include @@ -99,6 +100,7 @@ struct _GdkWaylandPointerData { uint32_t grab_time; struct wl_surface *pointer_surface; + struct wp_cursor_shape_device_v1 *shape_device; GdkCursor *cursor; guint cursor_timeout_id; guint cursor_image_index; @@ -115,6 +117,7 @@ struct _GdkWaylandTabletToolData { GdkSeat *seat; struct zwp_tablet_tool_v2 *wp_tablet_tool; + struct wp_cursor_shape_device_v1 *shape_device; GdkAxisFlags axes; GdkDeviceToolType type; guint64 hardware_serial; @@ -406,6 +409,77 @@ gdk_wayland_device_manager_find_pad (GdkWaylandSeat *seat, } +static const struct +{ + const char *cursor_name; + unsigned int shape; + unsigned int version; +} shape_map[] = { + { "default", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT, 1 }, + { "context-menu", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CONTEXT_MENU, 1 }, + { "help", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_HELP, 1 }, + { "pointer", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER, 1 }, + { "progress", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_PROGRESS }, + { "wait", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_WAIT, 1 }, + { "cell", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CELL, 1 }, + { "crosshair", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR, 1 }, + { "text", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT, 1 }, + { "vertical-text", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_VERTICAL_TEXT, 1 }, + { "alias", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALIAS, 1 }, + { "copy", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_COPY, 1 }, + { "move", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE, 1 }, + { "no-drop", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NO_DROP, 1 }, + { "not-allowed", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NOT_ALLOWED, 1 }, + { "grab", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_GRAB, 1 }, + { "grabbing", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_GRABBING, 1 }, + { "e-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_E_RESIZE, 1 }, + { "n-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_N_RESIZE, 1 }, + { "ne-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NE_RESIZE, 1 }, + { "nw-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NW_RESIZE, 1 }, + { "s-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_S_RESIZE, 1 }, + { "se-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_SE_RESIZE, 1 }, + { "sw-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_SW_RESIZE, 1 }, + { "w-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_W_RESIZE, 1 }, + { "ew-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_EW_RESIZE, 1 }, + { "ns-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NS_RESIZE, 1 }, + { "nesw-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NESW_RESIZE, 1 }, + { "nwse-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NWSE_RESIZE, 1 }, + { "col-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_COL_RESIZE, 1 }, + { "row-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ROW_RESIZE, 1 }, + { "all-scroll", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_SCROLL, 1 }, + { "zoom-in", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ZOOM_IN, 1 }, + { "zoom-out", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ZOOM_OUT, 1 }, + { "all-scroll", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_SCROLL, 1 }, + /* the following a v2 additions, with a fallback for v1 */ + { "dnd-ask", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DND_ASK, 2 }, + { "dnd-ask", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CONTEXT_MENU, 1 }, + { "all-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_RESIZE, 2 }, + { "all-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE, 1 }, + { "none", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NONE, 2 }, + { "none", 0, 1 }, +}; + +static unsigned int +_gdk_wayland_cursor_get_shape (GdkCursor *cursor, + int version) +{ + gsize i; + const char *cursor_name; + + cursor_name = _gdk_wayland_cursor_get_name (cursor); + if (cursor_name == NULL) + return 0; + + for (i = 0; i < G_N_ELEMENTS (shape_map); i++) + { + if (g_str_equal (shape_map[i].cursor_name, cursor_name) && + version >= shape_map[i].version) + return shape_map[i].shape; + } + + return 0; +} + static gboolean gdk_wayland_device_update_window_cursor (GdkDevice *device) { @@ -416,29 +490,50 @@ gdk_wayland_device_update_window_cursor (GdkDevice *device) guint next_image_index, next_image_delay; gboolean retval = G_SOURCE_REMOVE; GdkWaylandTabletData *tablet; + unsigned int shape; tablet = gdk_wayland_device_manager_find_tablet (seat, device); - if (pointer->cursor) + if (!pointer->cursor) { - buffer = _gdk_wayland_cursor_get_buffer (pointer->cursor, - pointer->cursor_image_index, - &x, &y, &w, &h, &scale); + pointer->cursor_timeout_id = 0; + return G_SOURCE_REMOVE; } - else + + if (tablet && !tablet->current_tool) { pointer->cursor_timeout_id = 0; return G_SOURCE_REMOVE; } - if (tablet) + if (GDK_WAYLAND_DISPLAY (seat->display)->cursor_shape) { - if (!tablet->current_tool) + shape = _gdk_wayland_cursor_get_shape (pointer->cursor, + wp_cursor_shape_manager_v1_get_version (GDK_WAYLAND_DISPLAY (seat->display)->cursor_shape)); + if (shape != 0) { - pointer->cursor_timeout_id = 0; - return G_SOURCE_REMOVE; + if (tablet && tablet->current_tool->shape_device) + { + wp_cursor_shape_device_v1_set_shape (tablet->current_tool->shape_device, pointer->enter_serial, shape); + return G_SOURCE_REMOVE; + } + else if (seat->wl_pointer && pointer->shape_device) + { + wp_cursor_shape_device_v1_set_shape (pointer->shape_device, pointer->enter_serial, shape); + return G_SOURCE_REMOVE; + } } + } + if (pointer->cursor) + { + buffer = _gdk_wayland_cursor_get_buffer (pointer->cursor, + pointer->cursor_image_index, + &x, &y, &w, &h, &scale); + } + + if (tablet) + { zwp_tablet_tool_v2_set_cursor (tablet->current_tool->wp_tablet_tool, pointer->enter_serial, pointer->pointer_surface, @@ -2856,6 +2951,8 @@ static void _gdk_wayland_seat_remove_tool (GdkWaylandSeat *seat, GdkWaylandTabletToolData *tool) { + g_clear_pointer (&tool->shape_device, wp_cursor_shape_device_v1_destroy); + seat->tablet_tools = g_list_remove (seat->tablet_tools, tool); gdk_seat_tool_removed (GDK_SEAT (seat), tool->tool); @@ -3185,6 +3282,12 @@ seat_handle_capabilities (void *data, &gesture_pinch_listener, seat); } + if (display_wayland->cursor_shape) + { + seat->pointer_info.shape_device = + wp_cursor_shape_manager_v1_get_pointer (display_wayland->cursor_shape, seat->wl_pointer); + } + g_signal_emit_by_name (device_manager, "device-added", seat->pointer); } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && seat->wl_pointer) @@ -3231,6 +3334,8 @@ seat_handle_capabilities (void *data, g_signal_emit_by_name (device_manager, "device-removed", seat->continuous_scrolling); g_clear_object (&seat->continuous_scrolling); } + + g_clear_pointer (&seat->pointer_info.shape_device, wp_cursor_shape_device_v1_destroy); } if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !seat->wl_keyboard) @@ -4625,6 +4730,7 @@ tablet_seat_handle_tool_added (void *data, { GdkWaylandSeat *seat = data; GdkWaylandTabletToolData *tool; + GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display); tool = g_new0 (GdkWaylandTabletToolData, 1); tool->wp_tablet_tool = wp_tablet_tool; @@ -4634,6 +4740,13 @@ tablet_seat_handle_tool_added (void *data, zwp_tablet_tool_v2_set_user_data (wp_tablet_tool, tool); seat->tablet_tools = g_list_prepend (seat->tablet_tools, tool); + + if (display->cursor_shape) + { + tool->shape_device = + wp_cursor_shape_manager_v1_get_tablet_tool_v2 ( + display->cursor_shape, tool->wp_tablet_tool); + } } static void diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c index 8b4c3496b3f..7da4ed01bf4 100644 --- a/gdk/wayland/gdkdisplay-wayland.c +++ b/gdk/wayland/gdkdisplay-wayland.c @@ -553,6 +553,12 @@ gdk_registry_handle_global (void *data, display_wayland->xdg_activation_version); } #endif + else if (strcmp (interface, wp_cursor_shape_manager_v1_interface.name) == 0) + { + display_wayland->cursor_shape = + wl_registry_bind (display_wayland->wl_registry, id, + &wp_cursor_shape_manager_v1_interface, 1); + } g_hash_table_insert (display_wayland->known_globals, GUINT_TO_POINTER (id), g_strdup (interface)); diff --git a/gdk/wayland/gdkdisplay-wayland.h b/gdk/wayland/gdkdisplay-wayland.h index eb5e4b3b310..d379d1c0d56 100644 --- a/gdk/wayland/gdkdisplay-wayland.h +++ b/gdk/wayland/gdkdisplay-wayland.h @@ -40,6 +40,7 @@ #ifdef HAVE_XDG_ACTIVATION #include #endif +#include #include #include @@ -108,6 +109,7 @@ struct _GdkWaylandDisplay #ifdef HAVE_XDG_ACTIVATION struct xdg_activation_v1 *xdg_activation; #endif + struct wp_cursor_shape_manager_v1 *cursor_shape; GList *async_roundtrips; diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h index 64aa708b2d3..1916a1283c1 100644 --- a/gdk/wayland/gdkprivate-wayland.h +++ b/gdk/wayland/gdkprivate-wayland.h @@ -89,6 +89,8 @@ gboolean _gdk_wayland_display_supports_cursor_color (GdkDisplay *display); void gdk_wayland_display_system_bell (GdkDisplay *display, GdkWindow *window); +const char *_gdk_wayland_cursor_get_name (GdkCursor *cursor); + struct wl_buffer *_gdk_wayland_cursor_get_buffer (GdkCursor *cursor, guint image_index, int *hotspot_x, diff --git a/gdk/wayland/meson.build b/gdk/wayland/meson.build index af7ea1f6981..ef07d135dec 100644 --- a/gdk/wayland/meson.build +++ b/gdk/wayland/meson.build @@ -59,6 +59,7 @@ proto_sources = [ ['server-decoration', 'private' ], ['xdg-output', 'unstable', 'v1', ], ['primary-selection', 'unstable', 'v1', ], + ['cursor-shape-v1', 'private', ], ] if wlprotocolsdep.version().version_compare('>=1.21') proto_sources += [['xdg-activation', 'staging', 'v1', ]] diff --git a/gdk/wayland/protocol/cursor-shape-v1.xml b/gdk/wayland/protocol/cursor-shape-v1.xml new file mode 100644 index 00000000000..ea55c4d12af --- /dev/null +++ b/gdk/wayland/protocol/cursor-shape-v1.xml @@ -0,0 +1,163 @@ + + + + Copyright 2018 The Chromium Authors + Copyright 2023 Simon Ser + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + + + + This global offers an alternative, optional way to set cursor images. This + new way uses enumerated cursors instead of a wl_surface like + wl_pointer.set_cursor does. + + Warning! The protocol described in this file is currently in the testing + phase. Backward compatible changes may be added together with the + corresponding interface version bump. Backward incompatible changes can + only be done by creating a new major version of the extension. + + + + + Destroy the cursor shape manager. + + + + + + Obtain a wp_cursor_shape_device_v1 for a wl_pointer object. + + When the pointer capability is removed from the wl_seat, the + wp_cursor_shape_device_v1 object becomes inert. + + + + + + + + Obtain a wp_cursor_shape_device_v1 for a zwp_tablet_tool_v2 object. + + When the zwp_tablet_tool_v2 is removed, the wp_cursor_shape_device_v1 + object becomes inert. + + + + + + + + + This interface allows clients to set the cursor shape. + + + + + This enum describes cursor shapes. + + The names are taken from the CSS W3C specification: + https://w3c.github.io/csswg-drafts/css-ui/#cursor + with a few additions. + + Note that there are some groups of cursor shapes that are related: + The first group is drag-and-drop cursors which are used to indicate + the selected action during dnd operations. The second group is resize + cursors which are used to indicate resizing and moving possibilities + on window borders. It is recommended that the shapes in these groups + should use visually compatible images and metaphors. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Destroy the cursor shape device. + + The device cursor shape remains unchanged. + + + + + + Sets the device cursor to the specified shape. The compositor will + change the cursor image based on the specified shape. + + The cursor actually changes only if the input device focus is one of + the requesting client's surfaces. If any, the previous cursor image + (surface or shape) is replaced. + + The "shape" argument must be a valid enum entry, otherwise the + invalid_shape protocol error is raised. + + This is similar to the wl_pointer.set_cursor and + zwp_tablet_tool_v2.set_cursor requests, but this request accepts a + shape instead of contents in the form of a surface. Clients can mix + set_cursor and set_shape requests. + + The serial parameter must match the latest wl_pointer.enter or + zwp_tablet_tool_v2.proximity_in serial number sent to the client. + Otherwise the request will be ignored. + + + + + + -- GitLab From 580846fcdc15727bd3e17bbb466201b76ccc8c35 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 28 Feb 2025 07:35:13 -0500 Subject: [PATCH 5/6] wayland: Go back to the old none cursor Upstream found this enum value objectionable, despite being a perfectly good CSS cursor. (cherry picked from commit eda5bd5242a9b04ed5c1e9f43592c7fc9d8dca4a) --- gdk/wayland/gdkdevice-wayland.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index 52c3e4fa95c..ea9c3809556 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -455,8 +455,6 @@ static const struct { "dnd-ask", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CONTEXT_MENU, 1 }, { "all-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_RESIZE, 2 }, { "all-resize", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE, 1 }, - { "none", WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NONE, 2 }, - { "none", 0, 1 }, }; static unsigned int @@ -467,7 +465,8 @@ _gdk_wayland_cursor_get_shape (GdkCursor *cursor, const char *cursor_name; cursor_name = _gdk_wayland_cursor_get_name (cursor); - if (cursor_name == NULL) + if (cursor_name == NULL || + g_str_equal (cursor_name, "none") == 0) return 0; for (i = 0; i < G_N_ELEMENTS (shape_map); i++) -- GitLab From d6cb3b4a2a4d4ce69f74ef768521ee9d4d311fa2 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sun, 2 Mar 2025 23:13:02 +0200 Subject: [PATCH 6/6] wayland: Fix none cursor check We should skip going through the look up table if the cursor name is "none", i.e. when g_str_equal() returns true or 1. (cherry picked from commit 7ee2e50dc4f0898f7d56d67017c36414618f2e82) --- gdk/wayland/gdkdevice-wayland.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index ea9c3809556..0b0c966225f 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -466,7 +466,7 @@ _gdk_wayland_cursor_get_shape (GdkCursor *cursor, cursor_name = _gdk_wayland_cursor_get_name (cursor); if (cursor_name == NULL || - g_str_equal (cursor_name, "none") == 0) + g_str_equal (cursor_name, "none")) return 0; for (i = 0; i < G_N_ELEMENTS (shape_map); i++) -- GitLab