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
21 sub kill_and_confirm_focus {
26 is($x->input_focus, $focus, $msg);
33 for (my $i = $#windows; $i >= 0; $i--) {
34 cmd '[id=' . $windows[$i]->id . '] focus';
41 is($x->input_focus, $windows[0]->id, $msg . ': window 0 focused');
42 foreach my $i (1 .. $#windows) {
43 kill_and_confirm_focus($windows[$i]->id, "$msg: window $i focused");
49 #####################################################################
50 # Open 5 windows, focus them in a custom order and then change to
51 # tabbed layout. The focus order should be preserved.
52 #####################################################################
56 $windows[3] = open_window;
57 $windows[1] = open_window;
58 $windows[0] = open_window;
59 $windows[2] = open_window;
60 $windows[4] = open_window;
64 confirm_focus('tabbed');
66 #####################################################################
67 # Same as above but with stacked.
68 #####################################################################
72 $windows[3] = open_window;
73 $windows[1] = open_window;
74 $windows[0] = open_window;
75 $windows[2] = open_window;
76 $windows[4] = open_window;
80 confirm_focus('stacked');
82 #####################################################################
83 # Open 4 windows horizontally, move the last one down. The focus
84 # order should be preserved.
85 #####################################################################
88 $windows[3] = open_window;
89 $windows[2] = open_window;
90 $windows[1] = open_window;
91 $windows[0] = open_window;
94 confirm_focus('split-h + move');
96 #####################################################################
97 # Same as above but with a vertical split.
98 #####################################################################
101 $windows[3] = open_window;
103 $windows[2] = open_window;
104 $windows[1] = open_window;
105 $windows[0] = open_window;
108 confirm_focus('split-v + move');
110 ######################################################################
111 # Test that moving an unfocused container maintains the correct focus
113 # Layout: H [ A V1 [ B C D ] ]
114 ######################################################################
117 $windows[3] = open_window;
118 $windows[2] = open_window;
120 $windows[1] = open_window;
121 $windows[0] = open_window;
123 cmd '[id=' . $windows[3]->id . '] move right';
124 confirm_focus('split-v + unfocused move');
126 ######################################################################
127 # Test that moving an unfocused container from inside a split
128 # container to another workspace doesn't focus sibling.
129 ######################################################################
131 $ws = fresh_workspace;
132 $windows[0] = open_window;
133 $windows[1] = open_window;
138 cmd '[id=' . $windows[0]->id . '] focus';
139 cmd '[con_mark=a] move to workspace ' . get_unused_workspace;
141 is(@{get_ws_content($ws)}, 2, 'Sanity check: marked window moved');
142 confirm_focus('Move unfocused window from split container');
144 ######################################################################
145 # Moving containers to another workspace puts them on the top of the
146 # focus stack but behind the focused container.
147 ######################################################################
149 for my $new_workspace (0 .. 1) {
151 $windows[2] = open_window;
152 $windows[1] = open_window;
153 fresh_workspace if $new_workspace;
154 $windows[3] = open_window;
155 $windows[0] = open_window;
158 cmd '[id=' . $windows[2]->id . '] move to mark target';
159 cmd '[id=' . $windows[1]->id . '] move to mark target';
160 confirm_focus('\'move to mark\' focus order' . ($new_workspace ? ' when moving containers from other workspace' : ''));
163 ######################################################################
164 # Same but with workspace commands.
165 ######################################################################
168 $windows[2] = open_window;
169 $windows[1] = open_window;
170 $ws = fresh_workspace;
171 $windows[3] = open_window;
172 $windows[0] = open_window;
175 cmd '[id=' . $windows[2]->id . '] move to workspace ' . $ws;
176 cmd '[id=' . $windows[1]->id . '] move to workspace ' . $ws;
177 confirm_focus('\'move to workspace\' focus order when moving containers from other workspace');
179 ######################################################################
180 # Test focus order with floating and tiling windows.
182 ######################################################################
185 $windows[2] = open_window;
186 $windows[0] = open_window;
187 $windows[3] = open_floating_window;
188 $windows[1] = open_floating_window;
191 confirm_focus('mix of floating and tiling windows');
193 ######################################################################
194 # Same but an unfocused tiling window is killed first.
195 ######################################################################
198 $windows[2] = open_window;
199 $windows[0] = open_window;
200 $windows[3] = open_floating_window;
201 $windows[1] = open_floating_window;
204 cmd '[id=' . $windows[1]->id . '] focus';
205 cmd '[id=' . $windows[0]->id . '] kill';
207 kill_and_confirm_focus($windows[2]->id, 'window 2 focused after tiling killed');
208 kill_and_confirm_focus($windows[3]->id, 'window 3 focused after tiling killed');