diff options
author | Tudor Brindus <me@tbrindus.ca> | 2020-05-29 23:33:03 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2020-05-30 02:16:15 -0400 |
commit | 83866558d37d8a16d88090df59b27365cf73490a (patch) | |
tree | 7bfe5738dd3d3b6d2953dd1aa01590008f2daf4e | |
parent | 0cbd26f0dae32db38160a82d557017edab8bb632 (diff) |
tree/container: refactor `tiling_container_at` to check bounds
This fixes bugs where a floating container would take input way past its
borders when its parent was fullscreen, since the call to
`tiling_container_at` in input/cursor.c's `node_at_coords` did not check
bounds.
-rw-r--r-- | sway/tree/container.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index d6c9a945..3e99aa75 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -274,14 +274,10 @@ static struct sway_container *container_at_linear(struct sway_node *parent, list_t *children = node_get_children(parent); for (int i = 0; i < children->length; ++i) { struct sway_container *child = children->items[i]; - struct wlr_box box = { - .x = child->x, - .y = child->y, - .width = child->width, - .height = child->height, - }; - if (wlr_box_contains_point(&box, lx, ly)) { - return tiling_container_at(&child->node, lx, ly, surface, sx, sy); + struct sway_container *container = + tiling_container_at(&child->node, lx, ly, surface, sx, sy); + if (container) { + return container; } } return NULL; @@ -303,15 +299,10 @@ static struct sway_container *floating_container_at(double lx, double ly, // reverse. for (int k = ws->floating->length - 1; k >= 0; --k) { struct sway_container *floater = ws->floating->items[k]; - struct wlr_box box = { - .x = floater->x, - .y = floater->y, - .width = floater->width, - .height = floater->height, - }; - if (wlr_box_contains_point(&box, lx, ly)) { - return tiling_container_at(&floater->node, lx, ly, - surface, sx, sy); + struct sway_container *container = + tiling_container_at(&floater->node, lx, ly, surface, sx, sy); + if (container) { + return container; } } } @@ -319,12 +310,34 @@ static struct sway_container *floating_container_at(double lx, double ly, return NULL; } +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")) { + return NULL; + } + + struct sway_container *container = parent->sway_container; + struct wlr_box box = { + .x = container->x, + .y = container->y, + .width = container->width, + .height = container->height, + }; + + if (wlr_box_contains_point(&box, lx, ly)) { + surface_at_view(parent->sway_container, lx, ly, surface, sx, sy); + return container; + } + + return NULL; +} + struct sway_container *tiling_container_at(struct sway_node *parent, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (node_is_view(parent)) { - surface_at_view(parent->sway_container, lx, ly, surface, sx, sy); - return parent->sway_container; + return view_container_at(parent, lx, ly, surface, sx, sy); } if (!node_get_children(parent)) { return NULL; |