From 269bbbe8b1dfc6ac8236a592e00cbbdda3fc1bbc Mon Sep 17 00:00:00 2001 From: IoIxD Date: Sat, 26 Sep 2026 13:38:35 -0700 Subject: [PATCH] wayland: proper hit testing that doesn't penetrate through widgets --- src/backend/wayland/interfaces.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/backend/wayland/interfaces.c b/src/backend/wayland/interfaces.c index ea4269f5..2740c6f3 100644 --- a/src/backend/wayland/interfaces.c +++ b/src/backend/wayland/interfaces.c @@ -754,14 +754,34 @@ static MwBool hit_detect(MwLL child, MwLL* _topmost_parent, MwPoint* _point, MwP point.y >= absolute_pos.y && point.y <= absolute_pos.y + child->wayland.wh; } +/* deepest, topmost-z sublevel under the pointer, or self if none */ +static MwLL find_target(MwLL self, MwPoint* local) { + MwLL* children = MwLLWaylandSublevelsByZIndex(self); + MwLL target = self; + int i; + for(i = arrlen(children) - 1; i >= 0; i--) { + MwLL tp; + MwPoint pt, rel, abs; + if(hit_detect(children[i], &tp, &pt, &rel, &abs)) { + *local = rel; + target = find_target(children[i], local); + break; + } + } + arrfree(children); + return target; +} + static void mouse_dispatch(MwLL self, MwMouse p, MwU32 state) { + MwLL target = find_target(self, &p.point); + switch(state) { case WL_POINTER_BUTTON_STATE_PRESSED: - MwLLDispatch(self, down, &p); + MwLLDispatch(target, down, &p); break; case WL_POINTER_BUTTON_STATE_RELEASED: - MwLLDispatch(self, up, &p); - break; + MwLLDispatch(target, up, &p); + return; } { @@ -797,7 +817,6 @@ static void mouse_dispatch(MwLL self, MwMouse p, MwU32 state) { break; } - printf("%d\n", child->wayland.parent->wayland.type); mouse_dispatch(child, p, state); break; }