From fc8e147e4a86c133633945c48f26a455e47a3324 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 25 Mar 2021 09:27:25 +0530 Subject: [PATCH] Fix mouse handling when using client side decorations The mouse co-ordinates used by glfw were all wrong. --- docs/changelog.rst | 2 ++ glfw/wl_init.c | 24 ++++++++++++------------ glfw/wl_platform.h | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 675f8a39b..fc9be69d1 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -146,6 +146,8 @@ To update |kitty|, :doc:`follow the instructions `. - Wayland: Add support for the text input protocol (:iss:`3410`) +- Wayland: Fix mouse handling when using client side decorations + - Add an option, :opt:`detect_urls` to control whether kitty will detect URLs when the mouse moves over them (:pull:`3118`) diff --git a/glfw/wl_init.c b/glfw/wl_init.c index 3903c6496..c978dd58a 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -173,6 +173,8 @@ static void setCursor(GLFWCursorShape shape, _GLFWwindow* window) _glfw.wl.cursorPreviousShape = shape; } +#define x window->wl.allCursorPosX +#define y window->wl.allCursorPosY static void pointerHandleMotion(void* data UNUSED, struct wl_pointer* pointer UNUSED, uint32_t time UNUSED, @@ -181,15 +183,14 @@ static void pointerHandleMotion(void* data UNUSED, { _GLFWwindow* window = _glfw.wl.pointerFocus; GLFWCursorShape cursorShape = GLFW_ARROW_CURSOR; - double x, y; if (!window) return; if (window->cursorMode == GLFW_CURSOR_DISABLED) return; - x = wl_fixed_to_double(sx); - y = wl_fixed_to_double(sy); + window->wl.allCursorPosX = wl_fixed_to_double(sx); + window->wl.allCursorPosY = wl_fixed_to_double(sy); switch (window->wl.decorations.focus) { @@ -252,7 +253,7 @@ static void pointerHandleButton(void* data UNUSED, case mainWindow: break; case topDecoration: - if (window->wl.cursorPosY < _GLFW_DECORATION_WIDTH) + if (y < _GLFW_DECORATION_WIDTH) edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP; else { @@ -261,21 +262,21 @@ static void pointerHandleButton(void* data UNUSED, } break; case leftDecoration: - if (window->wl.cursorPosY < _GLFW_DECORATION_WIDTH) + if (y < _GLFW_DECORATION_WIDTH) edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT; else edges = XDG_TOPLEVEL_RESIZE_EDGE_LEFT; break; case rightDecoration: - if (window->wl.cursorPosY < _GLFW_DECORATION_WIDTH) + if (y < _GLFW_DECORATION_WIDTH) edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT; else edges = XDG_TOPLEVEL_RESIZE_EDGE_RIGHT; break; case bottomDecoration: - if (window->wl.cursorPosX < _GLFW_DECORATION_WIDTH) + if (x < _GLFW_DECORATION_WIDTH) edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_LEFT; - else if (window->wl.cursorPosX > window->wl.width + _GLFW_DECORATION_WIDTH) + else if (x > window->wl.width + _GLFW_DECORATION_WIDTH) edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_RIGHT; else edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM; @@ -293,10 +294,7 @@ static void pointerHandleButton(void* data UNUSED, { if (window->wl.decorations.focus != mainWindow && window->wl.xdg.toplevel) { - xdg_toplevel_show_window_menu(window->wl.xdg.toplevel, - _glfw.wl.seat, serial, - (int32_t)window->wl.cursorPosX, - (int32_t)window->wl.cursorPosY); + xdg_toplevel_show_window_menu(window->wl.xdg.toplevel, _glfw.wl.seat, serial, (int32_t)x, (int32_t)y - _GLFW_DECORATION_TOP); return; } } @@ -318,6 +316,8 @@ static void pointerHandleButton(void* data UNUSED, : GLFW_RELEASE, _glfw.wl.xkb.states.modifiers); } +#undef x +#undef y static void pointerHandleAxis(void* data UNUSED, struct wl_pointer* pointer UNUSED, diff --git a/glfw/wl_platform.h b/glfw/wl_platform.h index 5b6ee79d4..f29da2564 100644 --- a/glfw/wl_platform.h +++ b/glfw/wl_platform.h @@ -132,7 +132,7 @@ typedef struct _GLFWwindowWayland } xdg; _GLFWcursor* currentCursor; - double cursorPosX, cursorPosY; + double cursorPosX, cursorPosY, allCursorPosX, allCursorPosY; char* title; char appId[256];