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
108 is($x->input_focus, $third->id, 'last container focused');
110 cmd '[id="' . $second->id . '"] focus';
111 cmd 'floating enable';
112 cmd '[id="' . $third->id . '"] floating enable';
115 is($x->input_focus, $second->id, 'second con focused');
117 # now kill the second one. focus should fall back to the third one, which is
120 wait_for_unmap($second);
122 is($x->input_focus, $third->id, 'third con focused');
125 wait_for_unmap($third);
127 is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
129 #############################################################################
130 # 5: see if the 'focus tiling' and 'focus floating' commands work
131 #############################################################################
133 $tmp = fresh_workspace;
135 $first = open_window({ background_color => '#ff0000' }); # window 8
136 $second = open_window({ background_color => '#00ff00' }); # window 9
138 is($x->input_focus, $second->id, 'second container focused');
140 cmd 'floating enable';
142 is($x->input_focus, $second->id, 'second container focused');
146 is($x->input_focus, $first->id, 'first (tiling) container focused');
148 cmd 'focus floating';
150 is($x->input_focus, $second->id, 'second (floating) container focused');
152 cmd 'focus floating';
154 is($x->input_focus, $second->id, 'second (floating) container still focused');
156 cmd 'focus mode_toggle';
158 is($x->input_focus, $first->id, 'first (tiling) container focused');
160 cmd 'focus mode_toggle';
162 is($x->input_focus, $second->id, 'second (floating) container focused');
164 #############################################################################
165 # 6: see if switching floating focus using the focus left/right command works
166 #############################################################################
168 $tmp = fresh_workspace;
170 $first = open_floating_window({ background_color => '#ff0000' });# window 10
171 $second = open_floating_window({ background_color => '#00ff00' }); # window 11
172 $third = open_floating_window({ background_color => '#0000ff' }); # window 12
174 is($x->input_focus, $third->id, 'third container focused');
178 is($x->input_focus, $second->id, 'second container focused');
182 is($x->input_focus, $first->id, 'first container focused');
186 is($x->input_focus, $third->id, 'focus wrapped to third container');
190 is($x->input_focus, $first->id, 'focus wrapped to first container');
194 is($x->input_focus, $second->id, 'focus on second container');
196 #############################################################################
197 # 7: verify that focusing the parent of a window inside a floating con goes
198 # up to the grandparent (workspace) and that focusing child from the ws
199 # goes back down to the child of the floating con
200 #############################################################################
202 $tmp = fresh_workspace;
204 my $tiled = open_window;
205 my $floating = open_floating_window;
206 is($x->input_focus, $floating->id, 'floating window focused');
210 is(get_ws($tmp)->{focused}, 1, 'workspace is focused');
213 is($x->input_focus, $floating->id, 'floating window focused');
215 #############################################################################
216 # 8: verify that focusing a floating window raises it to the top.
217 # This test can't verify that the floating container is visually on top, just
218 # that it is placed on the tail of the floating_head.
220 #############################################################################
222 $tmp = fresh_workspace;
224 $first = open_floating_window;
225 $second = open_floating_window;
227 is($x->input_focus, $second->id, 'second floating window focused');
228 my $ws = get_ws($tmp);
229 is($ws->{floating_nodes}->[1]->{nodes}->[0]->{window}, $second->id, 'second on top');
230 is($ws->{floating_nodes}->[0]->{nodes}->[0]->{window}, $first->id, 'first behind');
232 cmd '[id=' . $first->id . '] focus';
234 is($x->input_focus, $first->id, 'first floating window focused');
236 is($ws->{floating_nodes}->[1]->{nodes}->[0]->{window}, $first->id, 'first on top');
237 is($ws->{floating_nodes}->[0]->{nodes}->[0]->{window}, $second->id, 'second behind');
239 #############################################################################
240 # 9: verify that disabling / enabling floating for a window from a different
241 # workspace maintains the correct focus order.
242 #############################################################################
244 sub open_window_helper {
245 my $floating = shift if @_;
247 return open_floating_window;
254 for my $floating (0, 1){
255 $tmp = fresh_workspace;
256 $first = open_window;
257 $second = open_window_helper($floating);
258 is($x->input_focus, $second->id, "second window focused");
261 cmd "[id=" . $second->id . "] floating toggle";
262 cmd "workspace $tmp";
265 my $workspace = get_ws($tmp);
266 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $second->id, 'second window on first workspace, floating') unless $floating;
267 is($workspace->{nodes}->[1]->{window}, $second->id, 'second window on first workspace, right') unless !$floating;
268 is($x->input_focus, $second->id, 'second window still focused');
271 #############################################################################
272 # 10: verify that toggling floating for an unfocused window on another
273 # workspace doesn't make it focused.
274 #############################################################################
276 for my $floating (0, 1){
277 $tmp = fresh_workspace;
278 $first = open_window_helper($floating);
279 $second = open_window;
280 is($x->input_focus, $second->id, 'second (tiling) window focused');
283 cmd "[id=" . $first->id . "] floating toggle";
284 cmd "workspace $tmp";
287 my $workspace = get_ws($tmp);
288 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $first->id, 'first window on first workspace, floating') unless $floating;
289 is($workspace->{nodes}->[1]->{window}, $first->id, 'first window on first workspace, right') unless !$floating;
290 is($x->input_focus, $second->id, 'second window still focused');
293 #############################################################################
294 # 11: verify that toggling floating for a focused window on another workspace
295 # which has another, unfocused floating window maintains the focus of the
297 #############################################################################
298 for my $floating (0, 1){
299 $tmp = fresh_workspace;
300 $first = open_window;
301 $second = open_floating_window;
302 is($x->input_focus, $second->id, 'second (floating) window focused');
303 $third = open_window_helper($floating);
304 is($x->input_focus, $third->id, "third (floating = $floating) window focused");
307 cmd "[id=" . $third->id . "] floating toggle";
308 cmd "workspace $tmp";
311 my $workspace = get_ws($tmp);
312 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $third->id, 'third window on first workspace, floating') unless $floating;
313 is($workspace->{nodes}->[1]->{window}, $third->id, 'third window on first workspace, right') unless !$floating;
314 is($x->input_focus, $third->id, 'third window still focused');
317 #############################################################################
318 # 12: verify that toggling floating for an unfocused window on another
319 # workspace which has another, focused floating window doesn't change focus.
320 #############################################################################
322 for my $floating (0, 1){
323 $tmp = fresh_workspace;
324 $first = open_window;
325 $second = open_window_helper($floating);
326 is($x->input_focus, $second->id, "second (floating = $floating) window focused");
327 $third = open_floating_window;
328 is($x->input_focus, $third->id, 'third (floating) window focused');
331 cmd "[id=" . $second->id . "] floating toggle";
332 cmd "workspace $tmp";
335 my $workspace = get_ws($tmp);
336 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $second->id, 'second window on first workspace, floating') unless $floating;
337 is($workspace->{nodes}->[1]->{window}, $second->id, 'second window on first workspace, right') unless !$floating;
338 is($x->input_focus, $third->id, 'third window still focused');
341 #############################################################################
342 # 13: For layout [H1 [A V1[ B F ] ] ] verify that toggling F's floating
343 # mode maintains its focus.
344 #############################################################################
346 for my $floating (0, 1){
347 $tmp = fresh_workspace;
348 $first = open_window;
349 $second = open_window;
352 is($x->input_focus, $second->id, "second (floating = $floating) window focused");
353 $third = open_window_helper($floating);
354 is($x->input_focus, $third->id, 'third (floating) window focused');
357 cmd "[id=" . $third->id . "] floating toggle";
358 cmd "workspace $tmp";
361 my $workspace = get_ws($tmp);
362 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $third->id, 'third window on first workspace, floating') unless $floating;
363 is($workspace->{nodes}->[1]->{nodes}->[1]->{window}, $third->id, 'third window on first workspace') unless !$floating;
364 is($x->input_focus, $third->id, 'third window still focused');
367 #############################################################################
368 # 14: For layout [H1 [A V1[ H2 [B H2 [ C V2 [ F D ] ] ] ] ] ] verify that
369 # toggling F's floating mode maintains its focus.
370 #############################################################################
372 sub kill_and_confirm_focus {
377 is($x->input_focus, $focus, $msg);
380 $tmp = fresh_workspace;
389 is($x->input_focus, $D->id, "D is focused");
392 my $workspace = get_ws($tmp);
393 is($workspace->{nodes}->[1]->{nodes}->[1]->{nodes}->[1]->{nodes}->[0]->{window}, $F->id, 'F opened in its expected position');
396 cmd "[id=" . $F->id . "] floating enable";
397 cmd "workspace $tmp";
400 $workspace = get_ws($tmp);
401 is($workspace->{floating_nodes}->[0]->{nodes}->[0]->{window}, $F->id, 'F on first workspace, floating');
402 is($workspace->{nodes}->[1]->{nodes}->[1]->{nodes}->[1]->{nodes}->[0]->{window}, $D->id, 'D where F used to be');
403 is($x->input_focus, $D->id, 'D still focused');
406 cmd "[id=" . $F->id . "] floating disable";
407 cmd "workspace $tmp";
410 $workspace = get_ws($tmp);
411 is($workspace->{nodes}->[1]->{nodes}->[1]->{nodes}->[1]->{nodes}->[1]->{window}, $F->id, 'F where D used to be');
412 is($x->input_focus, $D->id, 'D still focused');
414 kill_and_confirm_focus($F->id, 'F focused after D is killed');
415 kill_and_confirm_focus($C->id, 'C focused after F is killed');
416 kill_and_confirm_focus($B->id, 'B focused after C is killed');
417 kill_and_confirm_focus($A->id, 'A focused after B is killed');