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