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 # Test if new containers get focused when there is a fullscreen container at
18 # the time of launching the new one. Also make sure that focusing containers
19 # in other workspaces work even when there is a fullscreen container.
21 use i3test i3_config => <<EOT;
23 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
25 fake-outputs 1024x768+0+0,1024x768+1024+0
27 # Screen setup looks like this:
32 my $tmp = fresh_workspace;
34 ################################################################################
35 # Open the left window.
36 ################################################################################
38 my $left = open_window({ background_color => '#ff0000' });
40 is($x->input_focus, $left->id, 'left window focused');
42 diag("left = " . $left->id);
44 ################################################################################
45 # Open the right window.
46 ################################################################################
48 my $right = open_window({ background_color => '#00ff00' });
50 diag("right = " . $right->id);
52 ################################################################################
53 # Set the right window to fullscreen.
54 ################################################################################
56 cmd 'nop setting fullscreen';
59 ################################################################################
60 # Open a third window. Since we're fullscreen, the window won't be # mapped, so
61 # don't wait for it to be mapped. Instead, just send the map request and sync
62 # with i3 to make sure i3 recognizes it.
63 ################################################################################
65 my $third = open_window({
66 background_color => '#0000ff',
67 name => 'Third window',
75 diag("third = " . $third->id);
77 ################################################################################
78 # Move the window to a different workspace, and verify that the third window now
79 # gets focused in the current workspace.
80 ################################################################################
82 my $tmp2 = get_unused_workspace;
84 cmd "move workspace $tmp2";
86 is($x->input_focus, $third->id, 'third window focused');
88 ################################################################################
89 # Ensure that moving a window to a workspace which has a fullscreen window does
90 # not focus it (otherwise the user cannot get out of fullscreen mode anymore).
91 ################################################################################
93 $tmp = fresh_workspace;
95 my $fullscreen_window = open_window;
98 my $nodes = get_ws_content($tmp);
99 is(scalar @$nodes, 1, 'precisely one window');
100 is($nodes->[0]->{focused}, 1, 'fullscreen window focused');
101 my $old_id = $nodes->[0]->{id};
103 $tmp2 = fresh_workspace;
104 my $move_window = open_window;
105 cmd "move workspace $tmp";
107 cmd "workspace $tmp";
109 $nodes = get_ws_content($tmp);
110 is(scalar @$nodes, 2, 'precisely two windows');
111 is($nodes->[0]->{id}, $old_id, 'id unchanged');
112 is($nodes->[0]->{focused}, 1, 'fullscreen window focused');
114 ################################################################################
115 # Ensure it's possible to change focus if it doesn't escape the fullscreen
116 # container with fullscreen global. We can't even focus a container in a
117 # different workspace.
118 ################################################################################
124 $x->root->warp_pointer(1025, 0);
127 $tmp = fresh_workspace;
128 cmd "workspace $tmp";
129 my $diff_ws = open_window;
133 $x->root->warp_pointer(0, 0);
136 $tmp2 = fresh_workspace;
137 cmd "workspace $tmp2";
141 my $right1 = open_window;
143 my $right2 = open_window;
146 cmd 'fullscreen global';
148 cmd '[id="' . $right1->id . '"] focus';
149 is($x->input_focus, $right1->id, 'upper right window focused');
151 cmd '[id="' . $right2->id . '"] focus';
152 is($x->input_focus, $right2->id, 'bottom right window focused');
155 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
158 is($x->input_focus, $right2->id, 'bottom right window focused again');
161 is($x->input_focus, $right1->id, 'allowed focus up');
164 is($x->input_focus, $right2->id, 'allowed focus down');
167 is($x->input_focus, $right2->id, 'prevented focus left');
170 is($x->input_focus, $right2->id, 'prevented focus right');
173 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
176 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
178 ################################################################################
179 # Same tests when we're in non-global fullscreen mode. It should now be possible
180 # to focus a container in a different workspace.
181 ################################################################################
184 cmd 'fullscreen global';
187 cmd '[id="' . $right1->id . '"] focus';
188 is($x->input_focus, $right1->id, 'upper right window focused');
190 cmd '[id="' . $right2->id . '"] focus';
191 is($x->input_focus, $right2->id, 'bottom right window focused');
194 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
197 is($x->input_focus, $right2->id, 'bottom right window focused again');
200 is($x->input_focus, $right1->id, 'allowed focus up');
203 is($x->input_focus, $right2->id, 'allowed focus down');
206 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
209 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
212 is($x->input_focus, $right2->id, 'focus left wrapped (no-op)');
215 is($x->input_focus, $diff_ws->id, 'allowed focus change to different ws');
218 is($x->input_focus, $right2->id, 'focused back into fullscreen container');
220 cmd '[id="' . $diff_ws->id . '"] focus';
221 is($x->input_focus, $diff_ws->id, 'allowed focus change to different ws by id');
223 ################################################################################
224 # More testing of the interaction between wrapping and the fullscreen focus
226 ################################################################################
228 cmd '[id="' . $right1->id . '"] focus';
229 is($x->input_focus, $right1->id, 'upper right window focused');
236 my $right12 = open_window;
239 is($x->input_focus, $right2->id, 'bottom right window focused');
242 my $right22 = open_window;
249 is($x->input_focus, $right2->id, 'focus did not leave parent container (1)');
252 is($x->input_focus, $right22->id, 'focus did not leave parent container (2)');
255 is($x->input_focus, $right2->id, 'focus did not leave parent container (3)');
258 is($x->input_focus, $right22->id, 'focus did not leave parent container (4)');
260 ################################################################################
261 # Ensure that moving in a direction doesn't violate the focus restrictions.
262 ################################################################################
267 my $nodes = get_ws_content($tmp2);
268 my $split = $nodes->[1];
269 my $fs = $split->{nodes}->[1];
270 is(scalar @{$fs->{nodes}}, $num, $msg);
274 verify_move(2, 'prevented move left');
276 verify_move(2, 'prevented move right');
278 verify_move(2, 'prevented move down');
281 verify_move(2, 'prevented move up');
283 ################################################################################
284 # Moving to a different workspace is allowed with per-output fullscreen
286 ################################################################################
288 cmd "move to workspace $tmp";
289 verify_move(1, 'did not prevent move to workspace by name');
291 cmd "workspace $tmp";
292 cmd "move to workspace $tmp2";
293 cmd "workspace $tmp2";
295 cmd "move to workspace prev";
296 verify_move(1, 'did not prevent move to workspace by position');
298 ################################################################################
299 # Ensure that is not allowed with global fullscreen containers.
300 ################################################################################
302 cmd "workspace $tmp";
303 cmd "move to workspace $tmp2";
304 cmd "workspace $tmp2";
308 cmd 'fullscreen global';
311 cmd "move to workspace $tmp";
312 verify_move(2, 'prevented move to workspace by name');
314 cmd "move to workspace prev";
315 verify_move(2, 'prevented move to workspace by position');
317 ################################################################################
318 # Ensure it's possible to focus a window using the focus command despite
319 # fullscreen window blocking it. Fullscreen window should lose its fullscreen
321 ################################################################################
323 # first & second tiling, focus using id
326 $tmp = fresh_workspace;
327 my $first = open_window;
328 my $second = open_window;
330 is($x->input_focus, $second->id, 'fullscreen window focused');
331 is_num_fullscreen($tmp, 1, '1 fullscreen window');
333 cmd '[id="'. $first->id .'"] focus';
336 is($x->input_focus, $first->id, 'correctly focused using id');
337 is_num_fullscreen($tmp, 0, 'no fullscreen windows');
339 # first floating, second tiling, focus using 'focus floating'
342 $tmp = fresh_workspace;
343 $first = open_floating_window;
344 $second = open_window;
346 is($x->input_focus, $second->id, 'fullscreen window focused');
347 is_num_fullscreen($tmp, 1, '1 fullscreen window');
349 cmd 'focus floating';
352 is($x->input_focus, $first->id, 'correctly focused using focus floating');
353 is_num_fullscreen($tmp, 0, 'no fullscreen windows');
355 # first tiling, second floating, focus using 'focus tiling'
358 $tmp = fresh_workspace;
359 $first = open_window;
360 $second = open_floating_window;
362 is($x->input_focus, $second->id, 'fullscreen window focused');
363 is_num_fullscreen($tmp, 1, '1 fullscreen window');
368 is($x->input_focus, $first->id, 'correctly focused using focus tiling');
369 is_num_fullscreen($tmp, 0, 'no fullscreen windows');
371 ################################################################################
372 # When the fullscreen window is in an other workspace it should maintain its
373 # fullscreen mode since it's not blocking the window to be focused.
374 ################################################################################
378 $tmp = fresh_workspace;
379 $first = open_window;
381 $tmp2 = fresh_workspace;
382 $second = open_window;
384 is($x->input_focus, $second->id, 'fullscreen window focused');
385 is_num_fullscreen($tmp2, 1, '1 fullscreen window');
387 cmd '[id="'. $first->id .'"] focus';
390 is($x->input_focus, $first->id, 'correctly focused using focus id');
391 is_num_fullscreen($tmp, 0, 'no fullscreen windows on first workspace');
392 is_num_fullscreen($tmp2, 1, 'still one fullscreen window on second workspace');
394 ################################################################################
395 # But a global window in another workspace is blocking the window to be focused.
396 # Ensure that it loses its fullscreen mode.
397 ################################################################################
401 $tmp = fresh_workspace;
402 $first = open_window;
404 $tmp2 = fresh_workspace;
405 $second = open_window;
406 cmd 'fullscreen global';
407 is($x->input_focus, $second->id, 'global window focused');
408 is_num_fullscreen($tmp2, 1, '1 fullscreen window');
410 cmd '[id="'. $first->id .'"] focus';
413 is($x->input_focus, $first->id, 'correctly focused using focus id');
414 is_num_fullscreen($tmp2, 0, 'no fullscreen windows');
417 # TODO: Tests for "move to output" and "move workspace to output".