X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=testcases%2Ft%2F29-focus-after-close.t;h=ac029eb14f85c1f2b6ade674c1baa7eb2c52f50d;hb=057e0e9794c498be97b27cc6f0f9eb9ff6d0a3ee;hp=d189ead68c8e39090b9ecde639bd8aa094f5af86;hpb=b4e3563dc1478f9b4696653be81d34e628757d9a;p=i3%2Fi3 diff --git a/testcases/t/29-focus-after-close.t b/testcases/t/29-focus-after-close.t index d189ead6..ac029eb1 100644 --- a/testcases/t/29-focus-after-close.t +++ b/testcases/t/29-focus-after-close.t @@ -3,31 +3,33 @@ # # Check if the focus is correctly restored after closing windows. # -use i3test tests => 9; +use i3test; +use X11::XCB qw(:all); use List::Util qw(first); -use Time::HiRes qw(sleep); -my $i3 = i3("/tmp/nestedcons"); +my $x = X11::XCB::Connection->new; -my $tmp = get_unused_workspace(); -$i3->command("workspace $tmp")->recv; +my $i3 = i3(get_socket_path()); + +my $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); my $first = open_empty_con($i3); +my $second = open_empty_con($i3); -$i3->command('split v')->recv; +cmd 'split v'; my ($nodes, $focus) = get_ws_content($tmp); -is($nodes->[0]->{focused}, 0, 'split container not focused'); -$i3->command('level up')->recv; +ok(!$nodes->[1]->{focused}, 'split container not focused'); +cmd 'focus parent'; ($nodes, $focus) = get_ws_content($tmp); -is($nodes->[0]->{focused}, 1, 'split container focused after level up'); +ok($nodes->[1]->{focused}, 'split container focused after focus parent'); -my $second = open_empty_con($i3); +my $third = open_empty_con($i3); -isnt($first, $second, 'different container focused'); +isnt(get_focused($tmp), $second, 'different container focused'); # We have the following layout now (con is focused): # .----------------. @@ -42,32 +44,31 @@ isnt($first, $second, 'different container focused'); # when closing $second ############################################################## -$i3->command('kill')->recv; +cmd 'kill'; # 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'); +is($nodes->[1]->{nodes}->[0]->{id}, $second, 'second container found'); +ok($nodes->[1]->{nodes}->[0]->{focused}, 'second container focused'); ############################################################## # another case, using a slightly different layout (regression) ############################################################## -$tmp = get_unused_workspace(); -$i3->command("workspace $tmp")->recv; +$tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); -$i3->command('split v')->recv; +cmd 'split v'; $first = open_empty_con($i3); my $bottom = open_empty_con($i3); -$i3->command('prev v')->recv; -$i3->command('split h')->recv; +cmd 'focus up'; +cmd 'split h'; my $middle = open_empty_con($i3); my $right = open_empty_con($i3); -$i3->command('next v')->recv; +cmd 'focus down'; # We have the following layout now (second is focused): # .----------------------------. @@ -81,7 +82,7 @@ $i3->command('next v')->recv; # `----------------------------' # Check if the focus is restored to $right when we close $second -$i3->command('kill')->recv; +cmd 'kill'; is(get_focused($tmp), $right, 'top right container focused (in focus stack)'); @@ -89,6 +90,27 @@ is(get_focused($tmp), $right, 'top right container focused (in focus stack)'); my $tr = first { $_->{id} eq $right } @{$nodes->[0]->{nodes}}; is($tr->{focused}, 1, 'top right container really has focus'); +############################################################## +# check if focus is correct after closing an unfocused window +############################################################## + +$tmp = fresh_workspace; + +ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); + +$first = open_empty_con($i3); +$middle = open_empty_con($i3); +# XXX: the $right empty con will be filled with the x11 window we are creating afterwards +$right = open_empty_con($i3); +my $win = open_standard_window($x, '#00ff00'); + +cmd qq|[con_id="$middle"] focus|; +$win->destroy; + +sleep 0.25; + +is(get_focused($tmp), $middle, 'middle container focused'); + ############################################################## # and now for something completely different: # check if the pointer position is relevant when restoring focus @@ -97,4 +119,4 @@ is($tr->{focused}, 1, 'top right container really has focus'); # TODO: add test code as soon as I can reproduce it -diag( "Testing i3, Perl $], $^X" ); +done_testing;