]> git.sur5r.net Git - i3/i3/blob - testcases/t/29-focus-after-close.t
t/29-focus-after-close.t: add more tests (for a regression)
[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 => 9;
7 use List::Util qw(first);
8 use Time::HiRes qw(sleep);
9
10 my $i3 = i3("/tmp/nestedcons");
11
12 my $tmp = get_unused_workspace();
13 $i3->command("workspace $tmp")->recv;
14
15 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
16
17 my $first = open_empty_con($i3);
18
19 $i3->command('split v')->recv;
20
21 my ($nodes, $focus) = get_ws_content($tmp);
22
23 is($nodes->[0]->{focused}, 0, 'split container not focused');
24 $i3->command('level up')->recv;
25 ($nodes, $focus) = get_ws_content($tmp);
26 is($nodes->[0]->{focused}, 1, 'split container focused after level up');
27
28 my $second = open_empty_con($i3);
29
30 isnt($first, $second, 'different container focused');
31
32 # We have the following layout now (con is focused):
33 # .----------------.
34 # | split  |       |
35 # | .----. |  con  |
36 # | | cn | |       |
37 # | `----' |       |
38 # `----------------'
39
40 ##############################################################
41 # see if the focus goes down to $first (not to its split parent)
42 # when closing $second
43 ##############################################################
44
45 $i3->command('kill')->recv;
46 # TODO: this testcase sometimes has different outcomes when the
47 # sleep is missing. why?
48 sleep 0.25;
49 ($nodes, $focus) = get_ws_content($tmp);
50 is($nodes->[0]->{nodes}->[0]->{id}, $first, 'first container found');
51 is($nodes->[0]->{nodes}->[0]->{focused}, 1, 'first container focused');
52
53 ##############################################################
54 # another case, using a slightly different layout (regression)
55 ##############################################################
56
57 $tmp = get_unused_workspace();
58 $i3->command("workspace $tmp")->recv;
59
60 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
61
62 $i3->command('split v')->recv;
63 $first = open_empty_con($i3);
64 my $bottom = open_empty_con($i3);
65
66 $i3->command('prev v')->recv;
67 $i3->command('split h')->recv;
68 my $middle = open_empty_con($i3);
69 my $right = open_empty_con($i3);
70 $i3->command('next v')->recv;
71
72 # We have the following layout now (second is focused):
73 # .----------------------------.
74 # | .------------------------. |
75 # | | first | middle | right | |
76 # | `------------------------' |
77 # |----------------------------|
78 # |                            |
79 # |          second            |
80 # |                            |
81 # `----------------------------'
82
83 # Check if the focus is restored to $right when we close $second
84 $i3->command('kill')->recv;
85
86 is(get_focused($tmp), $right, 'top right container focused (in focus stack)');
87
88 ($nodes, $focus) = get_ws_content($tmp);
89 my $tr = first { $_->{id} eq $right } @{$nodes->[0]->{nodes}};
90 is($tr->{focused}, 1, 'top right container really has focus');
91
92 ##############################################################
93 # and now for something completely different:
94 # check if the pointer position is relevant when restoring focus
95 # (it should not be relevant, of course)
96 ##############################################################
97
98 # TODO: add test code as soon as I can reproduce it
99
100 diag( "Testing i3, Perl $], $^X" );