]> git.sur5r.net Git - i3/i3/blob - testcases/t/294-focus-order.t
6b16540c85d68e17285969962687ac6ea17e8867
[i3/i3] / testcases / t / 294-focus-order.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Verify that the corrent focus stack order is preserved after various
18 # operations.
19 use i3test i3_config => <<EOT;
20 # i3 config file (v4)
21 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
22 fake-outputs 1024x768+0+0,1024x768+1024+0
23 EOT
24
25 sub kill_and_confirm_focus {
26     my $focus = shift;
27     my $msg = shift;
28     cmd "kill";
29     sync_with_i3;
30     is($x->input_focus, $focus, $msg);
31 }
32
33 my @windows;
34 my $ws;
35
36 sub focus_windows {
37     for (my $i = $#windows; $i >= 0; $i--) {
38         cmd '[id=' . $windows[$i]->id . '] focus';
39     }
40 }
41
42 sub confirm_focus {
43     my $msg = shift;
44     sync_with_i3;
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");
48     }
49     cmd 'kill';
50     @windows = ();
51 }
52
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 #####################################################################
57
58 fresh_workspace;
59
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;
65 focus_windows;
66
67 cmd 'layout tabbed';
68 confirm_focus('tabbed');
69
70 #####################################################################
71 # Same as above but with stacked.
72 #####################################################################
73
74 fresh_workspace;
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;
80 focus_windows;
81
82 cmd 'layout stacked';
83 confirm_focus('stacked');
84
85 #####################################################################
86 # Open 4 windows horizontally, move the last one down. The focus
87 # order should be preserved.
88 #####################################################################
89
90 fresh_workspace;
91 $windows[3] = open_window;
92 $windows[2] = open_window;
93 $windows[1] = open_window;
94 $windows[0] = open_window;
95
96 cmd 'move down';
97 confirm_focus('split-h + move');
98
99 #####################################################################
100 # Same as above but with a vertical split.
101 #####################################################################
102
103 fresh_workspace;
104 $windows[3] = open_window;
105 cmd 'split v';
106 $windows[2] = open_window;
107 $windows[1] = open_window;
108 $windows[0] = open_window;
109
110 cmd 'move left';
111 confirm_focus('split-v + move');
112
113 #####################################################################
114 # Test that moving an unfocused container from another output
115 # maintains the correct focus order.
116 #####################################################################
117
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;
124
125 cmd '[id=' . $windows[3]->id . '] move right';
126 confirm_focus('unfocused move from other output');
127
128 #####################################################################
129 # Test that moving an unfocused container inside its original parent
130 # maintains the correct focus order.
131 #####################################################################
132
133 fresh_workspace;
134 $windows[0] = open_window;
135 $windows[1] = open_window;
136 cmd 'split v';
137 $windows[2] = open_window;
138 $windows[3] = open_window;
139 focus_windows;
140
141 cmd '[id=' . $windows[2]->id . '] move up';
142 confirm_focus('split-v + unfocused move inside parent');
143
144 ######################################################################
145 # Test that moving an unfocused container maintains the correct focus
146 # order.
147 # Layout: H [ A V1 [ B C D ] ]
148 ######################################################################
149
150 fresh_workspace;
151 $windows[3] = open_window;
152 $windows[2] = open_window;
153 cmd 'split v';
154 $windows[1] = open_window;
155 $windows[0] = open_window;
156
157 cmd '[id=' . $windows[3]->id . '] move right';
158 confirm_focus('split-v + unfocused move');
159
160 ######################################################################
161 # Test that moving an unfocused container from inside a split
162 # container to another workspace doesn't focus sibling.
163 ######################################################################
164
165 $ws = fresh_workspace;
166 $windows[0] = open_window;
167 $windows[1] = open_window;
168 cmd 'split v';
169 open_window;
170 cmd 'mark a';
171
172 cmd '[id=' . $windows[0]->id . '] focus';
173 cmd '[con_mark=a] move to workspace ' . get_unused_workspace;
174
175 is(@{get_ws_content($ws)}, 2, 'Sanity check: marked window moved');
176 confirm_focus('Move unfocused window from split container');
177
178 ######################################################################
179 # Moving containers to another workspace puts them on the top of the
180 # focus stack but behind the focused container.
181 ######################################################################
182
183 for my $new_workspace (0 .. 1) {
184     fresh_workspace;
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;
190     cmd 'mark target';
191
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' : ''));
195 }
196
197 ######################################################################
198 # Same but with workspace commands.
199 ######################################################################
200
201 fresh_workspace;
202 $windows[2] = open_window;
203 $windows[1] = open_window;
204 $ws = fresh_workspace;
205 $windows[3] = open_window;
206 $windows[0] = open_window;
207 cmd 'mark target';
208
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');
212
213 ######################################################################
214 # Test focus order with floating and tiling windows.
215 # See issue: 1975
216 ######################################################################
217
218 fresh_workspace;
219 $windows[2] = open_window;
220 $windows[0] = open_window;
221 $windows[3] = open_floating_window;
222 $windows[1] = open_floating_window;
223 focus_windows;
224
225 confirm_focus('mix of floating and tiling windows');
226
227 ######################################################################
228 # Same but an unfocused tiling window is killed first.
229 ######################################################################
230
231 fresh_workspace;
232 $windows[2] = open_window;
233 $windows[0] = open_window;
234 $windows[3] = open_floating_window;
235 $windows[1] = open_floating_window;
236 focus_windows;
237
238 cmd '[id=' . $windows[1]->id . '] focus';
239 cmd '[id=' . $windows[0]->id . '] kill';
240
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');
243
244 done_testing;