diff options
Diffstat (limited to 'sway/layout.c')
-rw-r--r-- | sway/layout.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sway/layout.c b/sway/layout.c index e628c5ed..37db2e52 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -298,3 +298,53 @@ swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) { | |||
298 | return NULL; | 298 | return NULL; |
299 | } | 299 | } |
300 | 300 | ||
301 | swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) { | ||
302 | swayc_t *parent = container->parent; | ||
303 | |||
304 | if (dir == MOVE_PARENT) { | ||
305 | if (parent->type == C_OUTPUT) { | ||
306 | return NULL; | ||
307 | } else { | ||
308 | return parent; | ||
309 | } | ||
310 | } | ||
311 | while (true) { | ||
312 | // Test if we can even make a difference here | ||
313 | bool can_move = false; | ||
314 | int diff = 0; | ||
315 | if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { | ||
316 | if (parent->layout == L_HORIZ || parent->type == C_ROOT) { | ||
317 | can_move = true; | ||
318 | diff = dir == MOVE_LEFT ? -1 : 1; | ||
319 | } | ||
320 | } else { | ||
321 | if (parent->layout == L_VERT) { | ||
322 | can_move = true; | ||
323 | diff = dir == MOVE_UP ? -1 : 1; | ||
324 | } | ||
325 | } | ||
326 | if (can_move) { | ||
327 | int i; | ||
328 | for (i = 0; i < parent->children->length; ++i) { | ||
329 | swayc_t *child = parent->children->items[i]; | ||
330 | if (child == container) { | ||
331 | break; | ||
332 | } | ||
333 | } | ||
334 | int desired = i + diff; | ||
335 | if (desired < 0 || desired >= parent->children->length) { | ||
336 | can_move = false; | ||
337 | } else { | ||
338 | return parent->children->items[desired]; | ||
339 | } | ||
340 | } | ||
341 | if (!can_move) { | ||
342 | container = parent; | ||
343 | parent = parent->parent; | ||
344 | if (!parent) { | ||
345 | // Nothing we can do | ||
346 | return NULL; | ||
347 | } | ||
348 | } | ||
349 | } | ||
350 | } | ||