]> git.sur5r.net Git - i3/i3/blob - testcases/t/65-for_window.t
Merge branch 'fix-i3bar-man'
[i3/i3] / testcases / t / 65-for_window.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
4 #
5 #
6 use X11::XCB qw(:all);
7 use X11::XCB::Connection;
8 use i3test;
9
10 my $x = X11::XCB::Connection->new;
11
12 ##############################################################
13 # 1: test the following directive:
14 #    for_window [class="borderless"] border none
15 # by first creating a window with a different class (should get
16 # the normal border), then creating a window with the class
17 # "borderless" (should get no border)
18 ##############################################################
19
20 my $config = <<EOT;
21 # i3 config file (v4)
22 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
23 for_window [class="borderless"] border none
24 for_window [title="special borderless title"] border none
25 EOT
26
27 my $process = launch_with_config($config);
28
29 my $tmp = fresh_workspace;
30
31 my $window = $x->root->create_child(
32     class => WINDOW_CLASS_INPUT_OUTPUT,
33     rect => [ 0, 0, 30, 30 ],
34     background_color => '#00ff00',
35 );
36
37 $window->name('Border window');
38 $window->map;
39 sleep 0.25;
40
41 my @content = @{get_ws_content($tmp)};
42 cmp_ok(@content, '==', 1, 'one node on this workspace now');
43 is($content[0]->{border}, 'normal', 'normal border');
44
45 $window->unmap;
46 sleep 0.25;
47
48 my @content = @{get_ws_content($tmp)};
49 cmp_ok(@content, '==', 0, 'no more nodes');
50 diag('content = '. Dumper(\@content));
51
52 $window = $x->root->create_child(
53     class => WINDOW_CLASS_INPUT_OUTPUT,
54     rect => [ 0, 0, 30, 30 ],
55     background_color => '#00ff00',
56 );
57
58 $window->_create;
59
60 # TODO: move this to X11::XCB::Window
61 sub set_wm_class {
62     my ($id, $class, $instance) = @_;
63
64     # Add a _NET_WM_STRUT_PARTIAL hint
65     my $atomname = $x->atom(name => 'WM_CLASS');
66     my $atomtype = $x->atom(name => 'STRING');
67
68     $x->change_property(
69         PROP_MODE_REPLACE,
70         $id,
71         $atomname->id,
72         $atomtype->id,
73         8,
74         length($class) + length($instance) + 2,
75         "$instance\x00$class\x00"
76     );
77 }
78
79 set_wm_class($window->id, 'borderless', 'borderless');
80 $window->name('Borderless window');
81 $window->map;
82 sleep 0.25;
83
84 @content = @{get_ws_content($tmp)};
85 cmp_ok(@content, '==', 1, 'one node on this workspace now');
86 is($content[0]->{border}, 'none', 'no border');
87
88 $window->unmap;
89 sleep 0.25;
90
91 @content = @{get_ws_content($tmp)};
92 cmp_ok(@content, '==', 0, 'no more nodes');
93
94 exit_gracefully($process->pid);
95
96 ##############################################################
97 # 2: match on the title, check if for_window is really executed
98 # only once
99 ##############################################################
100
101 $config = <<EOT;
102 # i3 config file (v4)
103 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
104 for_window [class="borderless"] border none
105 for_window [title="special borderless title"] border none
106 EOT
107
108 $process = launch_with_config($config);
109
110 $tmp = fresh_workspace;
111
112 $window = $x->root->create_child(
113     class => WINDOW_CLASS_INPUT_OUTPUT,
114     rect => [ 0, 0, 30, 30 ],
115     background_color => '#00ff00',
116 );
117
118 $window->name('special title');
119 $window->map;
120 sleep 0.25;
121
122 @content = @{get_ws_content($tmp)};
123 cmp_ok(@content, '==', 1, 'one node on this workspace now');
124 is($content[0]->{border}, 'normal', 'normal border');
125
126 $window->name('special borderless title');
127 sleep 0.25;
128
129 @content = @{get_ws_content($tmp)};
130 is($content[0]->{border}, 'none', 'no border');
131
132 $window->name('special title');
133 sleep 0.25;
134
135 cmd 'border normal';
136
137 @content = @{get_ws_content($tmp)};
138 is($content[0]->{border}, 'normal', 'border reset to normal');
139
140 $window->name('special borderless title');
141 sleep 0.25;
142
143 @content = @{get_ws_content($tmp)};
144 is($content[0]->{border}, 'normal', 'still normal border');
145
146 $window->unmap;
147 sleep 0.25;
148
149 @content = @{get_ws_content($tmp)};
150 cmp_ok(@content, '==', 0, 'no more nodes');
151
152 exit_gracefully($process->pid);
153
154 ##############################################################
155 # 3: match on the title, set border style *and* a mark
156 ##############################################################
157
158 $config = <<EOT;
159 # i3 config file (v4)
160 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
161 for_window [class="borderless" title="usethis"] border none
162 for_window [class="borderless"] border none
163 for_window [title="special borderless title"] border none
164 for_window [title="special mark title"] border none, mark bleh
165 EOT
166
167 $process = launch_with_config($config);
168
169 $tmp = fresh_workspace;
170
171 $window = $x->root->create_child(
172     class => WINDOW_CLASS_INPUT_OUTPUT,
173     rect => [ 0, 0, 30, 30 ],
174     background_color => '#00ff00',
175 );
176
177 $window->name('special mark title');
178 $window->map;
179 sleep 0.25;
180
181 @content = @{get_ws_content($tmp)};
182 cmp_ok(@content, '==', 1, 'one node on this workspace now');
183 is($content[0]->{border}, 'none', 'no border');
184
185 my $other = open_standard_window($x);
186
187 @content = @{get_ws_content($tmp)};
188 cmp_ok(@content, '==', 2, 'two nodes');
189 is($content[0]->{border}, 'none', 'no border');
190 is($content[1]->{border}, 'normal', 'normal border');
191 ok(!$content[0]->{focused}, 'first one not focused');
192
193 cmd qq|[con_mark="bleh"] focus|;
194
195 @content = @{get_ws_content($tmp)};
196 ok($content[0]->{focused}, 'first node focused');
197
198 exit_gracefully($process->pid);
199
200 ##############################################################
201 # 4: multiple criteria for the for_window command
202 ##############################################################
203
204 $config = <<EOT;
205 # i3 config file (v4)
206 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
207 for_window [class="borderless" title="usethis"] border none
208 EOT
209
210 $process = launch_with_config($config);
211
212 $tmp = fresh_workspace;
213
214 $window = $x->root->create_child(
215     class => WINDOW_CLASS_INPUT_OUTPUT,
216     rect => [ 0, 0, 30, 30 ],
217     background_color => '#00ff00',
218 );
219
220 $window->_create;
221
222 set_wm_class($window->id, 'borderless', 'borderless');
223 $window->name('usethis');
224 $window->map;
225 sleep 0.25;
226
227 @content = @{get_ws_content($tmp)};
228 cmp_ok(@content, '==', 1, 'one node on this workspace now');
229 is($content[0]->{border}, 'none', 'no border');
230
231 $window->unmap;
232 sleep 0.25;
233
234 @content = @{get_ws_content($tmp)};
235 cmp_ok(@content, '==', 0, 'no nodes on this workspace now');
236
237 set_wm_class($window->id, 'borderless', 'borderless');
238 $window->name('notthis');
239 $window->map;
240 sleep 0.25;
241
242 @content = @{get_ws_content($tmp)};
243 cmp_ok(@content, '==', 1, 'one node on this workspace now');
244 is($content[0]->{border}, 'normal', 'no border');
245
246
247 exit_gracefully($process->pid);
248
249 ##############################################################
250 # 5: check that a class criterion does not match the instance
251 ##############################################################
252
253 $config = <<EOT;
254 # i3 config file (v4)
255 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
256 for_window [class="foo"] border 1pixel
257 EOT
258
259 $process = launch_with_config($config);
260
261 $tmp = fresh_workspace;
262
263 $window = $x->root->create_child(
264     class => WINDOW_CLASS_INPUT_OUTPUT,
265     rect => [ 0, 0, 30, 30 ],
266     background_color => '#00ff00',
267 );
268
269 $window->_create;
270
271 set_wm_class($window->id, 'bar', 'foo');
272 $window->name('usethis');
273 $window->map;
274 sleep 0.25;
275
276 @content = @{get_ws_content($tmp)};
277 cmp_ok(@content, '==', 1, 'one node on this workspace now');
278 is($content[0]->{border}, 'normal', 'normal border, not matched');
279
280 exit_gracefully($process->pid);
281
282 ##############################################################
283 # 6: check that the 'instance' criterion works
284 ##############################################################
285
286 $config = <<EOT;
287 # i3 config file (v4)
288 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
289 for_window [class="foo"] border 1pixel
290 for_window [instance="foo"] border none
291 EOT
292
293 $process = launch_with_config($config);
294
295 $tmp = fresh_workspace;
296
297 $window = $x->root->create_child(
298     class => WINDOW_CLASS_INPUT_OUTPUT,
299     rect => [ 0, 0, 30, 30 ],
300     background_color => '#00ff00',
301 );
302
303 $window->_create;
304
305 set_wm_class($window->id, 'bar', 'foo');
306 $window->name('usethis');
307 $window->map;
308 sleep 0.25;
309
310 @content = @{get_ws_content($tmp)};
311 cmp_ok(@content, '==', 1, 'one node on this workspace now');
312 is($content[0]->{border}, 'none', 'no border');
313
314 exit_gracefully($process->pid);
315
316 ##############################################################
317 # 7: check that invalid criteria don’t end up matching all windows
318 ##############################################################
319
320 # this configuration is broken because "asdf" is not a valid integer
321 # the for_window should therefore recognize this error and don’t add the
322 # assignment
323 $config = <<EOT;
324 # i3 config file (v4)
325 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
326 for_window [id="asdf"] border none
327 EOT
328
329 $process = launch_with_config($config);
330
331 $tmp = fresh_workspace;
332
333 $window = $x->root->create_child(
334     class => WINDOW_CLASS_INPUT_OUTPUT,
335     rect => [ 0, 0, 30, 30 ],
336     background_color => '#00ff00',
337 );
338
339 $window->_create;
340
341 set_wm_class($window->id, 'bar', 'foo');
342 $window->name('usethis');
343 $window->map;
344 sleep 0.25;
345
346 @content = @{get_ws_content($tmp)};
347 cmp_ok(@content, '==', 1, 'one node on this workspace now');
348 is($content[0]->{border}, 'normal', 'normal border');
349
350 exit_gracefully($process->pid);
351
352
353 done_testing;