2 # vim:ts=4:sw=4:expandtab
4 # Test if new containers get focused when there is a fullscreen container at
5 # the time of launching the new one. Also make sure that focusing containers
6 # in other workspaces work even when there is a fullscreen container.
10 my $i3 = i3(get_socket_path());
12 my $tmp = fresh_workspace;
14 ################################################################################
15 # Open the left window.
16 ################################################################################
18 my $left = open_window({ background_color => '#ff0000' });
20 is($x->input_focus, $left->id, 'left window focused');
22 diag("left = " . $left->id);
24 ################################################################################
25 # Open the right window.
26 ################################################################################
28 my $right = open_window({ background_color => '#00ff00' });
30 diag("right = " . $right->id);
32 ################################################################################
33 # Set the right window to fullscreen.
34 ################################################################################
36 cmd 'nop setting fullscreen';
39 ################################################################################
40 # Open a third window. Since we're fullscreen, the window won't be # mapped, so
41 # don't wait for it to be mapped. Instead, just send the map request and sync
42 # with i3 to make sure i3 recognizes it.
43 ################################################################################
45 my $third = open_window({
46 background_color => '#0000ff',
47 name => 'Third window',
55 diag("third = " . $third->id);
57 ################################################################################
58 # Move the window to a different workspace, and verify that the third window now
59 # gets focused in the current workspace.
60 ################################################################################
62 my $tmp2 = get_unused_workspace;
64 cmd "move workspace $tmp2";
66 is($x->input_focus, $third->id, 'third window focused');
68 ################################################################################
69 # Ensure that moving a window to a workspace which has a fullscreen window does
70 # not focus it (otherwise the user cannot get out of fullscreen mode anymore).
71 ################################################################################
73 $tmp = fresh_workspace;
75 my $fullscreen_window = open_window;
78 my $nodes = get_ws_content($tmp);
79 is(scalar @$nodes, 1, 'precisely one window');
80 is($nodes->[0]->{focused}, 1, 'fullscreen window focused');
81 my $old_id = $nodes->[0]->{id};
83 $tmp2 = fresh_workspace;
84 my $move_window = open_window;
85 cmd "move workspace $tmp";
89 $nodes = get_ws_content($tmp);
90 is(scalar @$nodes, 2, 'precisely two windows');
91 is($nodes->[0]->{id}, $old_id, 'id unchanged');
92 is($nodes->[0]->{focused}, 1, 'fullscreen window focused');
94 ################################################################################
95 # Ensure it's possible to change focus if it doesn't escape the fullscreen
96 # container with fullscreen global. We can't even focus a container in a
97 # different workspace.
98 ################################################################################
102 $tmp = fresh_workspace;
103 cmd "workspace $tmp";
104 my $diff_ws = open_window;
106 $tmp2 = fresh_workspace;
107 cmd "workspace $tmp2";
111 my $right1 = open_window;
113 my $right2 = open_window;
116 cmd 'fullscreen global';
118 cmd '[id="' . $right1->id . '"] focus';
119 is($x->input_focus, $right1->id, 'upper right window focused');
121 cmd '[id="' . $right2->id . '"] focus';
122 is($x->input_focus, $right2->id, 'bottom right window focused');
125 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
128 is($x->input_focus, $right2->id, 'bottom right window focused again');
130 cmd '[id="' . $left->id . '"] focus';
131 is($x->input_focus, $right2->id, 'prevented focus change to left window');
134 is($x->input_focus, $right1->id, 'allowed focus up');
137 is($x->input_focus, $right2->id, 'allowed focus down');
140 is($x->input_focus, $right2->id, 'prevented focus left');
143 is($x->input_focus, $right2->id, 'prevented focus right');
146 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
149 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
151 cmd '[id="' . $diff_ws->id . '"] focus';
152 is($x->input_focus, $right2->id, 'prevented focus change to different ws');
154 ################################################################################
155 # Same tests when we're in non-global fullscreen mode. It should now be possible
156 # to focus a container in a different workspace.
157 ################################################################################
160 cmd 'fullscreen global';
163 cmd '[id="' . $right1->id . '"] focus';
164 is($x->input_focus, $right1->id, 'upper right window focused');
166 cmd '[id="' . $right2->id . '"] focus';
167 is($x->input_focus, $right2->id, 'bottom right window focused');
170 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
173 is($x->input_focus, $right2->id, 'bottom right window focused again');
175 cmd '[id="' . $left->id . '"] focus';
176 is($x->input_focus, $right2->id, 'prevented focus change to left window');
179 is($x->input_focus, $right1->id, 'allowed focus up');
182 is($x->input_focus, $right2->id, 'allowed focus down');
185 is($x->input_focus, $right2->id, 'prevented focus left');
188 is($x->input_focus, $right2->id, 'prevented focus right');
191 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
194 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
196 cmd '[id="' . $diff_ws->id . '"] focus';
197 is($x->input_focus, $diff_ws->id, 'allowed focus change to different ws');
199 ################################################################################
200 # More testing of the interaction between wrapping and the fullscreen focus
202 ################################################################################
204 cmd '[id="' . $right1->id . '"] focus';
205 is($x->input_focus, $right1->id, 'upper right window focused');
212 my $right12 = open_window;
215 is($x->input_focus, $right2->id, 'bottom right window focused');
218 my $right22 = open_window;
225 is($x->input_focus, $right2->id, 'focus did not leave parent container (1)');
228 is($x->input_focus, $right22->id, 'focus did not leave parent container (2)');
231 is($x->input_focus, $right2->id, 'focus did not leave parent container (3)');
234 is($x->input_focus, $right22->id, 'focus did not leave parent container (4)');
236 ################################################################################
237 # Ensure that moving in a direction doesn't violate the focus restrictions.
238 ################################################################################
243 my $nodes = get_ws_content($tmp2);
244 my $split = $nodes->[1];
245 my $fs = $split->{nodes}->[1];
246 is(scalar @{$fs->{nodes}}, $num, $msg);
250 verify_move(2, 'prevented move left');
252 verify_move(2, 'prevented move right');
254 verify_move(2, 'prevented move down');
257 verify_move(2, 'prevented move up');
259 ################################################################################
260 # Moving to a different workspace is allowed with per-output fullscreen
262 ################################################################################
264 cmd "move to workspace $tmp";
265 verify_move(1, 'did not prevent move to workspace by name');
267 cmd "workspace $tmp";
268 cmd "move to workspace $tmp2";
269 cmd "workspace $tmp2";
271 cmd "move to workspace prev";
272 verify_move(1, 'did not prevent move to workspace by position');
274 ################################################################################
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";
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');
293 # TODO: Tests for "move to output" and "move workspace to output".