]> git.sur5r.net Git - i3/i3/blob - testcases/t/100-fullscreen.t
Merge branch 'fix-resize'
[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} == 2 } @{$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 fullscreening a window on a second workspace and moving it onto
196 # the first workspace unfullscreens the first window.
197 ################################################################################
198
199 my $tmp2 = fresh_workspace;
200 $swindow = open_window;
201
202 cmd 'fullscreen';
203
204 is(fullscreen_windows($tmp2), 1, 'one fullscreen window on second ws');
205
206 cmd "move workspace $tmp";
207
208 is(fullscreen_windows($tmp2), 0, 'no fullscreen windows on second ws');
209 is(fullscreen_windows($tmp), 1, 'one fullscreen window on first ws');
210
211 $swindow->fullscreen(0);
212 sync_with_i3;
213
214 # Verify that $swindow was the one that initially remained fullscreen.
215 is(fullscreen_windows($tmp), 0, 'no fullscreen windows on first ws');
216
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 ################################################################################
221
222 $tmp = fresh_workspace;
223
224 $window = open_window();
225
226 cmd "fullscreen";
227
228 is(fullscreen_windows($tmp), 1, 'one fullscreen window on ws');
229 is($x->input_focus, $window->id, 'fullscreen window focused');
230
231 $swindow = open_window({
232     fullscreen => 1
233 });
234
235 is(fullscreen_windows($tmp), 1, 'one fullscreen window on ws');
236 is($x->input_focus, $swindow->id, 'fullscreen window focused');
237
238 done_testing;