From 3bab222aa7657036ae64e0a1da6cd626bcaceb3d Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 28 Nov 2010 01:51:16 +0100 Subject: [PATCH] Bugfix: Re-attach windows in correct order when switching layout (Thanks fernandotcl) --- include/con.h | 6 +++++- src/con.c | 28 +++++++++++++++++----------- src/tree.c | 4 ++-- src/workspace.c | 2 +- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/include/con.h b/include/con.h index 9194b0e0..736b526c 100644 --- a/include/con.h +++ b/include/con.h @@ -86,8 +86,12 @@ int con_num_children(Con *con); * a container or when inserting a new container at a specific place in the * tree. * + * ignore_focus is to just insert the Con at the end (useful when creating a + * new split container *around* some containers, that is, detaching and + * attaching them in order without wanting to mess with the focus in between). + * */ -void con_attach(Con *con, Con *parent); +void con_attach(Con *con, Con *parent, bool ignore_focus); /** * Detaches the given container from its current parent diff --git a/src/con.c b/src/con.c index e86f668c..80f69a6e 100644 --- a/src/con.c +++ b/src/con.c @@ -57,7 +57,7 @@ Con *con_new(Con *parent) { TAILQ_INIT(&(new->swallow_head)); if (parent != NULL) - con_attach(new, parent); + con_attach(new, parent, false); return new; } @@ -67,8 +67,12 @@ Con *con_new(Con *parent) { * a container or when inserting a new container at a specific place in the * tree. * + * ignore_focus is to just insert the Con at the end (useful when creating a + * new split container *around* some containers, that is, detaching and + * attaching them in order without wanting to mess with the focus in between). + * */ -void con_attach(Con *con, Con *parent) { +void con_attach(Con *con, Con *parent, bool ignore_focus) { con->parent = parent; Con *loop; Con *current = NULL; @@ -102,12 +106,14 @@ void con_attach(Con *con, Con *parent) { goto add_to_focus_head; } - /* Get the first tiling container in focus stack */ - TAILQ_FOREACH(loop, &(parent->focus_head), focused) { - if (loop->type == CT_FLOATING_CON) - continue; - current = loop; - break; + if (!ignore_focus) { + /* Get the first tiling container in focus stack */ + TAILQ_FOREACH(loop, &(parent->focus_head), focused) { + if (loop->type == CT_FLOATING_CON) + continue; + current = loop; + break; + } } /* Insert the container after the tiling container, if found */ @@ -428,7 +434,7 @@ void con_move_to_workspace(Con *con, Con *workspace) { DLOG("Re-attaching container to %p / %s\n", next, next->name); /* 4: re-attach the con to the parent of this focused container */ con_detach(con); - con_attach(con, next); + con_attach(con, next, false); /* 5: keep focus on the current workspace */ con_focus(focus_next); @@ -577,12 +583,12 @@ void con_set_layout(Con *con, int layout) { while (!TAILQ_EMPTY(&(con->nodes_head))) { child = TAILQ_FIRST(&(con->nodes_head)); con_detach(child); - con_attach(child, new); + con_attach(child, new, true); } /* 4: attach the new split container to the workspace */ DLOG("Attaching new split to ws\n"); - con_attach(new, con); + con_attach(new, con, false); if (old_focused) con_focus(old_focused); diff --git a/src/tree.c b/src/tree.c index 75f8c7cb..15799254 100644 --- a/src/tree.c +++ b/src/tree.c @@ -86,7 +86,7 @@ void tree_init() { ws->num = c; asprintf(&(ws->name), "%d", c); c++; - con_attach(ws, oc); + con_attach(ws, oc, false); asprintf(&name, "[i3 con] workspace %s", ws->name); x_set_name(ws, name); @@ -269,7 +269,7 @@ void tree_split(Con *con, orientation_t orientation) { new->orientation = orientation; /* 3: add it as a child to the new Con */ - con_attach(con, new); + con_attach(con, new, false); } /* diff --git a/src/workspace.c b/src/workspace.c index 837ac1fe..a1d3659d 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -59,7 +59,7 @@ Con *workspace_get(const char *num) { else workspace->num = parsed_num; LOG("num = %d\n", workspace->num); workspace->orientation = HORIZ; - con_attach(workspace, output); + con_attach(workspace, output, false); ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}"); } -- 2.39.5