- /* easy case: the move is within this container */
- if (same_orientation == con->parent) {
- DLOG("We are in the same container\n");
- Con *swap;
- if (!(swap = (direction == TOK_LEFT || direction == TOK_UP ?
- TAILQ_PREV(con, nodes_head, nodes) :
- TAILQ_NEXT(con, nodes))))
- return;
-
- if (!con_is_leaf(swap)) {
- insert_con_into(con, con_descend_focused(swap), AFTER);
- goto end;
+ /* easy case: the move is within this container */
+ if (same_orientation == con->parent) {
+ DLOG("We are in the same container\n");
+ Con *swap;
+ if ((swap = (direction == TOK_LEFT || direction == TOK_UP ?
+ TAILQ_PREV(con, nodes_head, nodes) :
+ TAILQ_NEXT(con, nodes)))) {
+ if (!con_is_leaf(swap)) {
+ insert_con_into(con, con_descend_focused(swap), AFTER);
+ goto end;
+ }
+ if (direction == TOK_LEFT || direction == TOK_UP)
+ TAILQ_SWAP(swap, con, &(swap->parent->nodes_head), nodes);
+ else TAILQ_SWAP(con, swap, &(swap->parent->nodes_head), nodes);
+
+ TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
+ TAILQ_INSERT_HEAD(&(swap->parent->focus_head), con, focused);
+
+ DLOG("Swapped.\n");
+ return;
+ }
+
+ /* If there was no con with which we could swap the current one, search
+ * again, but starting one level higher. If we are on the workspace
+ * level, don’t do that. The result would be a force change of
+ * workspace orientation, which is not necessary. */
+ if (con->parent == con_get_workspace(con))
+ return;
+ same_orientation = con_parent_with_orientation(con->parent, o);