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');
122 cmd '[id=' . $sixth->id . '] focus';
125 cmd "workspace $s1_ws";
127 is($x->input_focus, $second->id, 'second window focused');
130 cmd "workspace $s1_ws";
132 is($x->input_focus, $sixth->id, 'sixth window focused');
135 cmd "workspace $s2_ws";
137 is($x->input_focus, $sixth->id, 'sixth window focused');
139 cmd "workspace $s2_ws";
141 is($x->input_focus, $second->id, 'second window focused');
143 ###################################################################
144 # Test that focus (left|down|right|up), when focusing across
145 # outputs, doesn't focus the next window in the given direction but
146 # the most focused window of the container in the given direction.
147 # In the following layout:
148 # [ WS1*[ ] WS2[ H[ A B* ] ] ]
149 # (where the asterisk denotes the focused container within its
150 # parent) moving right from WS1 should focus B which is focused
151 # inside WS2, not A which is the next window on the right of WS1.
153 ###################################################################
158 $x->root->warp_pointer(1025, 0); # Second screen.
160 $s1_ws = fresh_workspace;
161 $first = open_window;
162 $second = open_window;
165 $x->root->warp_pointer(0, 0); # First screen.
167 $s0_ws = fresh_workspace;
169 $third = open_window;
172 is($x->input_focus, $second->id, 'second window (rightmost) focused');
174 is($x->input_focus, $first->id, 'first window focused');
176 is($x->input_focus, $third->id, 'third window focused');
179 ###################################################################
180 # Similar but with a tabbed layout.
181 ###################################################################
184 $fourth = open_window;
186 is($x->input_focus, $third->id, 'third window (tabbed) focused');
187 cmd "workspace $s1_ws";
189 is($x->input_focus, $third->id, 'third window (tabbed) focused');
192 ###################################################################
193 # Similar but with a stacked layout on the bottom screen.
194 ###################################################################
197 $x->root->warp_pointer(0, 769); # Third screen.
199 $s2_ws = fresh_workspace;
200 cmd 'layout stacked';
201 $fifth = open_window;
202 $sixth = open_window;
204 cmd "workspace $s0_ws";
206 is($x->input_focus, $sixth->id, 'sixth window (stacked) focused');
208 ###################################################################
209 # Similar but with a more complex layout.
210 ###################################################################
213 $x->root->warp_pointer(1025, 769); # Fourth screen.
215 $s3_ws = fresh_workspace;
222 my $nested = open_window;
225 is($x->input_focus, $nested->id, 'nested window focused');
227 cmd "workspace $s1_ws";
229 is($x->input_focus, $nested->id, 'nested window focused from workspace above');
231 cmd "workspace $s2_ws";
233 is($x->input_focus, $nested->id, 'nested window focused from workspace on the left');