From: Deiz Date: Wed, 3 Oct 2012 17:10:48 +0000 (-0400) Subject: Replace the discrete 'split' Con property with a simple function. X-Git-Tag: 4.4~81 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fdcba7b91aed15f43d4fb44c7083eed92549fb3a;p=i3%2Fi3 Replace the discrete 'split' Con property with a simple function. --- diff --git a/include/con.h b/include/con.h index 5bf82487..8b9ae9c7 100644 --- a/include/con.h +++ b/include/con.h @@ -33,6 +33,12 @@ void con_focus(Con *con); */ bool con_is_leaf(Con *con); +/* + * Returns true if a container should be considered split. + * + */ +bool con_is_split(Con *con); + /** * Returns true if this node accepts a window (if the node swallows windows, * it might already have swallowed enough and cannot hold any more). diff --git a/include/data.h b/include/data.h index 3cf22f61..810709cd 100644 --- a/include/data.h +++ b/include/data.h @@ -440,8 +440,6 @@ struct Assignment { */ struct Con { bool mapped; - /** whether this is a split container or not */ - bool split; enum { CT_ROOT = 0, CT_OUTPUT = 1, diff --git a/src/con.c b/src/con.c index 1389bf53..d872858b 100644 --- a/src/con.c +++ b/src/con.c @@ -36,7 +36,7 @@ static void con_force_split_parents_redraw(Con *con) { Con *parent = con; while (parent && parent->type != CT_WORKSPACE && parent->type != CT_DOCKAREA) { - if (parent->split) + if (!con_is_leaf(parent)) FREE(parent->deco_render_params); parent = parent->parent; } @@ -232,6 +232,24 @@ bool con_is_leaf(Con *con) { return TAILQ_EMPTY(&(con->nodes_head)); } +/* + * Returns true if a container should be considered split. + * + */ +bool con_is_split(Con *con) { + if (con_is_leaf(con)) + return false; + + switch (con->layout) { + case L_DOCKAREA: + case L_OUTPUT: + return false; + + default: + return true; + } +} + /* * Returns true if this node accepts a window (if the node swallows windows, * it might already have swallowed enough and cannot hold any more). @@ -242,7 +260,7 @@ bool con_accepts_window(Con *con) { if (con->type == CT_WORKSPACE) return false; - if (con->split) { + if (con_is_split(con)) { DLOG("container %p does not accept windows, it is a split container.\n", con); return false; } @@ -1163,7 +1181,6 @@ void con_set_layout(Con *con, int layout) { * split. */ new->layout = layout; new->last_split_layout = con->last_split_layout; - new->split = true; Con *old_focused = TAILQ_FIRST(&(con->focus_head)); if (old_focused == TAILQ_END(&(con->focus_head))) @@ -1336,7 +1353,7 @@ Rect con_minimum_size(Con *con) { /* For horizontal/vertical split containers we sum up the width (h-split) * or height (v-split) and use the maximum of the height (h-split) or width * (v-split) as minimum size. */ - if (con->split) { + if (con_is_split(con)) { uint32_t width = 0, height = 0; Con *child; TAILQ_FOREACH(child, &(con->nodes_head), nodes) { @@ -1354,7 +1371,7 @@ Rect con_minimum_size(Con *con) { } ELOG("Unhandled case, type = %d, layout = %d, split = %d\n", - con->type, con->layout, con->split); + con->type, con->layout, con_is_split(con)); assert(false); } diff --git a/src/floating.c b/src/floating.c index 17fe74cc..b884a182 100644 --- a/src/floating.c +++ b/src/floating.c @@ -99,7 +99,6 @@ void floating_enable(Con *con, bool automatic) { * otherwise. */ Con *ws = con_get_workspace(con); nc->parent = ws; - nc->split = true; nc->type = CT_FLOATING_CON; nc->layout = L_SPLITH; /* We insert nc already, even though its rect is not yet calculated. This diff --git a/src/ipc.c b/src/ipc.c index 84ef2c36..5232acf2 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -165,7 +165,7 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) { /* provided for backwards compatibility only. */ ystr("orientation"); - if (!con->split) + if (!con_is_split(con)) ystr("none"); else { if (con_orientation(con) == HORIZ) @@ -202,9 +202,6 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) { ystr("focused"); y(bool, (con == focused)); - ystr("split"); - y(bool, con->split); - ystr("layout"); switch (con->layout) { case L_DEFAULT: diff --git a/src/load_layout.c b/src/load_layout.c index d5735885..ca4c87ef 100644 --- a/src/load_layout.c +++ b/src/load_layout.c @@ -172,11 +172,6 @@ static int json_string(void *ctx, const unsigned char *val, unsigned int len) { else if (strcasecmp(buf, "vertical") == 0) json_node->last_split_layout = L_SPLITV; else LOG("Unhandled orientation: %s\n", buf); - - /* What used to be an implicit check whether orientation != - * NO_ORIENTATION is now a proper separate flag. */ - if (strcasecmp(buf, "none") != 0) - json_node->split = true; free(buf); } else if (strcasecmp(last_key, "border") == 0) { char *buf = NULL; @@ -202,11 +197,9 @@ static int json_string(void *ctx, const unsigned char *val, unsigned int len) { json_node->layout = L_STACKED; else if (strcasecmp(buf, "tabbed") == 0) json_node->layout = L_TABBED; - else if (strcasecmp(buf, "dockarea") == 0) { + else if (strcasecmp(buf, "dockarea") == 0) json_node->layout = L_DOCKAREA; - /* Necessary for migrating from older versions of i3. */ - json_node->split = false; - } else if (strcasecmp(buf, "output") == 0) + else if (strcasecmp(buf, "output") == 0) json_node->layout = L_OUTPUT; else if (strcasecmp(buf, "splith") == 0) json_node->layout = L_SPLITH; @@ -333,9 +326,6 @@ static int json_bool(void *ctx, int val) { to_focus = json_node; } - if (strcasecmp(last_key, "split") == 0) - json_node->split = val; - if (parsing_swallows) { if (strcasecmp(last_key, "restart_mode") == 0) current_swallow->restart_mode = val; diff --git a/src/tree.c b/src/tree.c index 3d598d50..d4794e4d 100644 --- a/src/tree.c +++ b/src/tree.c @@ -382,7 +382,6 @@ void tree_split(Con *con, orientation_t orientation) { TAILQ_REPLACE(&(parent->focus_head), con, new, focused); new->parent = parent; new->layout = (orientation == HORIZ) ? L_SPLITH : L_SPLITV; - new->split = true; /* 3: swap 'percent' (resize factor) */ new->percent = con->percent; @@ -626,8 +625,8 @@ void tree_flatten(Con *con) { /* The child must have a different orientation than the con but the same as * the con’s parent to be redundant */ - if (!con->split || - !child->split || + if (!con_is_split(con) || + !con_is_split(child) || con_orientation(con) == con_orientation(child) || con_orientation(child) != con_orientation(parent)) goto recurse; diff --git a/src/workspace.c b/src/workspace.c index ef6a2add..872ec768 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -768,7 +768,6 @@ void ws_force_orientation(Con *ws, orientation_t orientation) { /* 1: create a new split container */ Con *split = con_new(NULL, NULL); split->parent = ws; - split->split = true; /* 2: copy layout from workspace */ split->layout = ws->layout; @@ -820,7 +819,6 @@ Con *workspace_attach_to(Con *ws) { /* 1: create a new split container */ Con *new = con_new(NULL, NULL); new->parent = ws; - new->split = true; /* 2: set the requested layout on the split con */ new->layout = ws->workspace_layout; diff --git a/testcases/t/116-nestedcons.t b/testcases/t/116-nestedcons.t index fc0b742a..84e86879 100644 --- a/testcases/t/116-nestedcons.t +++ b/testcases/t/116-nestedcons.t @@ -52,7 +52,6 @@ my $expected = { name => 'root', orientation => $ignore, type => 0, - split => JSON::XS::false, id => $ignore, rect => $ignore, window_rect => $ignore,