From: Michael Stapelberg Date: Sun, 4 Jul 2010 17:50:44 +0000 (+0200) Subject: Bugfix: Correctly restore focus after close (and add testcase) X-Git-Tag: tree-pr1~163 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b186446fb76425dc88a8dc7f94ff477eab5f5829;p=i3%2Fi3 Bugfix: Correctly restore focus after close (and add testcase) --- diff --git a/src/tree.c b/src/tree.c index ec8b0a83..5b4e883b 100644 --- a/src/tree.c +++ b/src/tree.c @@ -143,8 +143,11 @@ void tree_close(Con *con, bool kill_window) { next = con_get_workspace(con); } else { next = TAILQ_NEXT(con, focused); - if (next == TAILQ_END(&(con->parent->nodes_head))) + if (next == TAILQ_END(&(con->parent->nodes_head))) { next = con->parent; + while (!TAILQ_EMPTY(&(next->focus_head))) + next = TAILQ_FIRST(&(next->focus_head)); + } } DLOG("closing %p, kill_window = %d\n", con, kill_window); diff --git a/testcases/t/29-focus-after-close.t b/testcases/t/29-focus-after-close.t new file mode 100644 index 00000000..b28ecf2a --- /dev/null +++ b/testcases/t/29-focus-after-close.t @@ -0,0 +1,49 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Check if the focus is correctly restored after closing windows. +# +use i3test tests => 6; +use Time::HiRes qw(sleep); + +my $i3 = i3("/tmp/nestedcons"); + +my $tmp = get_unused_workspace(); +$i3->command("workspace $tmp")->recv; + +ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); + +$i3->command('open')->recv; +my ($nodes, $focus) = get_ws_content($tmp); +my $first = $focus->[0]; + +$i3->command('split v')->recv; + +($nodes, $focus) = get_ws_content($tmp); + +is($nodes->[0]->{focused}, 0, 'split container not focused'); +$i3->command('level up')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($nodes->[0]->{focused}, 1, 'split container focused after level up'); + +$i3->command('open')->recv; + +($nodes, $focus) = get_ws_content($tmp); +my $second = $focus->[0]; + +isnt($first, $second, 'different container focused'); + +############################################################## +# see if the focus goes down to $first (not to its split parent) +# when closing $second +############################################################## + +$i3->command('kill')->recv; +# TODO: this testcase sometimes has different outcomes when the +# sleep is missing. why? +sleep 0.25; +($nodes, $focus) = get_ws_content($tmp); +is($nodes->[0]->{nodes}->[0]->{id}, $first, 'first container found'); +is($nodes->[0]->{nodes}->[0]->{focused}, 1, 'first container focused'); + +diag( "Testing i3, Perl $], $^X" );