]> git.sur5r.net Git - i3/i3/blob - testcases/t/156-fullscreen-focus.t
Merge branch 'master' into next
[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_autostart => 0;
22
23 # Screen setup looks like this:
24 # +----+----+
25 # | S1 | S2 |
26 # +----+----+
27 my $config = <<EOT;
28 # i3 config file (v4)
29 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
30
31 fake-outputs 1024x768+0+0,1024x768+1024+0
32 EOT
33
34 my $pid = launch_with_config($config);
35
36 my $i3 = i3(get_socket_path());
37
38 my $tmp = fresh_workspace;
39
40 ################################################################################
41 # Open the left window.
42 ################################################################################
43
44 my $left = open_window({ background_color => '#ff0000' });
45
46 is($x->input_focus, $left->id, 'left window focused');
47
48 diag("left = " . $left->id);
49
50 ################################################################################
51 # Open the right window.
52 ################################################################################
53
54 my $right = open_window({ background_color => '#00ff00' });
55
56 diag("right = " . $right->id);
57
58 ################################################################################
59 # Set the right window to fullscreen.
60 ################################################################################
61
62 cmd 'nop setting fullscreen';
63 cmd 'fullscreen';
64
65 ################################################################################
66 # Open a third window. Since we're fullscreen, the window won't be # mapped, so
67 # don't wait for it to be mapped. Instead, just send the map request and sync
68 # with i3 to make sure i3 recognizes it.
69 ################################################################################
70
71 my $third = open_window({
72         background_color => '#0000ff',
73         name => 'Third window',
74         dont_map => 1,
75     });
76
77 $third->map;
78
79 sync_with_i3;
80
81 diag("third = " . $third->id);
82
83 ################################################################################
84 # Move the window to a different workspace, and verify that the third window now
85 # gets focused in the current workspace.
86 ################################################################################
87
88 my $tmp2 = get_unused_workspace;
89
90 cmd "move workspace $tmp2";
91
92 is($x->input_focus, $third->id, 'third window focused');
93
94 ################################################################################
95 # Ensure that moving a window to a workspace which has a fullscreen window does
96 # not focus it (otherwise the user cannot get out of fullscreen mode anymore).
97 ################################################################################
98
99 $tmp = fresh_workspace;
100
101 my $fullscreen_window = open_window;
102 cmd 'fullscreen';
103
104 my $nodes = get_ws_content($tmp);
105 is(scalar @$nodes, 1, 'precisely one window');
106 is($nodes->[0]->{focused}, 1, 'fullscreen window focused');
107 my $old_id = $nodes->[0]->{id};
108
109 $tmp2 = fresh_workspace;
110 my $move_window = open_window;
111 cmd "move workspace $tmp";
112
113 cmd "workspace $tmp";
114
115 $nodes = get_ws_content($tmp);
116 is(scalar @$nodes, 2, 'precisely two windows');
117 is($nodes->[0]->{id}, $old_id, 'id unchanged');
118 is($nodes->[0]->{focused}, 1, 'fullscreen window focused');
119
120 ################################################################################
121 # Ensure it's possible to change focus if it doesn't escape the fullscreen
122 # container with fullscreen global. We can't even focus a container in a
123 # different workspace.
124 ################################################################################
125
126 cmd 'fullscreen';
127
128 # Focus screen 1
129 $x->root->warp_pointer(1025, 0);
130 sync_with_i3;
131
132 $tmp = fresh_workspace;
133 cmd "workspace $tmp";
134 my $diff_ws = open_window;
135
136 # Focus screen 0
137 $x->root->warp_pointer(0, 0);
138 sync_with_i3;
139
140 $tmp2 = fresh_workspace;
141 cmd "workspace $tmp2";
142 cmd 'split h';
143
144 $left = open_window;
145 my $right1 = open_window;
146 cmd 'split v';
147 my $right2 = open_window;
148
149 cmd 'focus parent';
150 cmd 'fullscreen global';
151
152 cmd '[id="' . $right1->id . '"] focus';
153 is($x->input_focus, $right1->id, 'upper right window focused');
154
155 cmd '[id="' . $right2->id . '"] focus';
156 is($x->input_focus, $right2->id, 'bottom right window focused');
157
158 cmd 'focus parent';
159 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
160
161 cmd 'focus child';
162 is($x->input_focus, $right2->id, 'bottom right window focused again');
163
164 cmd '[id="' . $left->id . '"] focus';
165 is($x->input_focus, $right2->id, 'prevented focus change to left window');
166
167 cmd 'focus up';
168 is($x->input_focus, $right1->id, 'allowed focus up');
169
170 cmd 'focus down';
171 is($x->input_focus, $right2->id, 'allowed focus down');
172
173 cmd 'focus left';
174 is($x->input_focus, $right2->id, 'prevented focus left');
175
176 cmd 'focus right';
177 is($x->input_focus, $right2->id, 'prevented focus right');
178
179 cmd 'focus down';
180 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
181
182 cmd 'focus up';
183 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
184
185 cmd '[id="' . $diff_ws->id . '"] focus';
186 is($x->input_focus, $right2->id, 'prevented focus change to different ws');
187
188 ################################################################################
189 # Same tests when we're in non-global fullscreen mode. It should now be possible
190 # to focus a container in a different workspace.
191 ################################################################################
192
193 cmd 'focus parent';
194 cmd 'fullscreen global';
195 cmd 'fullscreen';
196
197 cmd '[id="' . $right1->id . '"] focus';
198 is($x->input_focus, $right1->id, 'upper right window focused');
199
200 cmd '[id="' . $right2->id . '"] focus';
201 is($x->input_focus, $right2->id, 'bottom right window focused');
202
203 cmd 'focus parent';
204 isnt($x->input_focus, $right2->id, 'bottom right window no longer focused');
205
206 cmd 'focus child';
207 is($x->input_focus, $right2->id, 'bottom right window focused again');
208
209 cmd '[id="' . $left->id . '"] focus';
210 is($x->input_focus, $right2->id, 'prevented focus change to left window');
211
212 cmd 'focus up';
213 is($x->input_focus, $right1->id, 'allowed focus up');
214
215 cmd 'focus down';
216 is($x->input_focus, $right2->id, 'allowed focus down');
217
218 cmd 'focus down';
219 is($x->input_focus, $right1->id, 'allowed focus wrap (down)');
220
221 cmd 'focus up';
222 is($x->input_focus, $right2->id, 'allowed focus wrap (up)');
223
224 cmd 'focus left';
225 is($x->input_focus, $right2->id, 'focus left wrapped (no-op)');
226
227 cmd 'focus right';
228 is($x->input_focus, $diff_ws->id, 'allowed focus change to different ws');
229
230 cmd 'focus left';
231 is($x->input_focus, $right2->id, 'focused back into fullscreen container');
232
233 cmd '[id="' . $diff_ws->id . '"] focus';
234 is($x->input_focus, $diff_ws->id, 'allowed focus change to different ws by id');
235
236 ################################################################################
237 # More testing of the interaction between wrapping and the fullscreen focus
238 # restrictions.
239 ################################################################################
240
241 cmd '[id="' . $right1->id . '"] focus';
242 is($x->input_focus, $right1->id, 'upper right window focused');
243
244 cmd 'focus parent';
245 cmd 'fullscreen';
246 cmd 'focus child';
247
248 cmd 'split v';
249 my $right12 = open_window;
250
251 cmd 'focus down';
252 is($x->input_focus, $right2->id, 'bottom right window focused');
253
254 cmd 'split v';
255 my $right22 = open_window;
256
257 cmd 'focus parent';
258 cmd 'fullscreen';
259 cmd 'focus child';
260
261 cmd 'focus down';
262 is($x->input_focus, $right2->id, 'focus did not leave parent container (1)');
263
264 cmd 'focus down';
265 is($x->input_focus, $right22->id, 'focus did not leave parent container (2)');
266
267 cmd 'focus up';
268 is($x->input_focus, $right2->id, 'focus did not leave parent container (3)');
269
270 cmd 'focus up';
271 is($x->input_focus, $right22->id, 'focus did not leave parent container (4)');
272
273 ################################################################################
274 # Ensure that moving in a direction doesn't violate the focus restrictions.
275 ################################################################################
276
277 sub verify_move {
278     my $num = shift;
279     my $msg = shift;
280     my $nodes = get_ws_content($tmp2);
281     my $split = $nodes->[1];
282     my $fs = $split->{nodes}->[1];
283     is(scalar @{$fs->{nodes}}, $num, $msg);
284 }
285
286 cmd 'move left';
287 verify_move(2, 'prevented move left');
288 cmd 'move right';
289 verify_move(2, 'prevented move right');
290 cmd 'move down';
291 verify_move(2, 'prevented move down');
292 cmd 'move up';
293 cmd 'move up';
294 verify_move(2, 'prevented move up');
295
296 ################################################################################
297 # Moving to a different workspace is allowed with per-output fullscreen
298 # containers.
299 ################################################################################
300
301 cmd "move to workspace $tmp";
302 verify_move(1, 'did not prevent move to workspace by name');
303
304 cmd "workspace $tmp";
305 cmd "move to workspace $tmp2";
306 cmd "workspace $tmp2";
307
308 cmd "move to workspace prev";
309 verify_move(1, 'did not prevent move to workspace by position');
310
311 ################################################################################
312 # Ensure that is not allowed with global fullscreen containers.
313 ################################################################################
314
315 cmd "workspace $tmp";
316 cmd "move to workspace $tmp2";
317 cmd "workspace $tmp2";
318
319 cmd 'focus parent';
320 cmd 'fullscreen';
321 cmd 'fullscreen global';
322 cmd 'focus child';
323
324 cmd "move to workspace $tmp";
325 verify_move(2, 'prevented move to workspace by name');
326
327 cmd "move to workspace prev";
328 verify_move(2, 'prevented move to workspace by position');
329
330 # TODO: Tests for "move to output" and "move workspace to output".
331
332 exit_gracefully($pid);
333
334 done_testing;