Repository: godotengine/godot
Pull request #106251: [Wayland] Implement the cursor-shape-v1 protocol
Author: login: ArchercatNEO
Labels: name: enhancement
name: platform:linuxbsd
name: topic:platforms
Created: 2025-05-10T17:20:47Z | Merged: 2025-05-16T15:32:12Z

Related #106229. The color-shape protocol allows us to not have to deal with cursor theming and instead depend on the compositor for it.
This still does not quite solve the issue when the compositor doesn't implement the protocol (or running under the x11 backend) but for gnome/kde and a few more this should resolve things.

@Chapien On breeze I can get the normal pointer, text input and renames but can't quite remember where else to hover to get more cursors so how is this running for you?



Diff:
diff --git a/platform/linuxbsd/wayland/SCsub b/platform/linuxbsd/wayland/SCsub
index 4cceb49977a5..f9d3aee706a2 100644
--- a/platform/linuxbsd/wayland/SCsub
+++ b/platform/linuxbsd/wayland/SCsub
@@ -46,6 +46,14 @@ env.NoCache(
         "protocol/viewporter.gen.h", "#thirdparty/wayland-protocols/stable/viewporter/viewporter.xml"
     ),
     env.WAYLAND_API_CODE("protocol/viewporter.gen.c", "#thirdparty/wayland-protocols/stable/viewporter/viewporter.xml"),
