]> git.sur5r.net Git - i3/i3/blob - testcases/t/29-focus-after-close.t
more explanation in t/29-focus-after-close.t
[i3/i3] / testcases / t / 29-focus-after-close.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Check if the focus is correctly restored after closing windows.
5 #
6 use i3test tests => 6;
7 use Time::HiRes qw(sleep);
8
9 my $i3 = i3("/tmp/nestedcons");
10
11 my $tmp = get_unused_workspace();
12 $i3->command("workspace $tmp")->recv;
13
14 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
15
16 $i3->command('open')->recv;
17 my ($nodes, $focus) = get_ws_content($tmp);
18 my $first = $focus->[0];
19
20 $i3->command('split v')->recv;
21
22 ($nodes, $focus) = get_ws_content($tmp);
23
24 is($nodes->[0]->{focused}, 0, 'split container not focused');
25 $i3->command('level up')->recv;
26 ($nodes, $focus) = get_ws_content($tmp);
27 is($nodes->[0]->{focused}, 1, 'split container focused after level up');
28
29 $i3->command('open')->recv;
30
31 ($nodes, $focus) = get_ws_content($tmp);
32 my $second = $focus->[0];
33
34 isnt($first, $second, 'different container focused');
35
36 # We have the following layout now (con is focused):
37 # .----------------.
38 # | split  |       |
39 # | .----. |  con  |
40 # | | cn | |       |
41 # | `----' |       |
42 # `----------------'
43
44 ##############################################################
45 # see if the focus goes down to $first (not to its split parent)
46 # when closing $second
47 ##############################################################
48
49 $i3->command('kill')->recv;
50 # TODO: this testcase sometimes has different outcomes when the
51 # sleep is missing. why?
52 sleep 0.25;
53 ($nodes, $focus) = get_ws_content($tmp);
54 is($nodes->[0]->{nodes}->[0]->{id}, $first, 'first container found');
55 is($nodes->[0]->{nodes}->[0]->{focused}, 1, 'first container focused');
56
57 diag( "Testing i3, Perl $], $^X" );