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