Replace the discrete 'split' Con property with a simple function.
This commit is contained in:
parent
d7e5da8b39
commit
fdcba7b91a
@ -33,6 +33,12 @@ void con_focus(Con *con);
|
|||||||
*/
|
*/
|
||||||
bool con_is_leaf(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,
|
* Returns true if this node accepts a window (if the node swallows windows,
|
||||||
* it might already have swallowed enough and cannot hold any more).
|
* it might already have swallowed enough and cannot hold any more).
|
||||||
|
@ -440,8 +440,6 @@ struct Assignment {
|
|||||||
*/
|
*/
|
||||||
struct Con {
|
struct Con {
|
||||||
bool mapped;
|
bool mapped;
|
||||||
/** whether this is a split container or not */
|
|
||||||
bool split;
|
|
||||||
enum {
|
enum {
|
||||||
CT_ROOT = 0,
|
CT_ROOT = 0,
|
||||||
CT_OUTPUT = 1,
|
CT_OUTPUT = 1,
|
||||||
|
27
src/con.c
27
src/con.c
@ -36,7 +36,7 @@ static void con_force_split_parents_redraw(Con *con) {
|
|||||||
Con *parent = con;
|
Con *parent = con;
|
||||||
|
|
||||||
while (parent && parent->type != CT_WORKSPACE && parent->type != CT_DOCKAREA) {
|
while (parent && parent->type != CT_WORKSPACE && parent->type != CT_DOCKAREA) {
|
||||||
if (parent->split)
|
if (!con_is_leaf(parent))
|
||||||
FREE(parent->deco_render_params);
|
FREE(parent->deco_render_params);
|
||||||
parent = parent->parent;
|
parent = parent->parent;
|
||||||
}
|
}
|
||||||
@ -232,6 +232,24 @@ bool con_is_leaf(Con *con) {
|
|||||||
return TAILQ_EMPTY(&(con->nodes_head));
|
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,
|
* Returns true if this node accepts a window (if the node swallows windows,
|
||||||
* it might already have swallowed enough and cannot hold any more).
|
* 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)
|
if (con->type == CT_WORKSPACE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (con->split) {
|
if (con_is_split(con)) {
|
||||||
DLOG("container %p does not accept windows, it is a split container.\n", con);
|
DLOG("container %p does not accept windows, it is a split container.\n", con);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1163,7 +1181,6 @@ void con_set_layout(Con *con, int layout) {
|
|||||||
* split. */
|
* split. */
|
||||||
new->layout = layout;
|
new->layout = layout;
|
||||||
new->last_split_layout = con->last_split_layout;
|
new->last_split_layout = con->last_split_layout;
|
||||||
new->split = true;
|
|
||||||
|
|
||||||
Con *old_focused = TAILQ_FIRST(&(con->focus_head));
|
Con *old_focused = TAILQ_FIRST(&(con->focus_head));
|
||||||
if (old_focused == TAILQ_END(&(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)
|
/* 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
|
* or height (v-split) and use the maximum of the height (h-split) or width
|
||||||
* (v-split) as minimum size. */
|
* (v-split) as minimum size. */
|
||||||
if (con->split) {
|
if (con_is_split(con)) {
|
||||||
uint32_t width = 0, height = 0;
|
uint32_t width = 0, height = 0;
|
||||||
Con *child;
|
Con *child;
|
||||||
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
|
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",
|
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);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,6 @@ void floating_enable(Con *con, bool automatic) {
|
|||||||
* otherwise. */
|
* otherwise. */
|
||||||
Con *ws = con_get_workspace(con);
|
Con *ws = con_get_workspace(con);
|
||||||
nc->parent = ws;
|
nc->parent = ws;
|
||||||
nc->split = true;
|
|
||||||
nc->type = CT_FLOATING_CON;
|
nc->type = CT_FLOATING_CON;
|
||||||
nc->layout = L_SPLITH;
|
nc->layout = L_SPLITH;
|
||||||
/* We insert nc already, even though its rect is not yet calculated. This
|
/* We insert nc already, even though its rect is not yet calculated. This
|
||||||
|
@ -165,7 +165,7 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
|||||||
|
|
||||||
/* provided for backwards compatibility only. */
|
/* provided for backwards compatibility only. */
|
||||||
ystr("orientation");
|
ystr("orientation");
|
||||||
if (!con->split)
|
if (!con_is_split(con))
|
||||||
ystr("none");
|
ystr("none");
|
||||||
else {
|
else {
|
||||||
if (con_orientation(con) == HORIZ)
|
if (con_orientation(con) == HORIZ)
|
||||||
@ -202,9 +202,6 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
|||||||
ystr("focused");
|
ystr("focused");
|
||||||
y(bool, (con == focused));
|
y(bool, (con == focused));
|
||||||
|
|
||||||
ystr("split");
|
|
||||||
y(bool, con->split);
|
|
||||||
|
|
||||||
ystr("layout");
|
ystr("layout");
|
||||||
switch (con->layout) {
|
switch (con->layout) {
|
||||||
case L_DEFAULT:
|
case L_DEFAULT:
|
||||||
|
@ -172,11 +172,6 @@ static int json_string(void *ctx, const unsigned char *val, unsigned int len) {
|
|||||||
else if (strcasecmp(buf, "vertical") == 0)
|
else if (strcasecmp(buf, "vertical") == 0)
|
||||||
json_node->last_split_layout = L_SPLITV;
|
json_node->last_split_layout = L_SPLITV;
|
||||||
else LOG("Unhandled orientation: %s\n", buf);
|
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);
|
free(buf);
|
||||||
} else if (strcasecmp(last_key, "border") == 0) {
|
} else if (strcasecmp(last_key, "border") == 0) {
|
||||||
char *buf = NULL;
|
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;
|
json_node->layout = L_STACKED;
|
||||||
else if (strcasecmp(buf, "tabbed") == 0)
|
else if (strcasecmp(buf, "tabbed") == 0)
|
||||||
json_node->layout = L_TABBED;
|
json_node->layout = L_TABBED;
|
||||||
else if (strcasecmp(buf, "dockarea") == 0) {
|
else if (strcasecmp(buf, "dockarea") == 0)
|
||||||
json_node->layout = L_DOCKAREA;
|
json_node->layout = L_DOCKAREA;
|
||||||
/* Necessary for migrating from older versions of i3. */
|
else if (strcasecmp(buf, "output") == 0)
|
||||||
json_node->split = false;
|
|
||||||
} else if (strcasecmp(buf, "output") == 0)
|
|
||||||
json_node->layout = L_OUTPUT;
|
json_node->layout = L_OUTPUT;
|
||||||
else if (strcasecmp(buf, "splith") == 0)
|
else if (strcasecmp(buf, "splith") == 0)
|
||||||
json_node->layout = L_SPLITH;
|
json_node->layout = L_SPLITH;
|
||||||
@ -333,9 +326,6 @@ static int json_bool(void *ctx, int val) {
|
|||||||
to_focus = json_node;
|
to_focus = json_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(last_key, "split") == 0)
|
|
||||||
json_node->split = val;
|
|
||||||
|
|
||||||
if (parsing_swallows) {
|
if (parsing_swallows) {
|
||||||
if (strcasecmp(last_key, "restart_mode") == 0)
|
if (strcasecmp(last_key, "restart_mode") == 0)
|
||||||
current_swallow->restart_mode = val;
|
current_swallow->restart_mode = val;
|
||||||
|
@ -382,7 +382,6 @@ void tree_split(Con *con, orientation_t orientation) {
|
|||||||
TAILQ_REPLACE(&(parent->focus_head), con, new, focused);
|
TAILQ_REPLACE(&(parent->focus_head), con, new, focused);
|
||||||
new->parent = parent;
|
new->parent = parent;
|
||||||
new->layout = (orientation == HORIZ) ? L_SPLITH : L_SPLITV;
|
new->layout = (orientation == HORIZ) ? L_SPLITH : L_SPLITV;
|
||||||
new->split = true;
|
|
||||||
|
|
||||||
/* 3: swap 'percent' (resize factor) */
|
/* 3: swap 'percent' (resize factor) */
|
||||||
new->percent = con->percent;
|
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 child must have a different orientation than the con but the same as
|
||||||
* the con’s parent to be redundant */
|
* the con’s parent to be redundant */
|
||||||
if (!con->split ||
|
if (!con_is_split(con) ||
|
||||||
!child->split ||
|
!con_is_split(child) ||
|
||||||
con_orientation(con) == con_orientation(child) ||
|
con_orientation(con) == con_orientation(child) ||
|
||||||
con_orientation(child) != con_orientation(parent))
|
con_orientation(child) != con_orientation(parent))
|
||||||
goto recurse;
|
goto recurse;
|
||||||
|
@ -768,7 +768,6 @@ void ws_force_orientation(Con *ws, orientation_t orientation) {
|
|||||||
/* 1: create a new split container */
|
/* 1: create a new split container */
|
||||||
Con *split = con_new(NULL, NULL);
|
Con *split = con_new(NULL, NULL);
|
||||||
split->parent = ws;
|
split->parent = ws;
|
||||||
split->split = true;
|
|
||||||
|
|
||||||
/* 2: copy layout from workspace */
|
/* 2: copy layout from workspace */
|
||||||
split->layout = ws->layout;
|
split->layout = ws->layout;
|
||||||
@ -820,7 +819,6 @@ Con *workspace_attach_to(Con *ws) {
|
|||||||
/* 1: create a new split container */
|
/* 1: create a new split container */
|
||||||
Con *new = con_new(NULL, NULL);
|
Con *new = con_new(NULL, NULL);
|
||||||
new->parent = ws;
|
new->parent = ws;
|
||||||
new->split = true;
|
|
||||||
|
|
||||||
/* 2: set the requested layout on the split con */
|
/* 2: set the requested layout on the split con */
|
||||||
new->layout = ws->workspace_layout;
|
new->layout = ws->workspace_layout;
|
||||||
|
@ -52,7 +52,6 @@ my $expected = {
|
|||||||
name => 'root',
|
name => 'root',
|
||||||
orientation => $ignore,
|
orientation => $ignore,
|
||||||
type => 0,
|
type => 0,
|
||||||
split => JSON::XS::false,
|
|
||||||
id => $ignore,
|
id => $ignore,
|
||||||
rect => $ignore,
|
rect => $ignore,
|
||||||
window_rect => $ignore,
|
window_rect => $ignore,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user