From 37d745b01d372bcef995894db0cb7500f3c30c3d Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Sat, 25 Jan 2025 21:45:54 +0100 Subject: [PATCH] cursor.c: use subsurface as reference for out-of-surface movement The protocol states that the wl_pointer motion coordinates must be relative to the focused surface (e.g. the surface that last received a wl_pointer enter event). Before this patch, the coordinates were relative to the toplevel surface instead, resulting in subsurface events having the wrong coordinates when pressing a button over a subsurface and moving the cursor outside of that subsurface. Fixes: #2542 --- src/input/cursor.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/input/cursor.c b/src/input/cursor.c index 5af3bd0e..fdaaa59c 100644 --- a/src/input/cursor.c +++ b/src/input/cursor.c @@ -455,9 +455,18 @@ process_cursor_motion_out_of_surface(struct server *server, assert(surface); int lx, ly; - if (view) { + if (node && wlr_subsurface_try_from_wlr_surface(surface)) { + wlr_scene_node_coords(node, &lx, &ly); + } else if (view) { lx = view->current.x; ly = view->current.y; + /* Take into account invisible xdg-shell CSD borders */ + if (view->type == LAB_XDG_SHELL_VIEW) { + struct wlr_box geo; + wlr_xdg_surface_get_geometry(xdg_surface_from_view(view), &geo); + lx -= geo.x; + ly -= geo.y; + } } else if (node && wlr_layer_surface_v1_try_from_wlr_surface(surface)) { wlr_scene_node_coords(node, &lx, &ly); #if HAVE_XWAYLAND @@ -471,13 +480,6 @@ process_cursor_motion_out_of_surface(struct server *server, *sx = server->seat.cursor->x - lx; *sy = server->seat.cursor->y - ly; - /* Take into account invisible xdg-shell CSD borders */ - if (view && view->type == LAB_XDG_SHELL_VIEW) { - struct wlr_box geo; - wlr_xdg_surface_get_geometry(xdg_surface_from_view(view), &geo); - *sx += geo.x; - *sy += geo.y; - } return true; }