2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://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)
19 my $tmp = fresh_workspace;
21 #############################################################################
22 # 1: see if focus stays the same when toggling tiling/floating mode
23 #############################################################################
25 my $first = open_window;
26 my $second = open_window;
28 is($x->input_focus, $second->id, 'second window focused');
30 cmd 'floating enable';
31 cmd 'floating disable';
33 is($x->input_focus, $second->id, 'second window still focused after mode toggle');
35 #############################################################################
36 # 2: see if focus stays on the current floating window if killing another
38 #############################################################################
40 $tmp = fresh_workspace;
42 $first = open_window; # window 2
43 $second = open_window; # window 3
44 my $third = open_window; # window 4
46 is($x->input_focus, $third->id, 'last container focused');
48 cmd 'floating enable';
50 cmd '[id="' . $second->id . '"] focus';
52 is($x->input_focus, $second->id, 'second con focused');
54 cmd 'floating enable';
56 # now kill the third one (it's floating). focus should stay unchanged
57 cmd '[id="' . $third->id . '"] kill';
59 wait_for_unmap($third);
61 is($x->input_focus, $second->id, 'second con still focused after killing third');
64 #############################################################################
65 # 3: see if the focus gets reverted correctly when closing floating clients
66 # (first to the next floating client, then to the last focused tiling client)
67 #############################################################################
69 $tmp = fresh_workspace;
71 $first = open_window({ background_color => '#ff0000' }); # window 5
72 $second = open_window({ background_color => '#00ff00' }); # window 6
73 $third = open_window({ background_color => '#0000ff' }); # window 7
75 is($x->input_focus, $third->id, 'last container focused');
77 cmd 'floating enable';
79 cmd '[id="' . $second->id . '"] focus';
81 is($x->input_focus, $second->id, 'second con focused');
83 cmd 'floating enable';
85 # now kill the second one. focus should fall back to the third one, which is
88 wait_for_unmap($second);
90 is($x->input_focus, $third->id, 'third con focused');
93 wait_for_unmap($third);
95 is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
97 #############################################################################
98 # 4: same test as 3, but with another split con
99 #############################################################################
101 $tmp = fresh_workspace;
103 $first = open_window({ background_color => '#ff0000' }); # window 5
105 cmd 'layout stacked';
106 $second = open_window({ background_color => '#00ff00' }); # window 6
107 $third = open_window({ background_color => '#0000ff' }); # window 7
109 is($x->input_focus, $third->id, 'last container focused');
111 cmd 'floating enable';
113 cmd '[id="' . $second->id . '"] focus';
115 is($x->input_focus, $second->id, 'second con focused');
117 cmd 'floating enable';
121 # now kill the second one. focus should fall back to the third one, which is
124 wait_for_unmap($second);
126 is($x->input_focus, $third->id, 'third con focused');
129 wait_for_unmap($third);
131 is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
133 #############################################################################
134 # 5: see if the 'focus tiling' and 'focus floating' commands work
135 #############################################################################
137 $tmp = fresh_workspace;
139 $first = open_window({ background_color => '#ff0000' }); # window 8
140 $second = open_window({ background_color => '#00ff00' }); # window 9
142 is($x->input_focus, $second->id, 'second container focused');
144 cmd 'floating enable';
146 is($x->input_focus, $second->id, 'second container focused');
150 is($x->input_focus, $first->id, 'first (tiling) container focused');
152 cmd 'focus floating';
154 is($x->input_focus, $second->id, 'second (floating) container focused');
156 cmd 'focus floating';
158 is($x->input_focus, $second->id, 'second (floating) container still focused');
160 cmd 'focus mode_toggle';
162 is($x->input_focus, $first->id, 'first (tiling) container focused');
164 cmd 'focus mode_toggle';
166 is($x->input_focus, $second->id, 'second (floating) container focused');
168 #############################################################################
169 # 6: see if switching floating focus using the focus left/right command works
170 #############################################################################
172 $tmp = fresh_workspace;
174 $first = open_floating_window({ background_color => '#ff0000' });# window 10
175 $second = open_floating_window({ background_color => '#00ff00' }); # window 11
176 $third = open_floating_window({ background_color => '#0000ff' }); # window 12
178 is($x->input_focus, $third->id, 'third container focused');
182 is($x->input_focus, $second->id, 'second container focused');
186 is($x->input_focus, $first->id, 'first container focused');
190 is($x->input_focus, $third->id, 'focus wrapped to third container');
194 is($x->input_focus, $first->id, 'focus wrapped to first container');
198 is($x->input_focus, $second->id, 'focus on second container');
200 #############################################################################
201 # 7: verify that focusing the parent of a window inside a floating con goes
202 # up to the grandparent (workspace) and that focusing child from the ws
203 # goes back down to the child of the floating con
204 #############################################################################
206 $tmp = fresh_workspace;
208 my $tiled = open_window;
209 my $floating = open_floating_window;
210 is($x->input_focus, $floating->id, 'floating window focused');
214 is(get_ws($tmp)->{focused}, 1, 'workspace is focused');
217 is($x->input_focus, $floating->id, 'floating window focused');
219 #############################################################################
220 # 8: verify that focusing a floating window raises it to the top.
221 # This test can't verify that the floating container is visually on top, just
222 # that it is placed on the tail of the floating_head.
224 #############################################################################
226 $tmp = fresh_workspace;
228 $first = open_floating_window;
229 $second = open_floating_window;
231 is($x->input_focus, $second->id, 'second floating window focused');
232 my $ws = get_ws($tmp);
233 is($ws->{floating_nodes}->[1]->{nodes}->[0]->{window}, $second->id, 'second on top');
234 is($ws->{floating_nodes}->[0]->{nodes}->[0]->{window}, $first->id, 'first behind');
236 cmd '[id=' . $first->id . '] focus';
238 is($x->input_focus, $first->id, 'first floating window focused');
240 is($ws->{floating_nodes}->[1]->{nodes}->[0]->{window}, $first->id, 'first on top');
241 is($ws->{floating_nodes}->[0]->{nodes}->[0]->{window}, $second->id, 'second behind');
243 #############################################################################
244 # 9: verify that disabling / enabling floating for a window from a different
245 # workspace maintains the correct focus order.
246 #############################################################################
248 sub open_window_helper {
249 my $floating = shift if @_;
251 return open_floating_window;
258 for my $floating (0, 1){
259 $tmp = fresh_workspace;
260 $first = open_window;
261 $second = open_window_helper($floating);
262 is($x->input_focus, $second->id, "second window focused");
265 cmd "[id=" . $second->id . "] floating toggle";
266 cmd "workspace $tmp";
269 my $workspace = get_ws($tmp);
270 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $second->id, 'second window on first workspace, floating') unless $floating;
271 is($workspace->{nodes}->[1]->{window}, $second->id, 'second window on first workspace, right') unless !$floating;
272 is($x->input_focus, $second->id, 'second window still focused');
275 #############################################################################
276 # 10: verify that toggling floating for an unfocused window on another
277 # workspace doesn't make it focused.
278 #############################################################################
280 for my $floating (0, 1){
281 $tmp = fresh_workspace;
282 $first = open_window_helper($floating);
283 $second = open_window;
284 is($x->input_focus, $second->id, 'second (tiling) window focused');
287 cmd "[id=" . $first->id . "] floating toggle";
288 cmd "workspace $tmp";
291 my $workspace = get_ws($tmp);
292 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $first->id, 'first window on first workspace, floating') unless $floating;
293 is($workspace->{nodes}->[1]->{window}, $first->id, 'first window on first workspace, right') unless !$floating;
294 is($x->input_focus, $second->id, 'second window still focused');
297 #############################################################################
298 # 11: verify that toggling floating for a focused window on another workspace
299 # which has another, unfocused floating window maintains the focus of the
301 #############################################################################
302 for my $floating (0, 1){
303 $tmp = fresh_workspace;
304 $first = open_window;
305 $second = open_floating_window;
306 is($x->input_focus, $second->id, 'second (floating) window focused');
307 $third = open_window_helper($floating);
308 is($x->input_focus, $third->id, "third (floating = $floating) window focused");
311 cmd "[id=" . $third->id . "] floating toggle";
312 cmd "workspace $tmp";
315 my $workspace = get_ws($tmp);
316 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $third->id, 'third window on first workspace, floating') unless $floating;
317 is($workspace->{nodes}->[1]->{window}, $third->id, 'third window on first workspace, right') unless !$floating;
318 is($x->input_focus, $third->id, 'third window still focused');
321 #############################################################################
322 # 12: verify that toggling floating for an unfocused window on another
323 # workspace which has another, focused floating window doesn't change focus.
324 #############################################################################
326 for my $floating (0, 1){
327 $tmp = fresh_workspace;
328 $first = open_window;
329 $second = open_window_helper($floating);
330 is($x->input_focus, $second->id, "second (floating = $floating) window focused");
331 $third = open_floating_window;
332 is($x->input_focus, $third->id, 'third (floating) window focused');
335 cmd "[id=" . $second->id . "] floating toggle";
336 cmd "workspace $tmp";
339 my $workspace = get_ws($tmp);
340 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $second->id, 'second window on first workspace, floating') unless $floating;
341 is($workspace->{nodes}->[1]->{window}, $second->id, 'second window on first workspace, right') unless !$floating;
342 is($x->input_focus, $third->id, 'third window still focused');
345 #############################################################################
346 # 13: For layout [H1 [A V1[ B F ] ] ] verify that toggling F's floating
347 # mode maintains its focus.
348 #############################################################################
350 for my $floating (0, 1){
351 $tmp = fresh_workspace;
352 $first = open_window;
353 $second = open_window;
356 is($x->input_focus, $second->id, "second (floating = $floating) window focused");
357 $third = open_window_helper($floating);
358 is($x->input_focus, $third->id, 'third (floating) window focused');
361 cmd "[id=" . $third->id . "] floating toggle";
362 cmd "workspace $tmp";
365 my $workspace = get_ws($tmp);
366 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $third->id, 'third window on first workspace, floating') unless $floating;
367 is($workspace->{nodes}->[1]->{nodes}->[1]->{window}, $third->id, 'third window on first workspace') unless !$floating;
368 is($x->input_focus, $third->id, 'third window still focused');
371 #############################################################################
372 # 14: For layout [H1 [A V1[ H2 [B H2 [ C V2 [ F D ] ] ] ] ] ] verify that
373 # toggling F's floating mode maintains its focus.
374 #############################################################################
376 sub kill_and_confirm_focus {
381 is($x->input_focus, $focus, $msg);
384 $tmp = fresh_workspace;
393 is($x->input_focus, $D->id, "D is focused");
396 my $workspace = get_ws($tmp);
397 is($workspace->{nodes}->[1]->{nodes}->[1]->{nodes}->[1]->{nodes}->[0]->{window}, $F->id, 'F opened in its expected position');
400 cmd "[id=" . $F->id . "] floating enable";
401 cmd "workspace $tmp";
404 $workspace = get_ws($tmp);
405 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $F->id, 'F on first workspace, floating');
406 is($workspace->{nodes}->[1]->{nodes}->[1]->{nodes}->[1]->{nodes}->[0]->{window}, $D->id, 'D where F used to be');
407 is($x->input_focus, $D->id, 'D still focused');
410 cmd "[id=" . $F->id . "] floating disable";
411 cmd "workspace $tmp";
414 $workspace = get_ws($tmp);
415 is($workspace->{nodes}->[1]->{nodes}->[1]->{nodes}->[1]->{nodes}->[1]->{window}, $F->id, 'F where D used to be');
416 is($x->input_focus, $D->id, 'D still focused');
418 kill_and_confirm_focus($F->id, 'F focused after D is killed');
419 kill_and_confirm_focus($C->id, 'C focused after F is killed');
420 kill_and_confirm_focus($B->id, 'B focused after C is killed');
421 kill_and_confirm_focus($A->id, 'A focused after B is killed');