aboutsummaryrefslogtreecommitdiff
path: root/sway/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/layout.c')
-rw-r--r--sway/layout.c50
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) {
return NULL;
}
+swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) {
+ swayc_t *parent = container->parent;
+
+ if (dir == MOVE_PARENT) {
+ if (parent->type == C_OUTPUT) {
+ return NULL;
+ } else {
+ return parent;
+ }
+ }
+ while (true) {
+ // Test if we can even make a difference here
+ bool can_move = false;
+ int diff = 0;
+ if (dir == MOVE_LEFT || dir == MOVE_RIGHT) {
+ if (parent->layout == L_HORIZ || parent->type == C_ROOT) {
+ can_move = true;
+ diff = dir == MOVE_LEFT ? -1 : 1;
+ }
+ } else {
+ if (parent->layout == L_VERT) {
+ can_move = true;
+ diff = dir == MOVE_UP ? -1 : 1;
+ }
+ }
+ if (can_move) {
+ int i;
+ for (i = 0; i < parent->children->length; ++i) {
+ swayc_t *child = parent->children->items[i];
+ if (child == container) {
+ break;
+ }
+ }
+ int desired = i + diff;
+ if (desired < 0 || desired >= parent->children->length) {
+ can_move = false;
+ } else {
+ return parent->children->items[desired];
+ }
+ }
+ if (!can_move) {
+ container = parent;
+ parent = parent->parent;
+ if (!parent) {
+ // Nothing we can do
+ return NULL;
+ }
+ }
+ }
+}