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