From 1fecbb3e5ad5e4f6ddb1e8656ee8d043d698f29f Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 20 Jan 2011 10:09:43 +0100 Subject: [PATCH] Bugfix: also close empty split containers when the clients are moved away (Thanks mseed) Also update the testcase (which used only 'kill' before). --- src/con.c | 10 +++++++ testcases/t/30-close-empty-split.t | 42 +++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/con.c b/src/con.c index d5389ff4..b151d297 100644 --- a/src/con.c +++ b/src/con.c @@ -478,11 +478,21 @@ void con_move_to_workspace(Con *con, Con *workspace) { DLOG("Re-attaching container to %p / %s\n", next, next->name); /* 5: re-attach the con to the parent of this focused container */ + Con *parent = con->parent; con_detach(con); con_attach(con, next, false); /* 6: keep focus on the current workspace */ con_focus(focus_next); + + /* 7: check if the parent container is empty now and close it */ + if (parent->type != CT_WORKSPACE && + TAILQ_EMPTY(&(parent->nodes_head))) { + DLOG("Closing empty parent container\n"); + /* TODO: check if this container would swallow any other client and + * don’t close it automatically. */ + tree_close(parent, false, false); + } } /* diff --git a/testcases/t/30-close-empty-split.t b/testcases/t/30-close-empty-split.t index f1b7c2ab..44aa3372 100644 --- a/testcases/t/30-close-empty-split.t +++ b/testcases/t/30-close-empty-split.t @@ -3,7 +3,7 @@ # # Check if empty split containers are automatically closed. # -use i3test tests => 4; +use i3test tests => 8; use Time::HiRes qw(sleep); my $i3 = i3("/tmp/nestedcons"); @@ -42,4 +42,44 @@ $i3->command('kill')->recv; ($nodes, $focus) = get_ws_content($tmp); isnt($nodes->[0]->{id}, $split, 'split container closed'); +############################################################## +# same thing but this time we are moving the cons away instead +# of killing them +############################################################## + +$tmp = get_unused_workspace(); +$i3->command("workspace $tmp")->recv; + +ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); + +$first = open_empty_con($i3); +$second = open_empty_con($i3); +$i3->command(qq|[con_id="$first"] focus|)->recv; + +$i3->command('split v')->recv; + +($nodes, $focus) = get_ws_content($tmp); + +is($nodes->[0]->{focused}, 0, 'split container not focused'); + +# focus the split container +$i3->command('level up')->recv; +($nodes, $focus) = get_ws_content($tmp); +my $split = $focus->[0]; +$i3->command('level down')->recv; + +my $second = open_empty_con($i3); + +isnt($first, $second, 'different container focused'); + +############################################################## +# close both windows and see if the split container still exists +############################################################## + +my $otmp = get_unused_workspace(); +$i3->command("move workspace $otmp")->recv; +$i3->command("move workspace $otmp")->recv; +($nodes, $focus) = get_ws_content($tmp); +isnt($nodes->[0]->{id}, $split, 'split container closed'); + diag( "Testing i3, Perl $], $^X" ); -- 2.39.5