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:
33 # Report original line
34 local $Test::Builder::Level = $Test::Builder::Level + 1;
36 my ($expected, $msg) = @_;
37 $expected = $expected->id;
39 # Ensure the expected focus if the test fails.
40 cmd "[id=$expected] focus" unless is($x->input_focus, $expected, $msg);
43 ################################################################################
44 # Verify that window opened behind fullscreen window will get focus after the
45 # fullscreen window gets moved to a different workspace.
46 ################################################################################
49 my $left = open_window;
50 verify_focus($left, 'left window focused');
51 diag("left = " . $left->id);
53 my $right = open_window;
55 diag("right = " . $right->id);
57 # Open a third window. Since we're fullscreen, the window won't be mapped, so
58 # don't wait for it to be mapped. Instead, just send the map request and sync
59 # with i3 to make sure i3 recognizes it.
60 my $third = open_window({dont_map => 1});
63 diag("third = " . $third->id);
65 # Move the window to a different workspace, and verify that the third window now
66 # gets focused in the current workspace.
67 my $tmp2 = get_unused_workspace;
68 cmd "move workspace $tmp2";
69 verify_focus($third, 'third window focused');
73 ################################################################################
74 # Ensure that moving a window to a workspace which has a fullscreen window does
75 # not focus it (otherwise the user cannot get out of fullscreen mode anymore).
76 ################################################################################
78 my $tmp = fresh_workspace;
83 my $nodes = get_ws_content($tmp);
84 is(scalar @$nodes, 1, 'precisely one window');
85 is($nodes->[0]->{focused}, 1, 'fullscreen window focused');
86 my $old_id = $nodes->[0]->{id};
88 $tmp2 = fresh_workspace;
89 my $move_window = open_window;
90 cmd "move workspace $tmp";
94 $nodes = get_ws_content($tmp);
95 is(scalar @$nodes, 2, 'precisely two windows');
96 is($nodes->[0]->{id}, $old_id, 'id unchanged');
97 is($nodes->[0]->{focused}, 1, 'fullscreen window focused');
101 ################################################################################
102 # Ensure it's possible to change focus if it doesn't escape the fullscreen
103 # container with fullscreen global. We can't even focus a container in a
104 # different workspace.
105 ################################################################################
107 $tmp = fresh_workspace(output => 1);
108 my $diff_ws = open_window;
110 $tmp2 = fresh_workspace(output => 0);
112 my $right1 = open_window;
114 my $right2 = open_window;
117 cmd 'fullscreen global';
119 cmd '[id="' . $right1->id . '"] focus';
120 verify_focus($right1, 'upper right window focused');
122 cmd '[id="' . $right2->id . '"] focus';
123 verify_focus($right2, 'bottom right window focused');
126 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
129 verify_focus($right2, 'bottom right window focused again');
132 verify_focus($right1, 'allowed focus up');
135 verify_focus($right2, 'allowed focus down');
138 verify_focus($right2, 'prevented focus left');
141 verify_focus($right2, 'prevented focus right');
144 verify_focus($right1, 'allowed focus wrap (down)');
147 verify_focus($right2, 'allowed focus wrap (up)');
149 ################################################################################
150 # (depends on previous layout)
151 # Same tests when we're in non-global fullscreen mode. It should now be possible
152 # to focus a container in a different workspace.
153 ################################################################################
156 cmd 'fullscreen disable';
159 cmd '[id="' . $right1->id . '"] focus';
160 verify_focus($right1, 'upper right window focused');
162 cmd '[id="' . $right2->id . '"] focus';
163 verify_focus($right2, 'bottom right window focused');
166 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
169 verify_focus($right2, 'bottom right window focused again');
172 verify_focus($right1, 'allowed focus up');
175 verify_focus($right2, 'allowed focus down');
178 verify_focus($right1, 'allowed focus wrap (down)');
181 verify_focus($right2, 'allowed focus wrap (up)');
184 verify_focus($right2, 'focus left wrapped (no-op)');
187 verify_focus($diff_ws, 'allowed focus change to different ws');
190 verify_focus($right2, 'focused back into fullscreen container');
192 cmd '[id="' . $diff_ws->id . '"] focus';
193 verify_focus($diff_ws, 'allowed focus change to different ws by id');
195 ################################################################################
196 # (depends on previous layout)
197 # More testing of the interaction between wrapping and the fullscreen focus
199 ################################################################################
201 cmd '[id="' . $right1->id . '"] focus';
202 verify_focus($right1, 'upper right window focused');
205 cmd 'fullscreen disable';
209 my $right12 = open_window;
212 verify_focus($right2, 'bottom right window focused');
215 my $right22 = open_window;
222 verify_focus($right2, 'focus did not leave parent container (1)');
225 verify_focus($right22, 'focus did not leave parent container (2)');
228 verify_focus($right2, 'focus did not leave parent container (3)');
231 verify_focus($right22, 'focus did not leave parent container (4)');
233 ################################################################################
234 # (depends on previous layout)
235 # Ensure that moving in a direction doesn't violate the focus restrictions.
236 ################################################################################
241 my $nodes = get_ws_content($tmp2);
242 my $split = $nodes->[1];
243 my $fs = $split->{nodes}->[1];
244 is(scalar @{$fs->{nodes}}, $num, $msg);
248 verify_move(2, 'prevented move left');
250 verify_move(2, 'prevented move right');
252 verify_move(2, 'prevented move down');
255 verify_move(2, 'prevented move up');
257 ################################################################################
258 # (depends on previous layout)
259 # Moving to a different workspace is allowed with per-output fullscreen
261 ################################################################################
263 cmd "move to workspace $tmp";
264 verify_move(1, 'did not prevent move to workspace by name');
266 cmd "workspace $tmp";
267 cmd "move to workspace $tmp2";
268 cmd "workspace $tmp2";
270 cmd "move to workspace prev";
271 verify_move(1, 'did not prevent move to workspace by position');
273 ################################################################################
274 # (depends on previous layout)
275 # Ensure that is not allowed with global fullscreen containers.
276 ################################################################################
278 cmd "workspace $tmp";
279 cmd "move to workspace $tmp2";
280 cmd "workspace $tmp2";
283 cmd 'fullscreen disable';
284 cmd 'fullscreen global';
287 cmd "move to workspace $tmp";
288 verify_move(2, 'prevented move to workspace by name');
290 cmd "move to workspace prev";
291 verify_move(2, 'prevented move to workspace by position');
295 ################################################################################
296 # Ensure it's possible to focus a window using the focus command despite
297 # fullscreen window blocking it. Fullscreen window should lose its fullscreen
299 ################################################################################
301 # first & second tiling, focus using id
302 $tmp = fresh_workspace;
303 my $first = open_window;
304 my $second = open_window;
306 verify_focus($second, 'fullscreen window focused');
307 is_num_fullscreen($tmp, 1, '1 fullscreen window');
309 cmd '[id="' . $first->id . '"] focus';
312 verify_focus($first, 'correctly focused using id');
313 is_num_fullscreen($tmp, 0, 'no fullscreen windows');
317 # first floating, second tiling, focus using 'focus floating'
318 $tmp = fresh_workspace;
319 $first = open_floating_window;
320 $second = open_window;
322 verify_focus($second, 'fullscreen window focused');
323 is_num_fullscreen($tmp, 1, '1 fullscreen window');
325 cmd 'focus floating';
328 verify_focus($first, 'correctly focused using focus floating');
329 is_num_fullscreen($tmp, 0, 'no fullscreen windows');
333 # first tiling, second floating, focus using 'focus tiling'
334 $tmp = fresh_workspace;
335 $first = open_window;
336 $second = open_floating_window;
338 verify_focus($second, 'fullscreen window focused');
339 is_num_fullscreen($tmp, 1, '1 fullscreen window');
344 verify_focus($first, 'correctly focused using focus tiling');
345 is_num_fullscreen($tmp, 0, 'no fullscreen windows');
349 ################################################################################
350 # When the fullscreen window is in an other workspace it should maintain its
351 # fullscreen mode since it's not blocking the window to be focused.
352 ################################################################################
354 $tmp = fresh_workspace;
355 $first = open_window;
357 $tmp2 = fresh_workspace;
358 $second = open_window;
360 verify_focus($second, 'fullscreen window focused');
361 is_num_fullscreen($tmp2, 1, '1 fullscreen window');
363 cmd '[id="' . $first->id . '"] focus';
366 verify_focus($first, 'correctly focused using focus id');
367 is_num_fullscreen($tmp, 0, 'no fullscreen windows on first workspace');
368 is_num_fullscreen($tmp2, 1, 'still one fullscreen window on second workspace');
372 ################################################################################
373 # But a global window in another workspace is blocking the window to be focused.
374 # Ensure that it loses its fullscreen mode.
375 ################################################################################
377 $tmp = fresh_workspace;
378 $first = open_window;
380 $tmp2 = fresh_workspace;
381 $second = open_window;
382 cmd 'fullscreen global';
383 verify_focus($second, 'global window focused');
384 is_num_fullscreen($tmp2, 1, '1 fullscreen window');
386 cmd '[id="' . $first->id . '"] focus';
389 verify_focus($first, 'correctly focused using focus id');
390 is_num_fullscreen($tmp2, 0, 'no fullscreen windows');
393 # TODO: Tests for "move to output" and "move workspace to output".