+ 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(parent, path, &errormsg);
+ if (errormsg != NULL) {
+ yerror(errormsg);
+ free(errormsg);
+ /* Note that we continue executing since tree_append_json() has
+ * side-effects — user-provided layouts can be partly valid, partly
+ * invalid, leading to half of the placeholder containers being
+ * created. */
+ } else {
+ ysuccess(true);
+ }
+
+ // XXX: This is a bit of a kludge. Theoretically, render_con(parent,
+ // false); should be enough, but when sending 'workspace 4; append_layout
+ // /tmp/foo.json', the needs_tree_render == true of the workspace command
+ // is not executed yet and will be batched with append_layout’s
+ // needs_tree_render after the parser finished. We should check if that is
+ // necessary at all.
+ render_con(croot, false);
+
+ restore_open_placeholder_windows(parent);