]> git.sur5r.net Git - i3/i3/blob - testcases/t/135-floating-focus.t
testcases: fix race conditions in various tests
[i3/i3] / testcases / t / 135-floating-focus.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test;
5 use X11::XCB qw(:all);
6 use X11::XCB::Connection;
7
8 my $x = X11::XCB::Connection->new;
9
10 my $tmp = fresh_workspace;
11
12 #############################################################################
13 # 1: see if focus stays the same when toggling tiling/floating mode
14 #############################################################################
15
16 my $first = open_window($x);
17 my $second = open_window($x);
18
19 is($x->input_focus, $second->id, 'second window focused');
20
21 cmd 'floating enable';
22 cmd 'floating disable';
23
24 is($x->input_focus, $second->id, 'second window still focused after mode toggle');
25
26 #############################################################################
27 # 2: see if focus stays on the current floating window if killing another
28 # floating window
29 #############################################################################
30
31 $tmp = fresh_workspace;
32
33 $first = open_window($x);    # window 2
34 $second = open_window($x);   # window 3
35 my $third = open_window($x); # window 4
36
37 is($x->input_focus, $third->id, 'last container focused');
38
39 cmd 'floating enable';
40
41 cmd '[id="' . $second->id . '"] focus';
42
43 sync_with_i3($x);
44
45 is($x->input_focus, $second->id, 'second con focused');
46
47 cmd 'floating enable';
48
49 # now kill the third one (it's floating). focus should stay unchanged
50 cmd '[id="' . $third->id . '"] kill';
51
52 wait_for_unmap($x);
53
54 is($x->input_focus, $second->id, 'second con still focused after killing third');
55
56
57 #############################################################################
58 # 3: see if the focus gets reverted correctly when closing floating clients
59 # (first to the next floating client, then to the last focused tiling client)
60 #############################################################################
61
62 $tmp = fresh_workspace;
63
64 $first = open_window($x, { background_color => '#ff0000' });    # window 5
65 $second = open_window($x, { background_color => '#00ff00' });   # window 6
66 my $third = open_window($x, { background_color => '#0000ff' }); # window 7
67
68 is($x->input_focus, $third->id, 'last container focused');
69
70 cmd 'floating enable';
71
72 cmd '[id="' . $second->id . '"] focus';
73
74 sync_with_i3($x);
75
76 is($x->input_focus, $second->id, 'second con focused');
77
78 cmd 'floating enable';
79
80 # now kill the second one. focus should fall back to the third one, which is
81 # also floating
82 cmd 'kill';
83 wait_for_unmap($x);
84
85 is($x->input_focus, $third->id, 'third con focused');
86
87 cmd 'kill';
88 wait_for_unmap($x);
89
90 is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
91
92 #############################################################################
93 # 4: same test as 3, but with another split con
94 #############################################################################
95
96 $tmp = fresh_workspace;
97
98 $first = open_window($x, { background_color => '#ff0000' });    # window 5
99 cmd 'split v';
100 cmd 'layout stacked';
101 $second = open_window($x, { background_color => '#00ff00' });   # window 6
102 $third = open_window($x, { background_color => '#0000ff' }); # window 7
103
104 is($x->input_focus, $third->id, 'last container focused');
105
106 cmd 'floating enable';
107
108 cmd '[id="' . $second->id . '"] focus';
109
110 sync_with_i3($x);
111
112 is($x->input_focus, $second->id, 'second con focused');
113
114 cmd 'floating enable';
115
116 sync_with_i3($x);
117
118 # now kill the second one. focus should fall back to the third one, which is
119 # also floating
120 cmd 'kill';
121 wait_for_unmap($x);
122
123 is($x->input_focus, $third->id, 'third con focused');
124
125 cmd 'kill';
126 wait_for_unmap($x);
127
128 is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
129
130 #############################################################################
131 # 5: see if the 'focus tiling' and 'focus floating' commands work
132 #############################################################################
133
134 $tmp = fresh_workspace;
135
136 $first = open_window($x, { background_color => '#ff0000' });    # window 8
137 $second = open_window($x, { background_color => '#00ff00' });   # window 9
138
139 sync_with_i3($x);
140
141 is($x->input_focus, $second->id, 'second container focused');
142
143 cmd 'floating enable';
144
145 is($x->input_focus, $second->id, 'second container focused');
146
147 cmd 'focus tiling';
148
149 sync_with_i3($x);
150
151 is($x->input_focus, $first->id, 'first (tiling) container focused');
152
153 cmd 'focus floating';
154
155 sync_with_i3($x);
156
157 is($x->input_focus, $second->id, 'second (floating) container focused');
158
159 cmd 'focus floating';
160
161 sync_with_i3($x);
162
163 is($x->input_focus, $second->id, 'second (floating) container still focused');
164
165 cmd 'focus mode_toggle';
166
167 sync_with_i3($x);
168
169 is($x->input_focus, $first->id, 'first (tiling) container focused');
170
171 cmd 'focus mode_toggle';
172
173 sync_with_i3($x);
174
175 is($x->input_focus, $second->id, 'second (floating) container focused');
176
177 #############################################################################
178 # 6: see if switching floating focus using the focus left/right command works
179 #############################################################################
180
181 $tmp = fresh_workspace;
182
183 $first = open_floating_window($x, { background_color => '#ff0000' });# window 10
184 $second = open_floating_window($x, { background_color => '#00ff00' }); # window 11
185 $third = open_floating_window($x, { background_color => '#0000ff' }); # window 12
186
187 sync_with_i3($x);
188
189 is($x->input_focus, $third->id, 'third container focused');
190
191 cmd 'focus left';
192
193 sync_with_i3($x);
194
195 is($x->input_focus, $second->id, 'second container focused');
196
197 cmd 'focus left';
198
199 sync_with_i3($x);
200
201 is($x->input_focus, $first->id, 'first container focused');
202
203 cmd 'focus left';
204
205 sync_with_i3($x);
206
207 is($x->input_focus, $third->id, 'focus wrapped to third container');
208
209 cmd 'focus right';
210
211 sync_with_i3($x);
212
213 is($x->input_focus, $first->id, 'focus wrapped to first container');
214
215 cmd 'focus right';
216
217 sync_with_i3($x);
218
219 is($x->input_focus, $second->id, 'focus on second container');
220
221 done_testing;