2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Check if the focus is correctly restored after closing windows.
20 use List::Util qw(first);
22 my $i3 = i3(get_socket_path());
24 my $tmp = fresh_workspace;
26 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
28 my $first = open_empty_con($i3);
29 my $second = open_empty_con($i3);
33 my ($nodes, $focus) = get_ws_content($tmp);
35 ok(!$nodes->[1]->{focused}, 'split container not focused');
37 ($nodes, $focus) = get_ws_content($tmp);
38 ok($nodes->[1]->{focused}, 'split container focused after focus parent');
40 my $third = open_empty_con($i3);
42 isnt(get_focused($tmp), $second, 'different container focused');
44 # We have the following layout now (con is focused):
52 ##############################################################
53 # see if the focus goes down to $first (not to its split parent)
54 # when closing $second
55 ##############################################################
60 ($nodes, $focus) = get_ws_content($tmp);
61 is($nodes->[1]->{nodes}->[0]->{id}, $second, 'second container found');
62 ok($nodes->[1]->{nodes}->[0]->{focused}, 'second container focused');
64 ##############################################################
65 # another case, using a slightly different layout (regression)
66 ##############################################################
68 $tmp = fresh_workspace;
70 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
73 $first = open_empty_con($i3);
74 my $bottom = open_empty_con($i3);
78 my $middle = open_empty_con($i3);
79 my $right = open_empty_con($i3);
82 # We have the following layout now (second is focused):
83 # .----------------------------.
84 # | .------------------------. |
85 # | | first | middle | right | |
86 # | `------------------------' |
87 # |----------------------------|
91 # `----------------------------'
93 # Check if the focus is restored to $right when we close $second
96 is(get_focused($tmp), $right, 'top right container focused (in focus stack)');
98 ($nodes, $focus) = get_ws_content($tmp);
99 my $tr = first { $_->{id} eq $right } @{$nodes->[0]->{nodes}};
100 is($tr->{focused}, 1, 'top right container really has focus');
102 ##############################################################
103 # check if focus is correct after closing an unfocused window
104 ##############################################################
106 $tmp = fresh_workspace;
108 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
110 $first = open_empty_con($i3);
111 $middle = open_empty_con($i3);
112 # XXX: the $right empty con will be filled with the x11 window we are creating afterwards
113 $right = open_empty_con($i3);
114 my $win = open_window({ background_color => '#00ff00' });
116 cmd qq|[con_id="$middle"] focus|;
120 is(get_focused($tmp), $middle, 'middle container focused');
122 ##############################################################
123 # and now for something completely different:
124 # check if the pointer position is relevant when restoring focus
125 # (it should not be relevant, of course)
126 ##############################################################
128 # TODO: add test code as soon as I can reproduce it