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 maintains the correct focus
131 # Layout: H [ A V1 [ B C D ] ]
132 ######################################################################
135 $windows[3] = open_window;
136 $windows[2] = open_window;
138 $windows[1] = open_window;
139 $windows[0] = open_window;
141 cmd '[id=' . $windows[3]->id . '] move right';
142 confirm_focus('split-v + unfocused move');
144 ######################################################################
145 # Test that moving an unfocused container from inside a split
146 # container to another workspace doesn't focus sibling.
147 ######################################################################
149 $ws = fresh_workspace;
150 $windows[0] = open_window;
151 $windows[1] = open_window;
156 cmd '[id=' . $windows[0]->id . '] focus';
157 cmd '[con_mark=a] move to workspace ' . get_unused_workspace;
159 is(@{get_ws_content($ws)}, 2, 'Sanity check: marked window moved');
160 confirm_focus('Move unfocused window from split container');
162 ######################################################################
163 # Moving containers to another workspace puts them on the top of the
164 # focus stack but behind the focused container.
165 ######################################################################
167 for my $new_workspace (0 .. 1) {
169 $windows[2] = open_window;
170 $windows[1] = open_window;
171 fresh_workspace if $new_workspace;
172 $windows[3] = open_window;
173 $windows[0] = open_window;
176 cmd '[id=' . $windows[2]->id . '] move to mark target';
177 cmd '[id=' . $windows[1]->id . '] move to mark target';
178 confirm_focus('\'move to mark\' focus order' . ($new_workspace ? ' when moving containers from other workspace' : ''));
181 ######################################################################
182 # Same but with workspace commands.
183 ######################################################################
186 $windows[2] = open_window;
187 $windows[1] = open_window;
188 $ws = fresh_workspace;
189 $windows[3] = open_window;
190 $windows[0] = open_window;
193 cmd '[id=' . $windows[2]->id . '] move to workspace ' . $ws;
194 cmd '[id=' . $windows[1]->id . '] move to workspace ' . $ws;
195 confirm_focus('\'move to workspace\' focus order when moving containers from other workspace');
197 ######################################################################
198 # Test focus order with floating and tiling windows.
200 ######################################################################
203 $windows[2] = open_window;
204 $windows[0] = open_window;
205 $windows[3] = open_floating_window;
206 $windows[1] = open_floating_window;
209 confirm_focus('mix of floating and tiling windows');
211 ######################################################################
212 # Same but an unfocused tiling window is killed first.
213 ######################################################################
216 $windows[2] = open_window;
217 $windows[0] = open_window;
218 $windows[3] = open_floating_window;
219 $windows[1] = open_floating_window;
222 cmd '[id=' . $windows[1]->id . '] focus';
223 cmd '[id=' . $windows[0]->id . '] kill';
225 kill_and_confirm_focus($windows[2]->id, 'window 2 focused after tiling killed');
226 kill_and_confirm_focus($windows[3]->id, 'window 3 focused after tiling killed');