From d490bae8a2b1eba5844b8a48740907ef4cedc4cb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fernando=20Tarl=C3=A1=20Cardoso=20Lemos?= Date: Sun, 23 Oct 2011 19:06:43 -0200 Subject: [PATCH] Close empty workspaces if they're not visible. Previously, we'd only close an empty workspace when we moved away from it. Now we also close it when the last client exits, as long as that workspace is not visible anymore. --- src/con.c | 15 +++++++++++++-- testcases/t/178-regress-workspace-open.t | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 testcases/t/178-regress-workspace-open.t diff --git a/src/con.c b/src/con.c index 12efdf58..04605689 100644 --- a/src/con.c +++ b/src/con.c @@ -1007,14 +1007,25 @@ static void con_on_remove_child(Con *con) { /* Every container 'above' (in the hierarchy) the workspace content should * not be closed when the last child was removed */ - if (con->type == CT_WORKSPACE || - con->type == CT_OUTPUT || + if (con->type == CT_OUTPUT || con->type == CT_ROOT || con->type == CT_DOCKAREA) { DLOG("not handling, type = %d\n", con->type); return; } + /* For workspaces, close them only if they're not visible anymore */ + if (con->type == CT_WORKSPACE) { + int children = con_num_children(con); + if (children == 0 && !workspace_is_visible(con)) { + LOG("Closing old workspace (%p / %s), it is empty\n", con, con->name); + tree_close(con, DONT_KILL_WINDOW, false, false); + ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"empty\"}"); + ewmh_update_workarea(); + } + return; + } + /* TODO: check if this container would swallow any other client and * don’t close it automatically. */ int children = con_num_children(con); diff --git a/testcases/t/178-regress-workspace-open.t b/testcases/t/178-regress-workspace-open.t new file mode 100644 index 00000000..25fe7d9a --- /dev/null +++ b/testcases/t/178-regress-workspace-open.t @@ -0,0 +1,22 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Tests if empty workspaces are closed when the last child +# exits, as long as they're not empty. +# +use i3test; + +my $i3 = i3(get_socket_path()); + +# Get a workspace and open a container +my $ws = fresh_workspace; +my $con = open_empty_con($i3); + +# Go to a second workspace, kill the container +fresh_workspace; +cmd "[con_id=\"$con\"] kill"; + +# The first workspace should have been closed +ok(!workspace_exists($ws), 'workspace closed'); + +done_testing; -- 2.39.5