From d6eff8fa705aeca6e29d1ddf87560253ba8df5ad Mon Sep 17 00:00:00 2001 From: Naveen Karuthedath <1267337+envyen@users.noreply.github.com> Date: Wed, 20 Dec 2023 19:10:16 +0530 Subject: [PATCH] Add for Wayland Drag wl_pointer.leave and hold buttons behaviour Review changes suggested by @Seneral --- src/wl_window.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/wl_window.c b/src/wl_window.c index 9c03618c..41e718fd 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1312,6 +1312,14 @@ static void pointerHandleLeave(void* userData, _glfw.wl.pointerFocus = NULL; _glfw.wl.cursorPreviousName = NULL; _glfwInputCursorEnter(window, GLFW_FALSE); + + // Would like to silently set mouse button state to undefined without triggering a mouse button release event + // See https://gitlab.freedesktop.org/wayland/wayland/-/issues/280 + // But many underlying systems will keep their own state and only use GLFW events to keep it up to date + // So realistically, they NEED a mouse button event, even if wayland spec would like it to be implicitly undefined + for (int btn = 0; btn < GLFW_MOUSE_BUTTON_LAST+1; btn++) + if (window->mouseButtons[btn] != GLFW_RELEASE) + _glfwInputMouseClick(window, btn, GLFW_RELEASE, 0); } static void pointerHandleMotion(void* userData, @@ -1661,6 +1669,14 @@ static void keyboardHandleLeave(void* userData, _glfw.wl.serial = serial; _glfw.wl.keyboardFocus = NULL; _glfwInputWindowFocus(window, GLFW_FALSE); + + // Would like to silently set key state to undefined without triggering a key release event + // See https://gitlab.freedesktop.org/wayland/wayland/-/issues/280 + // But many underlying systems will keep their own state and only use GLFW events to keep it up to date + // So realistically, they NEED a key event, even if wayland spec would like it to be implicitly undefined + for (int key = 0; key < GLFW_KEY_LAST+1; key++) + if (window->keys[key] != GLFW_RELEASE) + _glfwInputKey(window, key, _glfwGetKeyScancodeWayland(key), GLFW_RELEASE, 0); } static void keyboardHandleKey(void* userData, @@ -2365,7 +2381,7 @@ void _glfwFocusWindowWayland(_GLFWwindow* window) void _glfwDragWindowWayland(_GLFWwindow* window) { - xdg_toplevel_move(window->wl.xdg.toplevel, _glfw.wl.seat, _glfw.wl.pointerEnterSerial); + xdg_toplevel_move(window->wl.xdg.toplevel, _glfw.wl.seat, _glfw.wl.serial); } void _glfwSetWindowMonitorWayland(_GLFWwindow* window,