Replace the discrete 'split' Con property with a simple function.

This commit is contained in:
Deiz 2012-10-03 13:10:48 -04:00 committed by Michael Stapelberg
parent d7e5da8b39
commit fdcba7b91a
9 changed files with 33 additions and 30 deletions

View File

@ -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).

View File

@ -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,

View File

@ -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);
}

View File

@ -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

View File

@ -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:

View File

@ -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;

View File

@ -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 cons 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;

View File

@ -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;

View File

@ -52,7 +52,6 @@ my $expected = {
name => 'root',
orientation => $ignore,
type => 0,
split => JSON::XS::false,
id => $ignore,
rect => $ignore,
window_rect => $ignore,