Con *old_parent = parent;
if (focused->type == CT_WORKSPACE)
return;
- bool level_changed = false;
while (con_orientation(parent) != orientation) {
DLOG("need to go one level further up\n");
/* If the current parent is an output, we are at a workspace
if (old_focused)
con_focus(old_focused);
- level_changed = true;
-
break;
}
parent = parent->parent;
- level_changed = true;
}
Con *current = TAILQ_FIRST(&(parent->focus_head));
assert(current != TAILQ_END(&(parent->focus_head)));
Con *next = current;
if (way == 'n') {
LOG("i would insert it after %p / %s\n", next, next->name);
- if (!level_changed) {
- next = TAILQ_NEXT(next, nodes);
- if (next == TAILQ_END(&(next->parent->nodes_head))) {
- LOG("cannot move further to the right\n");
- return;
- }
+ /* Have a look at the next container: If there is no next container or
+ * if it is a leaf node, we move the focused one left to it. However,
+ * for split containers, we descend into it. */
+ next = TAILQ_NEXT(next, nodes);
+ if (next == TAILQ_END(&(next->parent->nodes_head)) || con_is_leaf(next)) {
+ next = current;
+ } else {
/* if this is a split container, we need to go down */
while (!TAILQ_EMPTY(&(next->focus_head)))
next = TAILQ_FIRST(&(next->focus_head));
} else {
LOG("i would insert it before %p / %s\n", current, current->name);
bool gone_down = false;
- if (!level_changed) {
- next = TAILQ_PREV(next, nodes_head, nodes);
- if (next == TAILQ_END(&(next->parent->nodes_head))) {
- LOG("cannot move further\n");
- return;
- }
-
+ next = TAILQ_PREV(next, nodes_head, nodes);
+ if (next == TAILQ_END(&(next->parent->nodes_head)) || con_is_leaf(next)) {
+ next = current;
+ } else {
/* if this is a split container, we need to go down */
while (!TAILQ_EMPTY(&(next->focus_head))) {
gone_down = true;