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
This commit is contained in:
Consolatis 2025-01-25 21:45:54 +01:00
parent 26064fb8f6
commit 37d745b01d

View file

@ -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;
}