X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Ftree.c;h=fc9526e6d196e65a01016c9a500e6ec0b079eec1;hb=50edf495aa3971bfb67471c3aaf2eb72e7abd443;hp=5642c5c78f360148612af684bc1861e236fc9ed2;hpb=bc126aaeafa2c5f18dadd8cb0d7e57329c722273;p=i3%2Fi3 diff --git a/src/tree.c b/src/tree.c index 5642c5c7..fc9526e6 100644 --- a/src/tree.c +++ b/src/tree.c @@ -1,5 +1,3 @@ -#undef I3__FILE__ -#define I3__FILE__ "tree.c" /* * vim:ts=4:sw=4:expandtab * @@ -66,12 +64,19 @@ static Con *_create___i3(void) { * */ bool tree_restore(const char *path, xcb_get_geometry_reply_t *geometry) { + bool result = false; char *globbed = resolve_tilde(path); + char *buf = NULL; if (!path_exists(globbed)) { LOG("%s does not exist, not restoring tree\n", globbed); - free(globbed); - return false; + goto out; + } + + ssize_t len; + if ((len = slurp(globbed, &buf)) < 0) { + /* slurp already logged an error. */ + goto out; } /* TODO: refactor the following */ @@ -83,7 +88,7 @@ bool tree_restore(const char *path, xcb_get_geometry_reply_t *geometry) { geometry->height}; focused = croot; - tree_append_json(focused, globbed, NULL); + tree_append_json(focused, buf, len, NULL); DLOG("appended tree, using new root\n"); croot = TAILQ_FIRST(&(croot->nodes_head)); @@ -105,8 +110,12 @@ bool tree_restore(const char *path, xcb_get_geometry_reply_t *geometry) { } restore_open_placeholder_windows(croot); + result = true; - return true; +out: + free(globbed); + free(buf); + return result; } /* @@ -265,11 +274,8 @@ bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_par add_ignore_event(cookie.sequence, 0); } ipc_send_window_event("close", con); - FREE(con->window->class_class); - FREE(con->window->class_instance); - i3string_free(con->window->name); - FREE(con->window->ran_assignments); - FREE(con->window); + window_free(con->window); + con->window = NULL; } Con *ws = con_get_workspace(con); @@ -324,10 +330,7 @@ bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_par DLOG("parent container killed\n"); } - free(con->name); - FREE(con->deco_render_params); - TAILQ_REMOVE(&all_cons, con, all_cons); - free(con); + con_free(con); /* in the case of floating windows, we already focused another container * when closing the parent, so we can exit now. */ @@ -375,7 +378,11 @@ void tree_split(Con *con, orientation_t orientation) { if (con->type == CT_WORKSPACE) { if (con_num_children(con) < 2) { - DLOG("Just changing orientation of workspace\n"); + if (con_num_children(con) == 0) { + DLOG("Changing workspace_layout to L_DEFAULT\n"); + con->workspace_layout = L_DEFAULT; + } + DLOG("Changing orientation of workspace\n"); con->layout = (orientation == HORIZ) ? L_SPLITH : L_SPLITV; return; } else { @@ -473,7 +480,7 @@ static void mark_unmapped(Con *con) { TAILQ_FOREACH(current, &(con->nodes_head), nodes) mark_unmapped(current); if (con->type == CT_WORKSPACE) { - /* We need to call mark_unmapped on floating nodes aswell since we can + /* We need to call mark_unmapped on floating nodes as well since we can * make containers floating. */ TAILQ_FOREACH(current, &(con->floating_head), floating_windows) mark_unmapped(current); @@ -525,7 +532,7 @@ static bool _tree_next(Con *con, char way, orientation_t orientation, bool wrap) if (!current_output) return false; - DLOG("Current output is %s\n", current_output->name); + DLOG("Current output is %s\n", output_primary_name(current_output)); /* Try to find next output */ direction_t direction; @@ -543,7 +550,7 @@ static bool _tree_next(Con *con, char way, orientation_t orientation, bool wrap) next_output = get_output_next(direction, current_output, CLOSEST_OUTPUT); if (!next_output) return false; - DLOG("Next output is %s\n", next_output->name); + DLOG("Next output is %s\n", output_primary_name(next_output)); /* Find visible workspace on next output */ Con *workspace = NULL; @@ -634,7 +641,7 @@ static bool _tree_next(Con *con, char way, orientation_t orientation, bool wrap) next = TAILQ_PREV(current, nodes_head, nodes); if (!next) { - if (!config.force_focus_wrapping) { + if (config.focus_wrapping != FOCUS_WRAPPING_FORCE) { /* If there is no next/previous container, we check if we can focus one * when going higher (without wrapping, though). If so, we are done, if * not, we wrap */ @@ -668,7 +675,8 @@ static bool _tree_next(Con *con, char way, orientation_t orientation, bool wrap) * */ void tree_next(char way, orientation_t orientation) { - _tree_next(focused, way, orientation, true); + _tree_next(focused, way, orientation, + config.focus_wrapping != FOCUS_WRAPPING_OFF); } /*