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} == 2 } @{$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 fullscreening a window on a second workspace and moving it onto
196 # the first workspace unfullscreens the first window.
197 ################################################################################
199 my $tmp2 = fresh_workspace;
200 $swindow = open_window;
204 is(fullscreen_windows($tmp2), 1, 'one fullscreen window on second ws');
206 cmd "move workspace $tmp";
208 is(fullscreen_windows($tmp2), 0, 'no fullscreen windows on second ws');
209 is(fullscreen_windows($tmp), 1, 'one fullscreen window on first ws');
211 $swindow->fullscreen(0);
214 # Verify that $swindow was the one that initially remained fullscreen.
215 is(fullscreen_windows($tmp), 0, 'no fullscreen windows on first ws');
217 ################################################################################
218 # Verify that opening a window with _NET_WM_STATE_FULLSCREEN unfullscreens any
219 # existing container on the workspace and fullscreens the newly opened window.
220 ################################################################################
222 $tmp = fresh_workspace;
224 $window = open_window();
228 is(fullscreen_windows($tmp), 1, 'one fullscreen window on ws');
229 is($x->input_focus, $window->id, 'fullscreen window focused');
231 $swindow = open_window({
235 is(fullscreen_windows($tmp), 1, 'one fullscreen window on ws');
236 is($x->input_focus, $swindow->id, 'fullscreen window focused');