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:
parent
702906d0cf
commit
524f20b8a0
|
@ -10,4 +10,4 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
void tree_append_json(const char *filename, char **errormsg);
|
||||
void tree_append_json(Con *con, const char *filename, char **errormsg);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -395,7 +395,7 @@ static int json_double(void *ctx, double val) {
|
|||
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);
|
||||
|
@ -439,7 +439,7 @@ void tree_append_json(const char *filename, char **errormsg) {
|
|||
/* 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;
|
||||
|
@ -460,7 +460,7 @@ void tree_append_json(const char *filename, char **errormsg) {
|
|||
/* 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
|
||||
|
|
|
@ -84,7 +84,7 @@ bool tree_restore(const char *path, xcb_get_geometry_reply_t *geometry) {
|
|||
};
|
||||
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));
|
||||
|
|
Loading…
Reference in New Issue