]> git.sur5r.net Git - i3/i3/blob - testcases/t/294-focus-order.t
c818f1d441e36aea832e802163c2f42de8604f6b
[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;
20
21 sub kill_and_confirm_focus {
22     my $focus = shift;
23     my $msg = shift;
24     cmd "kill";
25     sync_with_i3;
26     is($x->input_focus, $focus, $msg);
27 }
28
29 my @windows;
30 my $ws;
31
32 sub focus_windows {
33     for (my $i = $#windows; $i >= 0; $i--) {
34         cmd '[id=' . $windows[$i]->id . '] focus';
35     }
36 }
37
38 sub confirm_focus {
39     my $msg = shift;
40     sync_with_i3;
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");
44     }
45     cmd 'kill';
46     @windows = ();
47 }
48
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 #####################################################################
53
54 fresh_workspace;
55
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;
61 focus_windows;
62
63 cmd 'layout tabbed';
64 confirm_focus('tabbed');
65
66 #####################################################################
67 # Same as above but with stacked.
68 #####################################################################
69
70 fresh_workspace;
71
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;
77 focus_windows;
78
79 cmd 'layout stacked';
80 confirm_focus('stacked');
81
82 #####################################################################
83 # Open 4 windows horizontally, move the last one down. The focus
84 # order should be preserved.
85 #####################################################################
86
87 fresh_workspace;
88 $windows[3] = open_window;
89 $windows[2] = open_window;
90 $windows[1] = open_window;
91 $windows[0] = open_window;
92
93 cmd 'move down';
94 confirm_focus('split-h + move');
95
96 #####################################################################
97 # Same as above but with a vertical split.
98 #####################################################################
99
100 fresh_workspace;
101 $windows[3] = open_window;
102 cmd 'split v';
103 $windows[2] = open_window;
104 $windows[1] = open_window;
105 $windows[0] = open_window;
106
107 cmd 'move left';
108 confirm_focus('split-v + move');
109
110 ######################################################################
111 # Test that moving an unfocused container maintains the correct focus
112 # order.
113 # Layout: H [ A V1 [ B C D ] ]
114 ######################################################################
115
116 fresh_workspace;
117 $windows[3] = open_window;
118 $windows[2] = open_window;
119 cmd 'split v';
120 $windows[1] = open_window;
121 $windows[0] = open_window;
122
123 cmd '[id=' . $windows[3]->id . '] move right';
124 confirm_focus('split-v + unfocused move');
125
126 ######################################################################
127 # Test that moving an unfocused container from inside a split
128 # container to another workspace doesn't focus sibling.
129 ######################################################################
130
131 $ws = fresh_workspace;
132 $windows[0] = open_window;
133 $windows[1] = open_window;
134 cmd 'split v';
135 open_window;
136 cmd 'mark a';
137
138 cmd '[id=' . $windows[0]->id . '] focus';
139 cmd '[con_mark=a] move to workspace ' . get_unused_workspace;
140
141 is(@{get_ws_content($ws)}, 2, 'Sanity check: marked window moved');
142 confirm_focus('Move unfocused window from split container');
143
144 ######################################################################
145 # Moving containers to another workspace puts them on the top of the
146 # focus stack but behind the focused container.
147 ######################################################################
148
149 for my $new_workspace (0 .. 1) {
150     fresh_workspace;
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;
156     cmd 'mark target';
157
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' : ''));
161 }
162
163 ######################################################################
164 # Same but with workspace commands.
165 ######################################################################
166
167 fresh_workspace;
168 $windows[2] = open_window;
169 $windows[1] = open_window;
170 $ws = fresh_workspace;
171 $windows[3] = open_window;
172 $windows[0] = open_window;
173 cmd 'mark target';
174
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');
178
179 ######################################################################
180 # Test focus order with floating and tiling windows.
181 # See issue: 1975
182 ######################################################################
183
184 fresh_workspace;
185 $windows[2] = open_window;
186 $windows[0] = open_window;
187 $windows[3] = open_floating_window;
188 $windows[1] = open_floating_window;
189 focus_windows;
190
191 confirm_focus('mix of floating and tiling windows');
192
193 ######################################################################
194 # Same but an unfocused tiling window is killed first.
195 ######################################################################
196
197 fresh_workspace;
198 $windows[2] = open_window;
199 $windows[0] = open_window;
200 $windows[3] = open_floating_window;
201 $windows[1] = open_floating_window;
202 focus_windows;
203
204 cmd '[id=' . $windows[1]->id . '] focus';
205 cmd '[id=' . $windows[0]->id . '] kill';
206
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');
209
210 done_testing;