From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Waris Boonyasiriwat Date: Wed, 12 May 2021 00:30:14 -0700 Subject: Wayland: Fix cursor offset when shape changes The Wayland protocol spec[1] states that set_cursor must be called with the serial number of the enter event. However, GLFW is passing in the serial number of the latest received event, which does not meet the protocol spec. [1] https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_pointer As a result, set_cursor calls were simply ignored by the compositor. This fix complies with the protocol more closely by specifically caching the enter event serial, and using it for all set_cursor calls. Fixes #1706 Closes #1899 --- src/wl_init.c | 3 ++- src/wl_platform.h | 1 + src/wl_window.c | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wl_init.c b/src/wl_init.c index f43a0f82..cc355136 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -130,6 +130,7 @@ static void pointerHandleEnter(void* data, #endif _glfw.wl.serial = serial; + _glfw.wl.pointerEnterSerial = serial; _glfw.wl.pointerFocus = window; window->wl.hovered = GLFW_TRUE; @@ -189,7 +190,7 @@ static void setCursor(_GLFWwindow* window, const char* name) buffer = wl_cursor_image_get_buffer(image); if (!buffer) return; - wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.serial, + wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.pointerEnterSerial, surface, image->hotspot_x / scale, image->hotspot_y / scale); diff --git a/src/wl_platform.h b/src/wl_platform.h index b6b3392e..18dbd60a 100644 --- a/src/wl_platform.h +++ b/src/wl_platform.h @@ -262,6 +262,7 @@ typedef struct _GLFWlibraryWayland const char* cursorPreviousName; int cursorTimerfd; uint32_t serial; + uint32_t pointerEnterSerial; int32_t keyboardRepeatRate; int32_t keyboardRepeatDelay; diff --git a/src/wl_window.c b/src/wl_window.c index ddf5ad37..23762e08 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -767,7 +767,7 @@ static void setCursorImage(_GLFWwindow* window, cursorWayland->yhot = image->hotspot_y; } - wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.serial, + wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.pointerEnterSerial, surface, cursorWayland->xhot / scale, cursorWayland->yhot / scale); @@ -1598,7 +1598,7 @@ static void lockPointer(_GLFWwindow* window) window->wl.pointerLock.relativePointer = relativePointer; window->wl.pointerLock.lockedPointer = lockedPointer; - wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.serial, + wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.pointerEnterSerial, NULL, 0, 0); } @@ -1666,7 +1666,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) } else if (window->cursorMode == GLFW_CURSOR_HIDDEN) { - wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.serial, NULL, 0, 0); + wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.pointerEnterSerial, NULL, 0, 0); } }