layout restoring: append at the nearest split container (or workspace) (Thanks chris)

Before this commit, leaf containers (such as terminal emulators) would
get children appended, which is not intended.

fixes #1223
This commit is contained in:
Michael Stapelberg
2014-04-18 20:30:27 +02:00
parent 702906d0cf
commit 524f20b8a0
4 changed files with 14 additions and 6 deletions

View File

@ -877,8 +877,16 @@ void cmd_nop(I3_CMD, char *comment) {
void cmd_append_layout(I3_CMD, char *path) {
LOG("Appending layout \"%s\"\n", path);
Con *parent = focused;
/* We need to append the layout to a split container, since a leaf
* container must not have any children (by definition).
* Note that we explicitly check for workspaces, since they are okay for
* this purpose, but con_accepts_window() returns false for workspaces. */
while (parent->type != CT_WORKSPACE && !con_accepts_window(parent))
parent = parent->parent;
DLOG("Appending to parent=%p instead of focused=%p\n",
parent, focused);
char *errormsg = NULL;
tree_append_json(path, &errormsg);
tree_append_json(parent, path, &errormsg);
if (errormsg != NULL) {
yerror(errormsg);
free(errormsg);