*/
#pragma once
-void tree_append_json(const char *filename, char **errormsg);
+void tree_append_json(Con *con, const char *filename, char **errormsg);
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);
return 1;
}
-void tree_append_json(const char *filename, char **errormsg) {
+void tree_append_json(Con *con, const char *filename, char **errormsg) {
FILE *f;
if ((f = fopen(filename, "r")) == NULL) {
LOG("Cannot open file \"%s\"\n", filename);
/* Allow multiple values, i.e. multiple nodes to attach */
yajl_config(hand, yajl_allow_multiple_values, true);
yajl_status stat;
- json_node = focused;
+ json_node = con;
to_focus = NULL;
parsing_swallows = false;
parsing_rect = false;
/* In case not all containers were restored, we need to fix the
* percentages, otherwise i3 will crash immediately when rendering the
* next time. */
- con_fix_percent(focused);
+ con_fix_percent(con);
setlocale(LC_NUMERIC, "");
#if YAJL_MAJOR >= 2
};
focused = croot;
- tree_append_json(globbed, NULL);
+ tree_append_json(focused, globbed, NULL);
printf("appended tree, using new root\n");
croot = TAILQ_FIRST(&(croot->nodes_head));