2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://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');