aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
authorLibravatar Tudor Brindus <me@tbrindus.ca>2020-05-29 23:33:03 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2020-05-30 02:16:15 -0400
commit83866558d37d8a16d88090df59b27365cf73490a (patch)
tree7bfe5738dd3d3b6d2953dd1aa01590008f2daf4e /sway/tree/container.c
parentAdd views idle inhibition status in get_tree output (diff)
downloadsway-83866558d37d8a16d88090df59b27365cf73490a.tar.gz
sway-83866558d37d8a16d88090df59b27365cf73490a.tar.zst
sway-83866558d37d8a16d88090df59b27365cf73490a.zip
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.
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c51
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,
274 list_t *children = node_get_children(parent); 274 list_t *children = node_get_children(parent);
275 for (int i = 0; i < children->length; ++i) { 275 for (int i = 0; i < children->length; ++i) {
276 struct sway_container *child = children->items[i]; 276 struct sway_container *child = children->items[i];
277 struct wlr_box box = { 277 struct sway_container *container =
278 .x = child->x, 278 tiling_container_at(&child->node, lx, ly, surface, sx, sy);
279 .y = child->y, 279 if (container) {
280 .width = child->width, 280 return container;
281 .height = child->height,
282 };
283 if (wlr_box_contains_point(&box, lx, ly)) {
284 return tiling_container_at(&child->node, lx, ly, surface, sx, sy);
285 } 281 }
286 } 282 }
287 return NULL; 283 return NULL;
@@ -303,15 +299,10 @@ static struct sway_container *floating_container_at(double lx, double ly,
303 // reverse. 299 // reverse.
304 for (int k = ws->floating->length - 1; k >= 0; --k) { 300 for (int k = ws->floating->length - 1; k >= 0; --k) {
305 struct sway_container *floater = ws->floating->items[k]; 301 struct sway_container *floater = ws->floating->items[k];
306 struct wlr_box box = { 302 struct sway_container *container =
307 .x = floater->x, 303 tiling_container_at(&floater->node, lx, ly, surface, sx, sy);
308 .y = floater->y, 304 if (container) {
309 .width = floater->width, 305 return container;
310 .height = floater->height,
311 };
312 if (wlr_box_contains_point(&box, lx, ly)) {
313 return tiling_container_at(&floater->node, lx, ly,
314 surface, sx, sy);
315 } 306 }
316 } 307 }
317 } 308 }
@@ -319,12 +310,34 @@ static struct sway_container *floating_container_at(double lx, double ly,
319 return NULL; 310 return NULL;
320} 311}
321 312
313struct sway_container *view_container_at(struct sway_node *parent,
314 double lx, double ly,
315 struct wlr_surface **surface, double *sx, double *sy) {
316 if (!sway_assert(node_is_view(parent), "Expected a view")) {
317 return NULL;
318 }
319
320 struct sway_container *container = parent->sway_container;
321 struct wlr_box box = {
322 .x = container->x,
323 .y = container->y,
324 .width = container->width,
325 .height = container->height,
326 };
327
328 if (wlr_box_contains_point(&box, lx, ly)) {
329 surface_at_view(parent->sway_container, lx, ly, surface, sx, sy);
330 return container;
331 }
332
333 return NULL;
334}
335
322struct sway_container *tiling_container_at(struct sway_node *parent, 336struct sway_container *tiling_container_at(struct sway_node *parent,
323 double lx, double ly, 337 double lx, double ly,
324 struct wlr_surface **surface, double *sx, double *sy) { 338 struct wlr_surface **surface, double *sx, double *sy) {
325 if (node_is_view(parent)) { 339 if (node_is_view(parent)) {
326 surface_at_view(parent->sway_container, lx, ly, surface, sx, sy); 340 return view_container_at(parent, lx, ly, surface, sx, sy);
327 return parent->sway_container;
328 } 341 }
329 if (!node_get_children(parent)) { 342 if (!node_get_children(parent)) {
330 return NULL; 343 return NULL;