sway

i3-compatible Wayland compositor
git clone https://git.awy.one/sway
Log | Files | Refs | README | LICENSE

commit 2e06403548fa5e940e01b810e538fd46d61c89c7
parent 837605d68dc6112682bce0f133e3ba0b4dcfd440
Author: Kenny Levinsen <kl@kl.wtf>
Date:   Wed,  3 Mar 2021 16:17:45 +0100

container: Add view_container_content_at

container_at checks if the position provided matches the currently
focused container with view_container_at as a fast path.

view_container_at checks using the main container geometry, which
includes the titlebar and border area. If a tabbed container is focused,
then positions over unfocused tabs are incorrectly reported as belonging
to the focused container, breaking focus on click.

Add view_container_content_at for use in the focused container fast path
which only tests container content area, and fall back to full workspace
scans for border and titlebar areas.

Closes: https://github.com/swaywm/sway/issues/6074

Diffstat:
Msway/tree/container.c | 27+++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/sway/tree/container.c b/sway/tree/container.c @@ -311,7 +311,30 @@ static struct sway_container *floating_container_at(double lx, double ly, return NULL; } -struct sway_container *view_container_at(struct sway_node *parent, +static struct sway_container *view_container_content_at(struct sway_node *parent, + double lx, double ly, + struct wlr_surface **surface, double *sx, double *sy) { + if (!sway_assert(node_is_view(parent), "Expected a view")) { + return NULL; + } + + struct sway_container *container = parent->sway_container; + struct wlr_box box = { + .x = container->pending.content_x, + .y = container->pending.content_y, + .width = container->pending.content_width, + .height = container->pending.content_height, + }; + + if (wlr_box_contains_point(&box, lx, ly)) { + surface_at_view(parent->sway_container, lx, ly, surface, sx, sy); + return container; + } + + return NULL; +} + +static struct sway_container *view_container_at(struct sway_node *parent, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (!sway_assert(node_is_view(parent), "Expected a view")) { @@ -395,7 +418,7 @@ struct sway_container *container_at(struct sway_workspace *workspace, } // Tiling (focused) if (focus && focus->view && !is_floating) { - if ((c = view_container_at(&focus->node, lx, ly, surface, sx, sy))) { + if ((c = view_container_content_at(&focus->node, lx, ly, surface, sx, sy))) { return c; } }