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
This commit is contained in:
Kenny Levinsen 2021-03-03 16:17:45 +01:00 committed by Simon Ser
parent 837605d68d
commit 2e06403548
1 changed files with 25 additions and 2 deletions

View File

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