From: Ingo Bürk Date: Mon, 26 Oct 2015 17:16:21 +0000 (+0100) Subject: Fix crash when trying to split and float a dock container. X-Git-Tag: 4.14.1~83 X-Git-Url: https://git.sur5r.net/?p=i3%2Fi3;a=commitdiff_plain;h=f02413b4cfba84d2d732d9534eb1434c5ba1cc3b Fix crash when trying to split and float a dock container. Since splitting a docking container was allowed and successful, the check to prevent floating it fails to work. This causes a crash because the workspace of the container cannot be determined as the dockarea is higher up in the tree than the workspace it belongs to. This patch extends to sanity check to nested dock containers when trying to float a container and also disallows manually splitting a docked container or changing its layout. fixes #2034 --- diff --git a/include/con.h b/include/con.h index 16ea6cfa..2e853016 100644 --- a/include/con.h +++ b/include/con.h @@ -112,6 +112,12 @@ bool con_is_internal(Con *con); */ bool con_is_floating(Con *con); +/** + * Returns true if the container is a docked container. + * + */ +bool con_is_docked(Con *con); + /** * Checks if the given container is either floating or inside some floating * container. It returns the FLOATING_CON container. diff --git a/src/commands.c b/src/commands.c index 95784c77..56b95061 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1270,16 +1270,18 @@ void cmd_move_workspace_to_output(I3_CMD, const char *name) { * */ void cmd_split(I3_CMD, const char *direction) { + HANDLE_EMPTY_MATCH; + owindow *current; - /* TODO: use matches */ LOG("splitting in direction %c\n", direction[0]); - if (match_is_empty(current_match)) - tree_split(focused, (direction[0] == 'v' ? VERT : HORIZ)); - else { - TAILQ_FOREACH(current, &owindows, owindows) { - DLOG("matching: %p / %s\n", current->con, current->con->name); - tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ)); + TAILQ_FOREACH(current, &owindows, owindows) { + if (con_is_docked(current->con)) { + ELOG("Cannot split a docked container, skipping.\n"); + continue; } + + DLOG("matching: %p / %s\n", current->con, current->con->name); + tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ)); } cmd_output->needs_tree_render = true; @@ -1606,9 +1608,10 @@ void cmd_move_direction(I3_CMD, const char *direction, long move_px) { * */ void cmd_layout(I3_CMD, const char *layout_str) { + HANDLE_EMPTY_MATCH; + if (strcmp(layout_str, "stacking") == 0) layout_str = "stacked"; - owindow *current; layout_t layout; /* default is a special case which will be handled in con_set_layout(). */ if (strcmp(layout_str, "default") == 0) @@ -1628,14 +1631,15 @@ void cmd_layout(I3_CMD, const char *layout_str) { DLOG("changing layout to %s (%d)\n", layout_str, layout); - /* check if the match is empty, not if the result is empty */ - if (match_is_empty(current_match)) - con_set_layout(focused, layout); - else { - TAILQ_FOREACH(current, &owindows, owindows) { - DLOG("matching: %p / %s\n", current->con, current->con->name); - con_set_layout(current->con, layout); + owindow *current; + TAILQ_FOREACH(current, &owindows, owindows) { + if (con_is_docked(current->con)) { + ELOG("cannot change layout of a docked container, skipping it.\n"); + continue; } + + DLOG("matching: %p / %s\n", current->con, current->con->name); + con_set_layout(current->con, layout); } cmd_output->needs_tree_render = true; diff --git a/src/con.c b/src/con.c index 5b0cc6c8..4233a8a8 100644 --- a/src/con.c +++ b/src/con.c @@ -447,6 +447,20 @@ bool con_is_floating(Con *con) { return (con->floating >= FLOATING_AUTO_ON); } +/* + * Returns true if the container is a docked container. + * + */ +bool con_is_docked(Con *con) { + if (con->parent == NULL) + return false; + + if (con->parent->type == CT_DOCKAREA) + return true; + + return con_is_docked(con->parent); +} + /* * Checks if the given container is either floating or inside some floating * container. It returns the FLOATING_CON container. diff --git a/src/floating.c b/src/floating.c index d7a33067..77bc9e17 100644 --- a/src/floating.c +++ b/src/floating.c @@ -108,7 +108,7 @@ void floating_check_size(Con *floating_con) { void floating_enable(Con *con, bool automatic) { bool set_focus = (con == focused); - if (con->parent && con->parent->type == CT_DOCKAREA) { + if (con_is_docked(con)) { LOG("Container is a dock window, not enabling floating mode.\n"); return; }