+    env.WAYLAND_API_HEADER(
+        "protocol/cursor_shape.gen.h",
+        "#thirdparty/wayland-protocols/staging/cursor-shape/cursor-shape-v1.xml",
+    ),
+    env.WAYLAND_API_CODE(
+        "protocol/cursor_shape.gen.c",
+        "#thirdparty/wayland-protocols/staging/cursor-shape/cursor-shape-v1.xml",
+    ),
     env.WAYLAND_API_HEADER(
         "protocol/fractional_scale.gen.h",
         "#thirdparty/wayland-protocols/staging/fractional-scale/fractional-scale-v1.xml",
@@ -158,6 +166,7 @@ env.NoCache(
 source_files = [
     "protocol/wayland.gen.c",
     "protocol/viewporter.gen.c",
+    "protocol/cursor_shape.gen.c",
     "protocol/fractional_scale.gen.c",
     "protocol/xdg_shell.gen.c",
     "protocol/xdg_system_bell.gen.c",
diff --git a/platform/linuxbsd/wayland/wayland_thread.cpp b/platform/linuxbsd/wayland/wayland_thread.cpp
index 4f5a08e96b64..aaa0c0106ffd 100644
--- a/platform/linuxbsd/wayland/wayland_thread.cpp
+++ b/platform/linuxbsd/wayland/wayland_thread.cpp
@@ -547,6 +547,12 @@ void WaylandThread::_wl_registry_on_global(void *data, struct wl_registry *wl_re
 		registry->wp_viewporter_name = name;
 	}
 
+	if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
+		registry->wp_cursor_shape_manager = (struct wp_cursor_shape_manager_v1 *)wl_registry_bind(wl_registry, name, &wp_cursor_shape_manager_v1_interface, 1);
+		registry->wp_cursor_shape_manager_name = name;
+		return;
+	}
+
 	if (strcmp(interface, wp_fractional_scale_manager_v1_interface.name) == 0) {
 		registry->wp_fractional_scale_manager = (struct wp_fractional_scale_manager_v1 *)wl_registry_bind(wl_registry, name, &wp_fractional_scale_manager_v1_interface, 1);
 		registry->wp_fractional_scale_manager_name = name;
@@ -753,6 +759,25 @@ void WaylandThread::_wl_registry_on_global_remove(void *data, struct wl_registry
 		return;
 	}
 
+	if (name == registry->wp_cursor_shape_manager_name) {
+		if (registry->wp_cursor_shape_manager) {
+			wp_cursor_shape_manager_v1_destroy(registry->wp_cursor_shape_manager);
+			registry->wp_cursor_shape_manager = nullptr;
+		}
+
+		registry->wp_cursor_shape_manager_name = 0;
+
+		for (struct wl_seat *wl_seat : registry->wl_seats) {
+			SeatState *ss = wl_seat_get_seat_state(wl_seat);
+			ERR_FAIL_NULL(ss);
+
+			if (ss->wp_cursor_shape_device) {
+				wp_cursor_shape_device_v1_destroy(ss->wp_cursor_shape_device);
+				ss->wp_cursor_shape_device = nullptr;
+			}
+		}
+	}
+
 	if (name == registry->wp_fractional_scale_manager_name) {
 		for (KeyValue<DisplayServer::WindowID, WindowState> &pair : registry->wayland_thread->windows) {
 			WindowState ws = pair.value;
@@ -1452,6 +1477,10 @@ void WaylandThread::_wl_seat_on_capabilities(void *data, struct wl_seat *wl_seat
 			ss->wl_pointer = wl_seat_get_pointer(wl_seat);
 			wl_pointer_add_listener(ss->wl_pointer, &wl_pointer_listener, ss);
 
+			if (ss->registry->wp_cursor_shape_manager) {
+				ss->wp_cursor_shape_device = wp_cursor_shape_manager_v1_get_pointer(ss->registry->wp_cursor_shape_manager, ss->wl_pointer);
+			}
+
 			if (ss->registry->wp_relative_pointer_manager) {
 				ss->wp_relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer(ss->registry->wp_relative_pointer_manager, ss->wl_pointer);
 				zwp_relative_pointer_v1_add_listener(ss->wp_relative_pointer, &wp_relative_pointer_listener, ss);
@@ -1483,6 +1512,11 @@ void WaylandThread::_wl_seat_on_capabilities(void *data, struct wl_seat *wl_seat
 			ss->wl_pointer = nullptr;
 		}
 
+		if (ss->wp_cursor_shape_device) {
+			wp_cursor_shape_device_v1_destroy(ss->wp_cursor_shape_device);
+			ss->wp_cursor_shape_device = nullptr;
+		}
+
 		if (ss->wp_relative_pointer) {
 			zwp_relative_pointer_v1_destroy(ss->wp_relative_pointer);
 			ss->wp_relative_pointer = nullptr;
@@ -3328,6 +3362,12 @@ void WaylandThread::seat_state_update_cursor(SeatState *p_ss) {
 			// We can't really reasonably scale custom cursors, so we'll let the
 			// compositor do it for us (badly).
 			scale = 1;
+		} else if (thread->registry.wp_cursor_shape_manager) {
+			wp_cursor_shape_device_v1_shape wp_shape = thread->standard_cursors[shape];
+			wp_cursor_shape_device_v1_set_shape(p_ss->wp_cursor_shape_device, p_ss->pointer_enter_serial, wp_shape);
+
+			// We should avoid calling the `wl_pointer_set_cursor` at the end of this method.
+			return;
 		} else {
 			struct wl_cursor *wl_cursor = thread->wl_cursors[shape];
 
@@ -4890,6 +4930,10 @@ void WaylandThread::destroy() {
 			wl_data_device_destroy(ss->wl_data_device);
 		}
 
+		if (ss->wp_cursor_shape_device) {
+			wp_cursor_shape_device_v1_destroy(ss->wp_cursor_shape_device);
+		}
+
 		if (ss->wp_relative_pointer) {
 			zwp_relative_pointer_v1_destroy(ss->wp_relative_pointer);
 		}
@@ -4957,6 +5001,10 @@ void WaylandThread::destroy() {
 		zxdg_decoration_manager_v1_destroy(registry.xdg_decoration_manager);
 	}
 
+	if (registry.wp_cursor_shape_manager) {
+		wp_cursor_shape_manager_v1_destroy(registry.wp_cursor_shape_manager);
+	}
+
 	if (registry.wp_fractional_scale_manager) {
 		wp_fractional_scale_manager_v1_destroy(registry.wp_fractional_scale_manager);
 	}
diff --git a/platform/linuxbsd/wayland/wayland_thread.h b/platform/linuxbsd/wayland/wayland_thread.h
index b70e6a359fe0..64e1babcf672 100644
--- a/platform/linuxbsd/wayland/wayland_thread.h
+++ b/platform/linuxbsd/wayland/wayland_thread.h
@@ -51,10 +51,11 @@
 // These must go after the Wayland client include to work properly.
 #include "wayland/protocol/idle_inhibit.gen.h"
 #include "wayland/protocol/primary_selection.gen.h"
-// These three protocol headers name wl_pointer method arguments as `pointer`,
+// These four protocol headers name wl_pointer method arguments as `pointer`,
 // which is the same name as X11's pointer typedef. This trips some very
 // annoying shadowing warnings. A `#define` works around this issue.
 #define pointer wl_pointer
+#include "wayland/protocol/cursor_shape.gen.h"
 #include "wayland/protocol/pointer_constraints.gen.h"
 #include "wayland/protocol/pointer_gestures.gen.h"
 #include "wayland/protocol/relative_pointer.gen.h"
@@ -187,6 +188,9 @@ class WaylandThread {
 		struct wp_fractional_scale_manager_v1 *wp_fractional_scale_manager = nullptr;
 		uint32_t wp_fractional_scale_manager_name = 0;
 
+		struct wp_cursor_shape_manager_v1 *wp_cursor_shape_manager = nullptr;
+		uint32_t wp_cursor_shape_manager_name = 0;
+
 		struct zxdg_decoration_manager_v1 *xdg_decoration_manager = nullptr;
 		uint32_t xdg_decoration_manager_name = 0;
 
@@ -416,6 +420,8 @@ class WaylandThread {
 
 		uint32_t pointer_enter_serial = 0;
 
+		struct wp_cursor_shape_device_v1 *wp_cursor_shape_device = nullptr;
+
 		struct zwp_relative_pointer_v1 *wp_relative_pointer = nullptr;
 		struct zwp_locked_pointer_v1 *wp_locked_pointer = nullptr;
 		struct zwp_confined_pointer_v1 *wp_confined_pointer = nullptr;
@@ -547,9 +553,32 @@ class WaylandThread {
 	// especially as usually screen scales don't change continuously.
 	int cursor_scale = 1;
 
+	// Use cursor-shape-v1 protocol if the compositor supports it.
+	wp_cursor_shape_device_v1_shape standard_cursors[DisplayServer::CURSOR_MAX] = {
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT, //CURSOR_ARROW
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT, //CURSOR_IBEAM
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER, //CURSOR_POINTING_HAND
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR, //CURSOR_CROSS
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_WAIT, //CURSOR_WAIT
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_PROGRESS, //CURSOR_BUSY
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_GRAB, //CURSOR_DRAG
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_GRABBING, //CURSOR_CAN_DROP
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NO_DROP, //CURSOR_FORBIDDEN
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NS_RESIZE, //CURSOR_VSIZE
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_EW_RESIZE, //CURSOR_HSIZE
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NESW_RESIZE, //CURSOR_BDIAGSIZE
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NWSE_RESIZE, //CURSOR_FDIAGSIZE
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE, //CURSOR_MOVE
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ROW_RESIZE, //CURSOR_VSPLIT
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_COL_RESIZE, //CURSOR_HSPLIT
+		wp_cursor_shape_device_v1_shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_HELP, //CURSOR_HELP
+	};
+
+	// Fallback to reading $XCURSOR and system themes if the compositor does not.
 	struct wl_cursor_theme *wl_cursor_theme = nullptr;
 	struct wl_cursor *wl_cursors[DisplayServer::CURSOR_MAX] = {};
 
+	// User-defined cursor overrides. Take precedence over standard and wl cursors.
 	HashMap<DisplayServer::CursorShape, CustomCursor> custom_cursors;
 
 	DisplayServer::CursorShape cursor_shape = DisplayServer::CURSOR_ARROW;
diff --git a/thirdparty/wayland-protocols/staging/cursor-shape/README b/thirdparty/wayland-protocols/staging/cursor-shape/README
new file mode 100644
index 000000000000..7ca8f5e1d3b3
--- /dev/null
+++ b/thirdparty/wayland-protocols/staging/cursor-shape/README
@@ -0,0 +1,4 @@
+cursor-shape protocol
+
+Maintainers:
+Simon Ser <contact@emersion.fr> (@emersion)
diff --git a/thirdparty/wayland-protocols/staging/cursor-shape/cursor-shape-v1.xml b/thirdparty/wayland-protocols/staging/cursor-shape/cursor-shape-v1.xml
new file mode 100644
index 000000000000..64b2f9b2c877
--- /dev/null
+++ b/thirdparty/wayland-protocols/staging/cursor-shape/cursor-shape-v1.xml
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="cursor_shape_v1">
+  <copyright>
+    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.
+  </copyright>
+
+  <interface name="wp_cursor_shape_manager_v1" version="2">
+    <description summary="cursor shape manager">
+      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.
+    </description>
+
+    <request name="destroy" type="destructor">
+      <description summary="destroy the manager">
+        Destroy the cursor shape manager.
+      </description>
+    </request>
+
+    <request name="get_pointer">
+      <description summary="manage the cursor shape of a pointer device">
+        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.
+      </description>
+      <arg name="cursor_shape_device" type="new_id" interface="wp_cursor_shape_device_v1"/>
+      <arg name="pointer" type="object" interface="wl_pointer"/>
+    </request>
+
+    <request name="get_tablet_tool_v2">
+      <description summary="manage the cursor shape of a tablet tool device">
+        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.
+      </description>
+      <arg name="cursor_shape_device" type="new_id" interface="wp_cursor_shape_device_v1"/>
+      <arg name="tablet_tool" type="object" interface="zwp_tablet_tool_v2"/>
+    </request>
+  </interface>
+
+  <interface name="wp_cursor_shape_device_v1" version="2">
+    <description summary="cursor shape for a device">
+      This interface allows clients to set the cursor shape.
+    </description>
+
+    <enum name="shape">
+      <description summary="cursor shapes">
+        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.
+      </description>
+      <entry name="default" value="1" summary="default cursor"/>
+      <entry name="context_menu" value="2" summary="a context menu is available for the object under the cursor"/>
+      <entry name="help" value="3" summary="help is available for the object under the cursor"/>
+      <entry name="pointer" value="4" summary="pointer that indicates a link or another interactive element"/>
+      <entry name="progress" value="5" summary="progress indicator"/>
+      <entry name="wait" value="6" summary="program is busy, user should wait"/>
+      <entry name="cell" value="7" summary="a cell or set of cells may be selected"/>
+      <entry name="crosshair" value="8" summary="simple crosshair"/>
+      <entry name="text" value="9" summary="text may be selected"/>
+      <entry name="vertical_text" value="10" summary="vertical text may be selected"/>
+      <entry name="alias" value="11" summary="drag-and-drop: alias of/shortcut to something is to be created"/>
+      <entry name="copy" value="12" summary="drag-and-drop: something is to be copied"/>
+      <entry name="move" value="13" summary="drag-and-drop: something is to be moved"/>
+      <entry name="no_drop" value="14" summary="drag-and-drop: the dragged item cannot be dropped at the current cursor location"/>
+      <entry name="not_allowed" value="15" summary="drag-and-drop: the requested action will not be carried out"/>
+      <entry name="grab" value="16" summary="drag-and-drop: something can be grabbed"/>
+      <entry name="grabbing" value="17" summary="drag-and-drop: something is being grabbed"/>
+      <entry name="e_resize" value="18" summary="resizing: the east border is to be moved"/>
+      <entry name="n_resize" value="19" summary="resizing: the north border is to be moved"/>
+      <entry name="ne_resize" value="20" summary="resizing: the north-east corner is to be moved"/>
+      <entry name="nw_resize" value="21" summary="resizing: the north-west corner is to be moved"/>
+      <entry name="s_resize" value="22" summary="resizing: the south border is to be moved"/>
+      <entry name="se_resize" value="23" summary="resizing: the south-east corner is to be moved"/>
+      <entry name="sw_resize" value="24" summary="resizing: the south-west corner is to be moved"/>
+      <entry name="w_resize" value="25" summary="resizing: the west border is to be moved"/>
+      <entry name="ew_resize" value="26" summary="resizing: the east and west borders are to be moved"/>
+      <entry name="ns_resize" value="27" summary="resizing: the north and south borders are to be moved"/>
+      <entry name="nesw_resize" value="28" summary="resizing: the north-east and south-west corners are to be moved"/>
+      <entry name="nwse_resize" value="29" summary="resizing: the north-west and south-east corners are to be moved"/>
+      <entry name="col_resize" value="30" summary="resizing: that the item/column can be resized horizontally"/>
+      <entry name="row_resize" value="31" summary="resizing: that the item/row can be resized vertically"/>
+      <entry name="all_scroll" value="32" summary="something can be scrolled in any direction"/>
+      <entry name="zoom_in" value="33" summary="something can be zoomed in"/>
+      <entry name="zoom_out" value="34" summary="something can be zoomed out"/>
+      <entry name="dnd_ask" value="35" summary="drag-and-drop: the user will select which action will be carried out (non-css value)" since="2"/>
+      <entry name="all_resize" value="36" summary="resizing: something can be moved or resized in any direction (non-css value)" since="2"/>
+    </enum>
+
+    <enum name="error">
+      <entry name="invalid_shape" value="1"
+        summary="the specified shape value is invalid"/>
+    </enum>
+
+    <request name="destroy" type="destructor">
+      <description summary="destroy the cursor shape device">
+        Destroy the cursor shape device.
+
+        The device cursor shape remains unchanged.
+      </description>
+    </request>
+
+    <request name="set_shape">
+      <description summary="set device cursor to the shape">
+        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.
+      </description>
+      <arg name="serial" type="uint" summary="serial number of the enter event"/>
+      <arg name="shape" type="uint" enum="shape"/>
+    </request>
+  </interface>
+</protocol>


Reviews:
user: login: deralmas
body: Hi, thank you for your contribution! I gave an initial look at the code.

(BTW, it's cursor-shape-v1 :P )
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-05-10T19:45:01Z
user: login: ArchercatNEO
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-11T06:37:25Z
user: login: ArchercatNEO
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-11T06:39:49Z
user: login: ArchercatNEO
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-11T06:43:31Z
user: login: deralmas
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-14T18:56:52Z
user: login: deralmas
body: All good now!
state: APPROVED
author_association: MEMBER
submitted_at: 2025-05-15T18:08:58Z

Review comments:
diff_hunk: @@ -3308,6 +3323,13 @@ void WaylandThread::seat_state_update_cursor(SeatState *p_ss) {
 		return;
 	}
 
+	if (thread->registry.wp_cursor_shape_manager) {
+		wp_cursor_shape_device_v1_shape shape = thread->standard_cursors.get(thread->cursor_shape);
+		struct wp_cursor_shape_device_v1 *cursor = wp_cursor_shape_manager_v1_get_pointer(thread->registry.wp_cursor_shape_manager, p_ss->wl_pointer);
path: platform/linuxbsd/wayland/wayland_thread.cpp
user: login: deralmas
body: This would cause a memory leak, since you don't destroy the cursor. Also, I think it would be more correct to instantiate the cursor shape device a bit like the relative pointer object, store it in the `SeatState` and reuse it between invocations.

Unfortunately everything "attached" to `wl_pointer`s must go through quite a few hoops to be registered/cleaned properly, so I can really only tell you to grep for `zwp_relative_pointer_v1` and go on from there.
created_at: 2025-05-10T19:36:15Z
author_association: MEMBER
diff_hunk: @@ -3308,6 +3323,13 @@ void WaylandThread::seat_state_update_cursor(SeatState *p_ss) {
 		return;
 	}
 
+	if (thread->registry.wp_cursor_shape_manager) {
+		wp_cursor_shape_device_v1_shape shape = thread->standard_cursors.get(thread->cursor_shape);
+		struct wp_cursor_shape_device_v1 *cursor = wp_cursor_shape_manager_v1_get_pointer(thread->registry.wp_cursor_shape_manager, p_ss->wl_pointer);
+		wp_cursor_shape_device_v1_set_shape(cursor, p_ss->pointer_enter_serial, shape);
+		return;
path: platform/linuxbsd/wayland/wayland_thread.cpp
user: login: deralmas
body: Have you tested custom cursors and pointer hiding? I'm afraid that this return statement will skip everything related to them.

More specifically, I'd move if statement in the `else` block of `if (custom_cursor)`, down there where non-custom `wl_cursor`s are handled. Looking at the docs, clients can mix `set_cursor` and `set_shape` with no issues, so that should do the trick.
created_at: 2025-05-10T19:36:54Z
author_association: MEMBER
diff_hunk: @@ -4310,6 +4332,26 @@ Error WaylandThread::init() {
 	}
 #endif // LIBDECOR_ENABLED
 
+	standard_cursors = HashMap<DisplayServer::CursorShape, wp_cursor_shape_device_v1_shape>();
path: platform/linuxbsd/wayland/wayland_thread.cpp
user: login: deralmas
body: IMO an hash map might be a bit overkill. Since it's an enum and thus a sequence from 0 (the first enum) to CURSOR_MAX, I think you might do something like the `wl_cursors` variable, which is a simple `CURSOR_MAX` sized stack array and fill that. Perhaps you might even just make a big switch case really.
created_at: 2025-05-10T19:41:50Z
author_association: MEMBER
diff_hunk: @@ -3308,6 +3323,13 @@ void WaylandThread::seat_state_update_cursor(SeatState *p_ss) {
 		return;
 	}
 
+	if (thread->registry.wp_cursor_shape_manager) {
+		wp_cursor_shape_device_v1_shape shape = thread->standard_cursors.get(thread->cursor_shape);
+		struct wp_cursor_shape_device_v1 *cursor = wp_cursor_shape_manager_v1_get_pointer(thread->registry.wp_cursor_shape_manager, p_ss->wl_pointer);
path: platform/linuxbsd/wayland/wayland_thread.cpp
user: login: ArchercatNEO
body: I grepped a bunch and now the cursor_shape_device is with all the other pointer structs. Hopefully I got every place it needed to be destroyed in.
created_at: 2025-05-11T06:37:25Z
author_association: CONTRIBUTOR
diff_hunk: @@ -3308,6 +3323,13 @@ void WaylandThread::seat_state_update_cursor(SeatState *p_ss) {
 		return;
 	}
 
+	if (thread->registry.wp_cursor_shape_manager) {
+		wp_cursor_shape_device_v1_shape shape = thread->standard_cursors.get(thread->cursor_shape);
+		struct wp_cursor_shape_device_v1 *cursor = wp_cursor_shape_manager_v1_get_pointer(thread->registry.wp_cursor_shape_manager, p_ss->wl_pointer);
+		wp_cursor_shape_device_v1_set_shape(cursor, p_ss->pointer_enter_serial, shape);
+		return;
path: platform/linuxbsd/wayland/wayland_thread.cpp
user: login: ArchercatNEO
body: I've moved the priority to `custom_cursor > standard_cursor > wl_cursor` which should mean pointer hiding and user-defined cursors work now while still using wp-cursor-shape over system theme when the compositor supports it. Return is still there just so we don't override the `set_shape` call with a `set_cursor` call.
created_at: 2025-05-11T06:39:49Z
author_association: CONTRIBUTOR
diff_hunk: @@ -4310,6 +4332,26 @@ Error WaylandThread::init() {
 	}
 #endif // LIBDECOR_ENABLED
 
+	standard_cursors = HashMap<DisplayServer::CursorShape, wp_cursor_shape_device_v1_shape>();
path: platform/linuxbsd/wayland/wayland_thread.cpp
user: login: ArchercatNEO
body: Truthfully I had forgotten arrays existed when I did this... I started with a big switch but that felt quite cumbersome so now it's just an array, hopefully that works a bit better.
created_at: 2025-05-11T06:43:31Z
author_association: CONTRIBUTOR
diff_hunk: @@ -3328,6 +3362,12 @@ void WaylandThread::seat_state_update_cursor(SeatState *p_ss) {
 			// We can't really reasonably scale custom cursors, so we'll let the
 			// compositor do it for us (badly).
 			scale = 1;
+		} else if (thread->registry.wp_cursor_shape_manager) {
+			wp_cursor_shape_device_v1_shape wp_shape = thread->standard_cursors[shape];
+			wp_cursor_shape_device_v1_set_shape(p_ss->wp_cursor_shape_device, p_ss->pointer_enter_serial, wp_shape);
+
+			//we should avoid calling the `wl_pointer_set_cursor` at the end of this method
path: platform/linuxbsd/wayland/wayland_thread.cpp
user: login: deralmas
body: ```suggestion
			// We should avoid calling the `wl_pointer_set_cursor` at the end of this method.
```

Small nitpick.
created_at: 2025-05-14T18:56:52Z
author_association: MEMBER

PR comments:
user: login: Chapien
created_at: 2025-05-10T17:36:18Z
body: > Related #106229. The color-shape protocol allows us to not have to deal with cursor theming and instead depend on the compositor for it. This still does not quite solve the issue when the compositor doesn't implement the protocol (or running under the x11 backend) but for gnome/kde and a few more this should resolve things.
> 
> @Chapien On breeze I can get the normal pointer, text input and renames but can't quite remember where else to hover to get more cursors so how is this running for you?

I'll have to pull and build, as well as remove my theme override file + relog. Will let you know in a bit but if it's working for you I don't see why it would be different.
author_association: NONE
user: login: ArchercatNEO
created_at: 2025-05-10T17:37:54Z
body: As long as you have your cursor theme set to breeze in the system settings you shouldn't need to change any files
author_association: CONTRIBUTOR
user: login: Chapien
created_at: 2025-05-10T17:37:57Z
body: > > Related #106229. The color-shape protocol allows us to not have to deal with cursor theming and instead depend on the compositor for it. This still does not quite solve the issue when the compositor doesn't implement the protocol (or running under the x11 backend) but for gnome/kde and a few more this should resolve things.
> > @Chapien On breeze I can get the normal pointer, text input and renames but can't quite remember where else to hover to get more cursors so how is this running for you?
> 
> I'll have to pull and build, as well as remove my theme override file + relog. Will let you know in a bit but if it's working for you I don't see why it would be different.

Actually I don't have to relog, removing my theme file was enough to cause the bug to return on my main build. Going to pull now.
author_association: NONE
user: login: Chapien
created_at: 2025-05-10T17:39:09Z
body: > As long as you have your cursor theme set to breeze in the system settings you shouldn't need to change any files

I more meant to make sure it's not my workaround fix that's fixing it on my end ^^
author_association: NONE
user: login: Chapien
created_at: 2025-05-10T19:33:30Z
body: I can't get godot building, I think the way cstdin is included on Fedora means I have to tweak some build settings. That said I'm almost positive your fix works.

Also -- I asked the KDE people, and got this response
> Note that for Wayland, there's https://wayland.app/protocols/cursor-shape-v1. However, my understanding is that this protocol is only for setting cursors, not for querying them. Which shouldn't be too big an issue if Godot relies on the compositor to draw the (standard) cursor instead of trying to do everything by itself.

It seems you can't really query the theme reliably. 
author_association: NONE
user: login: ArchercatNEO
created_at: 2025-05-11T16:52:21Z
body: The wayland enum values are just the CSS pointers so I synced them to what the Web DisplayServer says the mapping from godot to css is.
author_association: CONTRIBUTOR
user: login: ArchercatNEO
created_at: 2025-05-14T16:44:27Z
body: @Riteo I implemented the changes you suggested not just the CSS sync thing, have you just been busy these couple days?
author_association: CONTRIBUTOR
user: login: deralmas
created_at: 2025-05-14T17:30:36Z
body: Hi @ArchercatNEO, sorry for the delay. I got a bit burnt out while crunching game embedding (I really wanted to get it out of the way) and now I'm trying to focus on myself to recover.

Code looks good, I was just waiting to find a good chance to test the feature thoroughly.
author_association: MEMBER
user: login: ArchercatNEO
created_at: 2025-05-14T18:00:41Z
body: I see, thank you. I just got worried when you thumbs upped the part about CSS sync that maybe you though only that happened? Fairly paranoid but no worries, take the time to recover.
author_association: CONTRIBUTOR
user: login: deralmas
created_at: 2025-05-14T18:59:01Z
body: BTW I just finished the little test jig that I was making a few days ago and I can say that it works fine in all cases!

Thank you for your work, I really appreciate the extra comments :D
author_association: MEMBER
user: login: ArchercatNEO
created_at: 2025-05-15T14:43:30Z
body: Fixed the grammar, hopefully it's all good now
author_association: CONTRIBUTOR
user: login: Repiteo
created_at: 2025-05-16T15:32:22Z
body: Thanks!
author_association: CONTRIBUTOR
user: login: IntangibleMatter
created_at: 2026-01-05T06:09:59Z
body: I'm looking through all the things mentioning "Cursor" and "Wayland" in Godot right now and I just wanted to mention that my cursor doesn't shape at all. (I'm on Godot 4.5.1 and using the Cosmic desktop environment)
author_association: CONTRIBUTOR
user: login: Zireael07
created_at: 2026-01-05T08:05:21Z
body: @IntangibleMatter Please make a separate issue, this is an old PR long since merged
author_association: CONTRIBUTOR