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)
17 # Verify that the corrent focus stack order is preserved after various
19 use i3test i3_config => <<EOT;
21 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
22 fake-outputs 1024x768+0+0,1024x768+1024+0
25 sub kill_and_confirm_focus {
30 is($x->input_focus, $focus, $msg);
37 for (my $i = $#windows; $i >= 0; $i--) {
38 cmd '[id=' . $windows[$i]->id . '] focus';
45 is($x->input_focus, $windows[0]->id, $msg . ': window 0 focused');
46 foreach my $i (1 .. $#windows) {
47 kill_and_confirm_focus($windows[$i]->id, "$msg: window $i focused");
53 #####################################################################
54 # Open 5 windows, focus them in a custom order and then change to
55 # tabbed layout. The focus order should be preserved.
56 #####################################################################
60 $windows[3] = open_window;
61 $windows[1] = open_window;
62 $windows[0] = open_window;
63 $windows[2] = open_window;
64 $windows[4] = open_window;
68 confirm_focus('tabbed');
70 #####################################################################
71 # Same as above but with stacked.
72 #####################################################################
75 $windows[3] = open_window;
76 $windows[1] = open_window;
77 $windows[0] = open_window;
78 $windows[2] = open_window;
79 $windows[4] = open_window;
83 confirm_focus('stacked');
85 #####################################################################
86 # Open 4 windows horizontally, move the last one down. The focus
87 # order should be preserved.
88 #####################################################################
91 $windows[3] = open_window;
92 $windows[2] = open_window;
93 $windows[1] = open_window;
94 $windows[0] = open_window;
97 confirm_focus('split-h + move');
99 #####################################################################
100 # Same as above but with a vertical split.
101 #####################################################################
104 $windows[3] = open_window;
106 $windows[2] = open_window;
107 $windows[1] = open_window;
108 $windows[0] = open_window;
111 confirm_focus('split-v + move');
113 #####################################################################
114 # Test that moving an unfocused container from another output
115 # maintains the correct focus order.
116 #####################################################################
118 fresh_workspace(output => 0);
119 $windows[3] = open_window;
120 fresh_workspace(output => 1);
121 $windows[2] = open_window;
122 $windows[1] = open_window;
123 $windows[0] = open_window;
125 cmd '[id=' . $windows[3]->id . '] move right';
126 confirm_focus('unfocused move from other output');
128 #####################################################################
129 # Test that moving an unfocused container inside its original parent
130 # maintains the correct focus order.
131 #####################################################################
134 $windows[0] = open_window;
135 $windows[1] = open_window;
137 $windows[2] = open_window;
138 $windows[3] = open_window;
141 cmd '[id=' . $windows[2]->id . '] move up';
142 confirm_focus('split-v + unfocused move inside parent');
144 ######################################################################
145 # Test that moving an unfocused container maintains the correct focus
147 # Layout: H [ A V1 [ B C D ] ]
148 ######################################################################
151 $windows[3] = open_window;
152 $windows[2] = open_window;
154 $windows[1] = open_window;
155 $windows[0] = open_window;
157 cmd '[id=' . $windows[3]->id . '] move right';
158 confirm_focus('split-v + unfocused move');
160 ######################################################################
161 # Test that moving an unfocused container from inside a split
162 # container to another workspace doesn't focus sibling.
163 ######################################################################
165 $ws = fresh_workspace;
166 $windows[0] = open_window;
167 $windows[1] = open_window;
172 cmd '[id=' . $windows[0]->id . '] focus';
173 cmd '[con_mark=a] move to workspace ' . get_unused_workspace;
175 is(@{get_ws_content($ws)}, 2, 'Sanity check: marked window moved');
176 confirm_focus('Move unfocused window from split container');
178 ######################################################################
179 # Moving containers to another workspace puts them on the top of the
180 # focus stack but behind the focused container.
181 ######################################################################
183 for my $new_workspace (0 .. 1) {
185 $windows[2] = open_window;
186 $windows[1] = open_window;
187 fresh_workspace if $new_workspace;
188 $windows[3] = open_window;
189 $windows[0] = open_window;
192 cmd '[id=' . $windows[2]->id . '] move to mark target';
193 cmd '[id=' . $windows[1]->id . '] move to mark target';
194 confirm_focus('\'move to mark\' focus order' . ($new_workspace ? ' when moving containers from other workspace' : ''));
197 ######################################################################
198 # Same but with workspace commands.
199 ######################################################################
202 $windows[2] = open_window;
203 $windows[1] = open_window;
204 $ws = fresh_workspace;
205 $windows[3] = open_window;
206 $windows[0] = open_window;
209 cmd '[id=' . $windows[2]->id . '] move to workspace ' . $ws;
210 cmd '[id=' . $windows[1]->id . '] move to workspace ' . $ws;
211 confirm_focus('\'move to workspace\' focus order when moving containers from other workspace');
213 ######################################################################
214 # Test focus order with floating and tiling windows.
216 ######################################################################
219 $windows[2] = open_window;
220 $windows[0] = open_window;
221 $windows[3] = open_floating_window;
222 $windows[1] = open_floating_window;
225 confirm_focus('mix of floating and tiling windows');
227 ######################################################################
228 # Same but an unfocused tiling window is killed first.
229 ######################################################################
232 $windows[2] = open_window;
233 $windows[0] = open_window;
234 $windows[3] = open_floating_window;
235 $windows[1] = open_floating_window;
238 cmd '[id=' . $windows[1]->id . '] focus';
239 cmd '[id=' . $windows[0]->id . '] kill';
241 kill_and_confirm_focus($windows[2]->id, 'window 2 focused after tiling killed');
242 kill_and_confirm_focus($windows[3]->id, 'window 3 focused after tiling killed');