]> git.sur5r.net Git - i3/i3/blob - testcases/t/100-fullscreen.t
Extend the fullscreen command
[i3/i3] / testcases / t / 100-fullscreen.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 use i3test;
18 use List::Util qw(first);
19
20 my $i3 = i3(get_socket_path());
21
22 my $tmp = fresh_workspace;
23
24 sub fullscreen_windows {
25     my $ws = $tmp;
26     $ws = shift if @_;
27
28     scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($ws)}
29 }
30
31 # get the output of this workspace
32 my $tree = $i3->get_tree->recv;
33 my @outputs = @{$tree->{nodes}};
34 my $output;
35 for my $o (@outputs) {
36     # get the first CT_CON of each output
37     my $content = first { $_->{type} eq 'con' } @{$o->{nodes}};
38     if (defined(first { $_->{name} eq $tmp } @{$content->{nodes}})) {
39         $output = $o;
40         last;
41     }
42 }
43
44 ##################################
45 # map a window, then fullscreen it
46 ##################################
47
48 my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
49
50 my $window = open_window(
51     rect => $original_rect,
52     dont_map => 1,
53 );
54
55 isa_ok($window, 'X11::XCB::Window');
56
57 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
58
59 $window->map;
60
61 wait_for_map $window;
62
63 # open another container to make the window get only half of the screen
64 cmd 'open';
65
66 my $new_rect = $window->rect;
67 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned");
68 $original_rect = $new_rect;
69
70 $window->fullscreen(1);
71
72 sync_with_i3;
73
74 $new_rect = $window->rect;
75 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned after fullscreen");
76
77 my $orect = $output->{rect};
78 my $wrect = $new_rect;
79
80 # see if the window really is fullscreen. 20 px for borders are allowed
81 my $threshold = 20;
82 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
83 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
84 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
85 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
86
87
88 $window->unmap;
89
90 #########################################################
91 # test with a window which is fullscreened before mapping
92 #########################################################
93
94 # open another container because the empty one will swallow the window we
95 # map in a second
96 cmd 'open';
97
98 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
99 $window = open_window(
100     rect => $original_rect,
101     dont_map => 1,
102 );
103
104 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
105
106 $window->fullscreen(1);
107 $window->map;
108
109 wait_for_map $window;
110
111 $new_rect = $window->rect;
112 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned after fullscreen");
113 ok($window->mapped, "Window is mapped after opening it in fullscreen mode");
114
115 $wrect = $new_rect;
116
117 # see if the window really is fullscreen. 20 px for borders are allowed
118 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
119 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
120 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
121 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
122
123 ################################################################################
124 # Verify that when one window wants to go into fullscreen mode, the old
125 # fullscreen window will be replaced.
126 ################################################################################
127
128 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
129 my $swindow = open_window(
130     rect => $original_rect,
131     dont_map => 1,
132 );
133
134 $swindow->map;
135
136 sync_with_i3;
137
138 ok(!$swindow->mapped, 'window not mapped while fullscreen window active');
139
140 $new_rect = $swindow->rect;
141 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned");
142
143 $swindow->fullscreen(1);
144 sync_with_i3;
145
146 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
147
148 $window->fullscreen(0);
149 sync_with_i3;
150 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
151
152 ok($swindow->mapped, 'window mapped after other fullscreen ended');
153
154 ###########################################################################
155 # as $swindow is out of state at the moment (it requested to be fullscreen,
156 # but the WM denied), we check what happens if we go out of fullscreen now
157 # (nothing should happen)
158 ###########################################################################
159
160 $swindow->fullscreen(0);
161 sync_with_i3;
162
163 is(fullscreen_windows(), 0, 'amount of fullscreen windows after disabling');
164
165 cmd 'fullscreen';
166
167 is(fullscreen_windows(), 1, 'amount of fullscreen windows after fullscreen command');
168
169 cmd 'fullscreen';
170
171 is(fullscreen_windows(), 0, 'amount of fullscreen windows after fullscreen command');
172
173 # clean up the workspace so that it will be cleaned when switching away
174 cmd 'kill' for (@{get_ws_content($tmp)});
175
176 ################################################################################
177 # Verify that changing focus while in fullscreen does not work.
178 ################################################################################
179
180 $tmp = fresh_workspace;
181
182 my $other = open_window;
183 is($x->input_focus, $other->id, 'other window focused');
184
185 $window = open_window;
186 is($x->input_focus, $window->id, 'window focused');
187
188 cmd 'fullscreen';
189 is($x->input_focus, $window->id, 'fullscreen window focused');
190
191 cmd 'focus left';
192 is($x->input_focus, $window->id, 'fullscreen window still focused');
193
194 ################################################################################
195 # Verify that changing workspace while in global fullscreen does not work.
196 ################################################################################
197
198 $tmp = fresh_workspace;
199 $window = open_window;
200
201 cmd 'fullscreen global';
202 is($x->input_focus, $window->id, 'window focused');
203 is(focused_ws(), $tmp, 'workspace selected');
204
205 $other = get_unused_workspace;
206 cmd "workspace $other";
207 is($x->input_focus, $window->id, 'window still focused');
208 is(focused_ws(), $tmp, 'workspace still selected');
209
210 # leave global fullscreen so that is does not interfere with the other tests
211 $window->fullscreen(0);
212 sync_with_i3;
213
214 ################################################################################
215 # Verify that fullscreening a window on a second workspace and moving it onto
216 # the first workspace unfullscreens the first window.
217 ################################################################################
218
219 my $tmp2 = fresh_workspace;
220 $swindow = open_window;
221
222 cmd 'fullscreen';
223
224 is(fullscreen_windows($tmp2), 1, 'one fullscreen window on second ws');
225
226 cmd "move workspace $tmp";
227
228 is(fullscreen_windows($tmp2), 0, 'no fullscreen windows on second ws');
229 is(fullscreen_windows($tmp), 1, 'one fullscreen window on first ws');
230
231 $swindow->fullscreen(0);
232 sync_with_i3;
233
234 # Verify that $swindow was the one that initially remained fullscreen.
235 is(fullscreen_windows($tmp), 0, 'no fullscreen windows on first ws');
236
237 ################################################################################
238 # Verify that opening a window with _NET_WM_STATE_FULLSCREEN unfullscreens any
239 # existing container on the workspace and fullscreens the newly opened window.
240 ################################################################################
241
242 $tmp = fresh_workspace;
243
244 $window = open_window();
245
246 cmd "fullscreen";
247
248 is(fullscreen_windows($tmp), 1, 'one fullscreen window on ws');
249 is($x->input_focus, $window->id, 'fullscreen window focused');
250
251 $swindow = open_window({
252     fullscreen => 1
253 });
254
255 is(fullscreen_windows($tmp), 1, 'one fullscreen window on ws');
256 is($x->input_focus, $swindow->id, 'fullscreen window focused');
257
258 ################################################################################
259 # Verify that command ‘fullscreen enable’ works and is idempotent.
260 ################################################################################
261
262 $tmp = fresh_workspace;
263
264 $window = open_window;
265 is($x->input_focus, $window->id, 'window focused');
266 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
267
268 cmd 'fullscreen enable';
269 is($x->input_focus, $window->id, 'window still focused');
270 is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace');
271
272 cmd 'fullscreen enable';
273 is($x->input_focus, $window->id, 'window still focused');
274 is(fullscreen_windows($tmp), 1, 'still one fullscreen window on workspace');
275
276 $window->fullscreen(0);
277 sync_with_i3;
278 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
279
280 ################################################################################
281 # Verify that command ‘fullscreen enable global’ works and is idempotent.
282 ################################################################################
283
284 $tmp = fresh_workspace;
285
286 $window = open_window;
287 is($x->input_focus, $window->id, 'window focused');
288 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
289
290 cmd 'fullscreen enable global';
291 is($x->input_focus, $window->id, 'window still focused');
292 is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace');
293
294 cmd 'fullscreen enable global';
295 is($x->input_focus, $window->id, 'window still focused');
296 is(fullscreen_windows($tmp), 1, 'still one fullscreen window on workspace');
297
298 $window->fullscreen(0);
299 sync_with_i3;
300 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
301
302 ################################################################################
303 # Verify that command ‘fullscreen disable’ works and is idempotent.
304 ################################################################################
305
306 $tmp = fresh_workspace;
307
308 $window = open_window;
309 is($x->input_focus, $window->id, 'window focused');
310 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
311
312 $window->fullscreen(1);
313 sync_with_i3;
314 is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace');
315
316 cmd 'fullscreen disable';
317 is($x->input_focus, $window->id, 'window still focused');
318 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
319
320 cmd 'fullscreen disable';
321 is($x->input_focus, $window->id, 'window still focused');
322 is(fullscreen_windows($tmp), 0, 'still no fullscreen window on workspace');
323
324 ################################################################################
325 # Verify that command ‘fullscreen toggle’ works.
326 ################################################################################
327
328 $tmp = fresh_workspace;
329
330 $window = open_window;
331 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
332
333 cmd 'fullscreen toggle';
334 is($x->input_focus, $window->id, 'window still focused');
335 is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace');
336
337 cmd 'fullscreen toggle';
338 is($x->input_focus, $window->id, 'window still focused');
339 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
340
341 ################################################################################
342 # Verify that a window’s fullscreen is disabled when another one is enabled
343 # on the same workspace. The new fullscreen window should be focused.
344 ################################################################################
345
346 $tmp = fresh_workspace;
347
348 $window = open_window;
349 $other = open_window;
350
351 is($x->input_focus, $other->id, 'other window focused');
352 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
353
354 cmd 'fullscreen enable';
355 is($x->input_focus, $other->id, 'other window focused');
356 is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace');
357
358 cmd '[id="' . $window->id . '"] fullscreen enable';
359 is($x->input_focus, $window->id, 'window focused');
360 is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace');
361
362 ################################################################################
363 # Verify that when a global fullscreen is enabled the window is focused and
364 # its workspace is selected, so that disabling the fullscreen keeps the window
365 # focused and visible.
366 ################################################################################
367
368 $tmp = fresh_workspace;
369
370 $window = open_window;
371
372 is($x->input_focus, $window->id, 'window focused');
373
374 cmd 'workspace ' . get_unused_workspace;
375 isnt($x->input_focus, $window->id, 'window not focused');
376 isnt(focused_ws(), $tmp, 'workspace not selected');
377
378 cmd '[id="' . $window->id . '"] fullscreen enable global';
379 is($x->input_focus, $window->id, 'window focused');
380
381 cmd 'fullscreen disable';
382 is($x->input_focus, $window->id, 'window still focused');
383 is(focused_ws(), $tmp, 'workspace selected');
384
385 done_testing;