2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://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)
18 use List::Util qw(first);
20 my $i3 = i3(get_socket_path());
22 my $tmp = fresh_workspace;
24 sub fullscreen_windows {
28 scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($ws)}
31 # get the output of this workspace
32 my $tree = $i3->get_tree->recv;
33 my @outputs = @{$tree->{nodes}};
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}})) {
44 ##################################
45 # map a window, then fullscreen it
46 ##################################
48 my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
50 my $window = open_window(
51 rect => $original_rect,
55 isa_ok($window, 'X11::XCB::Window');
57 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
63 # open another container to make the window get only half of the screen
66 my $new_rect = $window->rect;
67 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned");
68 $original_rect = $new_rect;
70 $window->fullscreen(1);
74 $new_rect = $window->rect;
75 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned after fullscreen");
77 my $orect = $output->{rect};
78 my $wrect = $new_rect;
80 # see if the window really is fullscreen. 20 px for borders are allowed
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');
90 #########################################################
91 # test with a window which is fullscreened before mapping
92 #########################################################
94 # open another container because the empty one will swallow the window we
98 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
99 $window = open_window(
100 rect => $original_rect,
104 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
106 $window->fullscreen(1);
109 wait_for_map $window;
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");
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');
123 ################################################################################
124 # Verify that when one window wants to go into fullscreen mode, the old
125 # fullscreen window will be replaced.
126 ################################################################################
128 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
129 my $swindow = open_window(
130 rect => $original_rect,
138 ok(!$swindow->mapped, 'window not mapped while fullscreen window active');
140 $new_rect = $swindow->rect;
141 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned");
143 $swindow->fullscreen(1);
146 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
148 $window->fullscreen(0);
150 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
152 ok($swindow->mapped, 'window mapped after other fullscreen ended');
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 ###########################################################################
160 $swindow->fullscreen(0);
163 is(fullscreen_windows(), 0, 'amount of fullscreen windows after disabling');
167 is(fullscreen_windows(), 1, 'amount of fullscreen windows after fullscreen command');
171 is(fullscreen_windows(), 0, 'amount of fullscreen windows after fullscreen command');
173 # clean up the workspace so that it will be cleaned when switching away
174 cmd 'kill' for (@{get_ws_content($tmp)});
176 ################################################################################
177 # Verify that changing focus while in fullscreen does not work.
178 ################################################################################
180 $tmp = fresh_workspace;
182 my $other = open_window;
183 is($x->input_focus, $other->id, 'other window focused');
185 $window = open_window;
186 is($x->input_focus, $window->id, 'window focused');
189 is($x->input_focus, $window->id, 'fullscreen window focused');
192 is($x->input_focus, $window->id, 'fullscreen window still focused');
194 ################################################################################
195 # Verify that changing workspace while in global fullscreen does not work.
196 ################################################################################
198 $tmp = fresh_workspace;
199 $window = open_window;
201 cmd 'fullscreen global';
202 is($x->input_focus, $window->id, 'window focused');
203 is(focused_ws(), $tmp, 'workspace selected');
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');
210 # leave global fullscreen so that is does not interfere with the other tests
211 $window->fullscreen(0);
214 ################################################################################
215 # Verify that fullscreening a window on a second workspace and moving it onto
216 # the first workspace unfullscreens the first window.
217 ################################################################################
219 my $tmp2 = fresh_workspace;
220 $swindow = open_window;
224 is(fullscreen_windows($tmp2), 1, 'one fullscreen window on second ws');
226 cmd "move workspace $tmp";
228 is(fullscreen_windows($tmp2), 0, 'no fullscreen windows on second ws');
229 is(fullscreen_windows($tmp), 1, 'one fullscreen window on first ws');
231 $swindow->fullscreen(0);
234 # Verify that $swindow was the one that initially remained fullscreen.
235 is(fullscreen_windows($tmp), 0, 'no fullscreen windows on first ws');
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 ################################################################################
242 $tmp = fresh_workspace;
244 $window = open_window();
248 is(fullscreen_windows($tmp), 1, 'one fullscreen window on ws');
249 is($x->input_focus, $window->id, 'fullscreen window focused');
251 $swindow = open_window({
255 is(fullscreen_windows($tmp), 1, 'one fullscreen window on ws');
256 is($x->input_focus, $swindow->id, 'fullscreen window focused');
258 ################################################################################
259 # Verify that command ‘fullscreen enable’ works and is idempotent.
260 ################################################################################
262 $tmp = fresh_workspace;
264 $window = open_window;
265 is($x->input_focus, $window->id, 'window focused');
266 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
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');
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');
276 $window->fullscreen(0);
278 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
280 ################################################################################
281 # Verify that command ‘fullscreen enable global’ works and is idempotent.
282 ################################################################################
284 $tmp = fresh_workspace;
286 $window = open_window;
287 is($x->input_focus, $window->id, 'window focused');
288 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
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');
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');
298 $window->fullscreen(0);
300 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
302 ################################################################################
303 # Verify that command ‘fullscreen disable’ works and is idempotent.
304 ################################################################################
306 $tmp = fresh_workspace;
308 $window = open_window;
309 is($x->input_focus, $window->id, 'window focused');
310 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
312 $window->fullscreen(1);
314 is(fullscreen_windows($tmp), 1, 'one fullscreen window on workspace');
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');
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');
324 ################################################################################
325 # Verify that command ‘fullscreen toggle’ works.
326 ################################################################################
328 $tmp = fresh_workspace;
330 $window = open_window;
331 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
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');
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');
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 ################################################################################
346 $tmp = fresh_workspace;
348 $window = open_window;
349 $other = open_window;
351 is($x->input_focus, $other->id, 'other window focused');
352 is(fullscreen_windows($tmp), 0, 'no fullscreen window on workspace');
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');
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');
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 ################################################################################
368 $tmp = fresh_workspace;
370 $window = open_window;
372 is($x->input_focus, $window->id, 'window focused');
374 cmd 'workspace ' . get_unused_workspace;
375 isnt($x->input_focus, $window->id, 'window not focused');
376 isnt(focused_ws(), $tmp, 'workspace not selected');
378 cmd '[id="' . $window->id . '"] fullscreen enable global';
379 is($x->input_focus, $window->id, 'window focused');
381 cmd 'fullscreen disable';
382 is($x->input_focus, $window->id, 'window still focused');
383 is(focused_ws(), $tmp, 'workspace selected');