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