2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://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 # Tests that switching workspaces via 'focus $dir' never leaves a floating
20 use i3test i3_config => <<EOT;
22 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
24 fake-outputs 1024x768+0+0,1024x768+1024+0,1024x768+0+768,1024x768+1024+768
27 my $s0_ws = fresh_workspace;
28 my $first = open_window;
29 my $second = open_window;
30 my $third = open_window;
31 cmd 'floating toggle';
35 $x->root->warp_pointer(1025, 0);
37 my $s1_ws = fresh_workspace;
39 my $fourth = open_window;
43 $x->root->warp_pointer(0, 769);
45 my $s2_ws = fresh_workspace;
47 my $fifth = open_window;
51 $x->root->warp_pointer(1025, 769);
53 my $s3_ws = fresh_workspace;
55 my $sixth = open_window;
56 my $seventh = open_window;
57 my $eighth = open_window;
58 cmd 'floating toggle';
60 # Layout should look like this (windows 3 and 8 are floating):
73 ###################################################################
74 # Test that focus (left|down|right|up) doesn't focus floating
75 # windows when moving into horizontally-split workspaces.
76 ###################################################################
80 cmd "workspace $ws; focus floating";
83 cmd "workspace $s1_ws";
85 is($x->input_focus, $second->id, 'second window focused');
88 cmd "workspace $s1_ws";
90 is($x->input_focus, $seventh->id, 'seventh window focused');
93 cmd "workspace $s2_ws";
95 is($x->input_focus, $seventh->id, 'seventh window focused');
98 cmd "workspace $s2_ws";
100 is($x->input_focus, $second->id, 'second window focused');
103 ###################################################################
104 # Put the workspaces on screens 0 and 3 into vertical split mode
105 # and test focus (left|down|right|up) again.
106 ###################################################################
108 cmd "workspace $s0_ws";
109 is($x->input_focus, $third->id, 'third window focused');
113 # Focus second or else $first gets to the top of the focus stack.
114 cmd '[id=' . $second->id . '] focus';
117 cmd "workspace $s3_ws";
118 is($x->input_focus, $eighth->id, 'eighth window focused');
124 cmd "workspace $s1_ws";
126 is($x->input_focus, $second->id, 'second window focused');
129 cmd "workspace $s1_ws";
131 is($x->input_focus, $sixth->id, 'sixth window focused');
134 cmd "workspace $s2_ws";
136 is($x->input_focus, $sixth->id, 'sixth window focused');
138 cmd "workspace $s2_ws";
140 is($x->input_focus, $second->id, 'second window focused');
142 ###################################################################
143 # Test that focus (left|down|right|up), when focusing across
144 # outputs, doesn't focus the next window in the given direction but
145 # the most focused window of the container in the given direction.
146 # In the following layout:
147 # [ WS1*[ ] WS2[ H[ A B* ] ] ]
148 # (where the asterisk denotes the focused container within its
149 # parent) moving right from WS1 should focus B which is focused
150 # inside WS2, not A which is the next window on the right of WS1.
152 ###################################################################
157 $x->root->warp_pointer(1025, 0); # Second screen.
159 $s1_ws = fresh_workspace;
160 $first = open_window;
161 $second = open_window;
164 $x->root->warp_pointer(0, 0); # First screen.
166 $s0_ws = fresh_workspace;
168 $third = open_window;
171 is($x->input_focus, $second->id, 'second window (rightmost) focused');
173 is($x->input_focus, $first->id, 'first window focused');
175 is($x->input_focus, $third->id, 'third window focused');
178 ###################################################################
179 # Similar but with a tabbed layout.
180 ###################################################################
183 $fourth = open_window;
185 is($x->input_focus, $third->id, 'third window (tabbed) focused');
186 cmd "workspace $s1_ws";
188 is($x->input_focus, $third->id, 'third window (tabbed) focused');
191 ###################################################################
192 # Similar but with a stacked layout on the bottom screen.
193 ###################################################################
196 $x->root->warp_pointer(0, 769); # Third screen.
198 $s2_ws = fresh_workspace;
199 cmd 'layout stacked';
200 $fifth = open_window;
201 $sixth = open_window;
203 cmd "workspace $s0_ws";
205 is($x->input_focus, $sixth->id, 'sixth window (stacked) focused');
207 ###################################################################
208 # Similar but with a more complex layout.
209 ###################################################################
212 $x->root->warp_pointer(1025, 769); # Fourth screen.
214 $s3_ws = fresh_workspace;
221 my $nested = open_window;
224 is($x->input_focus, $nested->id, 'nested window focused');
226 cmd "workspace $s1_ws";
228 is($x->input_focus, $nested->id, 'nested window focused from workspace above');
230 cmd "workspace $s2_ws";
232 is($x->input_focus, $nested->id, 'nested window focused from workspace on the left');