]> git.sur5r.net Git - i3/i3/blob - testcases/t/156-fullscreen-focus.t
tests: use i3_config arg instead of precisely one launch_with_config
[i3/i3] / testcases / t / 156-fullscreen-focus.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
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.
20 #
21 use i3test i3_config => <<EOT;
22 # i3 config file (v4)
23 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
24
25 fake-outputs 1024x768+0+0,1024x768+1024+0
26 EOT
27 # Screen setup looks like this:
28 # +----+----+
29 # | S1 | S2 |
30 # +----+----+
31
32 my $tmp = fresh_workspace;
33
34 ################################################################################
35 # Open the left window.
36 ################################################################################
37
38 my $left = open_window({ background_color => '#ff0000' });
39
40 is($x->input_focus, $left->id, 'left window focused');
41
42 diag("left = " . $left->id);
43
44 ################################################################################
45 # Open the right window.
46 ################################################################################
47
48 my $right = open_window({ background_color => '#00ff00' });
49
50 diag("right = " . $right->id);
51
52 ################################################################################
53 # Set the right window to fullscreen.
54 ################################################################################
55
56 cmd 'nop setting fullscreen';
57 cmd 'fullscreen';
58
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 ################################################################################
64
65 my $third = open_window({
66         background_color => '#0000ff',
67         name => 'Third window',
68         dont_map => 1,
69     });
70
71 $third->map;
72
73 sync_with_i3;
74
75 diag("third = " . $third->id);
76
77 ################################################################################
78 # Move the window to a different workspace, and verify that the third window now
79 # gets focused in the current workspace.
80 ################################################################################
81
82 my $tmp2 = get_unused_workspace;
83
84 cmd "move workspace $tmp2";
85
86 is($x->input_focus, $third->id, 'third window focused');
87
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 ################################################################################
92
93 $tmp = fresh_workspace;
94
95 my $fullscreen_window = open_window;
96 cmd 'fullscreen';
97
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};
102
103 $tmp2 = fresh_workspace;
104 my $move_window = open_window;
105 cmd "move workspace $tmp";
106
107 cmd "workspace $tmp";
108
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');
113
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 ################################################################################
119
120 cmd 'fullscreen';
121
122 # Focus screen 1
123 sync_with_i3;
124 $x->root->warp_pointer(1025, 0);
125 sync_with_i3;
126
127 $tmp = fresh_workspace;
128 cmd "workspace $tmp";
129 my $diff_ws = open_window;
130
131 # Focus screen 0
132 sync_with_i3;
133 $x->root->warp_pointer(0, 0);
134 sync_with_i3;
135
136 $tmp2 = fresh_workspace;
137 cmd "workspace $tmp2";
138 cmd 'split h';
139
140 $left = open_window;
141 my $right1 = open_window;
142 cmd 'split v';
143 my $right2 = open_window;
144
145 cmd 'focus parent';
146 cmd 'fullscreen global';
147
148 cmd '[id="' . $right1->id . '"] focus';
149 is($x->input_focus, $right1->id, 'upper right window focused');
150
151 cmd '[id="' . $right2->id . '"] focus';
152 is($x->input_focus, $right2->id, 'bottom right window focused');
153
154 cmd 'focus parent';
155 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
156
157 cmd 'focus child';
158 is($x->input_focus, $right2->id, 'bottom right window focused again');
159
160 cmd '[id="' . $left->id . '"] focus';
161 is($x->input_focus, $right2->id, 'prevented focus change to left window');
162
163 cmd 'focus up';
164 is($x->input_focus, $right1->id, 'allowed focus up');
165
166 cmd 'focus down';
167 is($x->input_focus, $right2->id, 'allowed focus down');
168
169 cmd 'focus left';
170 is($x->input_focus, $right2->id, 'prevented focus left');
171
172 cmd 'focus right';
173 is($x->input_focus, $right2->id, 'prevented focus right');
174
175 cmd 'focus down';
176 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
177
178 cmd 'focus up';
179 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
180
181 cmd '[id="' . $diff_ws->id . '"] focus';
182 is($x->input_focus, $right2->id, 'prevented focus change to different ws');
183
184 ################################################################################
185 # Same tests when we're in non-global fullscreen mode. It should now be possible
186 # to focus a container in a different workspace.
187 ################################################################################
188
189 cmd 'focus parent';
190 cmd 'fullscreen global';
191 cmd 'fullscreen';
192
193 cmd '[id="' . $right1->id . '"] focus';
194 is($x->input_focus, $right1->id, 'upper right window focused');
195
196 cmd '[id="' . $right2->id . '"] focus';
197 is($x->input_focus, $right2->id, 'bottom right window focused');
198
199 cmd 'focus parent';
200 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
201
202 cmd 'focus child';
203 is($x->input_focus, $right2->id, 'bottom right window focused again');
204
205 cmd '[id="' . $left->id . '"] focus';
206 is($x->input_focus, $right2->id, 'prevented focus change to left window');
207
208 cmd 'focus up';
209 is($x->input_focus, $right1->id, 'allowed focus up');
210
211 cmd 'focus down';
212 is($x->input_focus, $right2->id, 'allowed focus down');
213
214 cmd 'focus down';
215 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
216
217 cmd 'focus up';
218 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
219
220 cmd 'focus left';
221 is($x->input_focus, $right2->id, 'focus left wrapped (no-op)');
222
223 cmd 'focus right';
224 is($x->input_focus, $diff_ws->id, 'allowed focus change to different ws');
225
226 cmd 'focus left';
227 is($x->input_focus, $right2->id, 'focused back into fullscreen container');
228
229 cmd '[id="' . $diff_ws->id . '"] focus';
230 is($x->input_focus, $diff_ws->id, 'allowed focus change to different ws by id');
231
232 ################################################################################
233 # More testing of the interaction between wrapping and the fullscreen focus
234 # restrictions.
235 ################################################################################
236
237 cmd '[id="' . $right1->id . '"] focus';
238 is($x->input_focus, $right1->id, 'upper right window focused');
239
240 cmd 'focus parent';
241 cmd 'fullscreen';
242 cmd 'focus child';
243
244 cmd 'split v';
245 my $right12 = open_window;
246
247 cmd 'focus down';
248 is($x->input_focus, $right2->id, 'bottom right window focused');
249
250 cmd 'split v';
251 my $right22 = open_window;
252
253 cmd 'focus parent';
254 cmd 'fullscreen';
255 cmd 'focus child';
256
257 cmd 'focus down';
258 is($x->input_focus, $right2->id, 'focus did not leave parent container (1)');
259
260 cmd 'focus down';
261 is($x->input_focus, $right22->id, 'focus did not leave parent container (2)');
262
263 cmd 'focus up';
264 is($x->input_focus, $right2->id, 'focus did not leave parent container (3)');
265
266 cmd 'focus up';
267 is($x->input_focus, $right22->id, 'focus did not leave parent container (4)');
268
269 ################################################################################
270 # Ensure that moving in a direction doesn't violate the focus restrictions.
271 ################################################################################
272
273 sub verify_move {
274     my $num = shift;
275     my $msg = shift;
276     my $nodes = get_ws_content($tmp2);
277     my $split = $nodes->[1];
278     my $fs = $split->{nodes}->[1];
279     is(scalar @{$fs->{nodes}}, $num, $msg);
280 }
281
282 cmd 'move left';
283 verify_move(2, 'prevented move left');
284 cmd 'move right';
285 verify_move(2, 'prevented move right');
286 cmd 'move down';
287 verify_move(2, 'prevented move down');
288 cmd 'move up';
289 cmd 'move up';
290 verify_move(2, 'prevented move up');
291
292 ################################################################################
293 # Moving to a different workspace is allowed with per-output fullscreen
294 # containers.
295 ################################################################################
296
297 cmd "move to workspace $tmp";
298 verify_move(1, 'did not prevent move to workspace by name');
299
300 cmd "workspace $tmp";
301 cmd "move to workspace $tmp2";
302 cmd "workspace $tmp2";
303
304 cmd "move to workspace prev";
305 verify_move(1, 'did not prevent move to workspace by position');
306
307 ################################################################################
308 # Ensure that is not allowed with global fullscreen containers.
309 ################################################################################
310
311 cmd "workspace $tmp";
312 cmd "move to workspace $tmp2";
313 cmd "workspace $tmp2";
314
315 cmd 'focus parent';
316 cmd 'fullscreen';
317 cmd 'fullscreen global';
318 cmd 'focus child';
319
320 cmd "move to workspace $tmp";
321 verify_move(2, 'prevented move to workspace by name');
322
323 cmd "move to workspace prev";
324 verify_move(2, 'prevented move to workspace by position');
325
326 # TODO: Tests for "move to output" and "move workspace to output".
327
328 done_testing;