summaryrefslogtreecommitdiffstats
path: root/platform/linuxbsd/wayland/display_server_wayland.cpp
diff options
context:
space:
mode:
authorRiteo <riteo@posteo.net>2024-09-13 18:59:38 +0200
committerRiteo <riteo@posteo.net>2024-09-13 19:08:53 +0200
commitc15cd3acc43b7b5012e41844c1715b84f6c7834c (patch)
treef9e876a12c4b7a5565e4e5fd2a698c2c67d512a4 /platform/linuxbsd/wayland/display_server_wayland.cpp
parent74de05a01c8716a42d4e3427f607d7bea76b35e5 (diff)
downloadredot-engine-c15cd3acc43b7b5012e41844c1715b84f6c7834c.tar.gz
Wayland: Simplify cursor code and fix custom cursors
Initially the WaylandThread cursor code was supposed to be as stateless as possible but, as time went on, this wasn't possible. This expectation made the resulting API quite convoluted, so this patch aims to simplify it substantially bot in terms of API surface and, most importantly, in terms of actual implementation complexity. This patch also fixes custom cursors since I accidentally changed the mmap flags to MAP_PRIVATE some time ago. This took me hours to notice.
Diffstat (limited to 'platform/linuxbsd/wayland/display_server_wayland.cpp')
-rw-r--r--platform/linuxbsd/wayland/display_server_wayland.cpp33
1 files changed, 7 insertions, 26 deletions
diff --git a/platform/linuxbsd/wayland/display_server_wayland.cpp b/platform/linuxbsd/wayland/display_server_wayland.cpp
index 2074d7228d..a36748efc1 100644
--- a/platform/linuxbsd/wayland/display_server_wayland.cpp
+++ b/platform/linuxbsd/wayland/display_server_wayland.cpp
@@ -327,15 +327,7 @@ void DisplayServerWayland::mouse_set_mode(MouseMode p_mode) {
bool show_cursor = (p_mode == MOUSE_MODE_VISIBLE || p_mode == MOUSE_MODE_CONFINED);
- if (show_cursor) {
- if (custom_cursors.has(cursor_shape)) {
- wayland_thread.cursor_set_custom_shape(cursor_shape);
- } else {
- wayland_thread.cursor_set_shape(cursor_shape);
- }
- } else {
- wayland_thread.cursor_hide();
- }
+ wayland_thread.cursor_set_visible(show_cursor);
WaylandThread::PointerConstraint constraint = WaylandThread::PointerConstraint::NONE;
@@ -993,11 +985,7 @@ void DisplayServerWayland::cursor_set_shape(CursorShape p_shape) {
return;
}
- if (custom_cursors.has(p_shape)) {
- wayland_thread.cursor_set_custom_shape(p_shape);
- } else {
- wayland_thread.cursor_set_shape(p_shape);
- }
+ wayland_thread.cursor_set_shape(p_shape);
}
DisplayServerWayland::CursorShape DisplayServerWayland::cursor_get_shape() const {
@@ -1009,18 +997,13 @@ DisplayServerWayland::CursorShape DisplayServerWayland::cursor_get_shape() const
void DisplayServerWayland::cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
MutexLock mutex_lock(wayland_thread.mutex);
- bool visible = (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED);
-
if (p_cursor.is_valid()) {
HashMap<CursorShape, CustomCursor>::Iterator cursor_c = custom_cursors.find(p_shape);
if (cursor_c) {
if (cursor_c->value.rid == p_cursor->get_rid() && cursor_c->value.hotspot == p_hotspot) {
// We have a cached cursor. Nice.
- if (visible) {
- wayland_thread.cursor_set_custom_shape(p_shape);
- }
-
+ wayland_thread.cursor_set_shape(p_shape);
return;
}
@@ -1039,20 +1022,18 @@ void DisplayServerWayland::cursor_set_custom_image(const Ref<Resource> &p_cursor
wayland_thread.cursor_shape_set_custom_image(p_shape, image, p_hotspot);
- if (visible) {
- wayland_thread.cursor_set_custom_shape(p_shape);
- }
+ wayland_thread.cursor_set_shape(p_shape);
} else {
// Clear cache and reset to default system cursor.
- if (cursor_shape == p_shape && visible) {
+ wayland_thread.cursor_shape_clear_custom_image(p_shape);
+
+ if (cursor_shape == p_shape) {
wayland_thread.cursor_set_shape(p_shape);
}
if (custom_cursors.has(p_shape)) {
custom_cursors.erase(p_shape);
}
-
- wayland_thread.cursor_shape_clear_custom_image(p_shape);
}
}