]> git.sur5r.net Git - i3/i3/blob - testcases/t/165-for_window.t
Merge "force_focus_wrapping" option into "focus_wrapping force"
[i3/i3] / testcases / t / 165-for_window.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://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 use i3test i3_autostart => 0;
18 use X11::XCB qw(PROP_MODE_REPLACE);
19
20 my (@nodes);
21
22 my $config = <<'EOT';
23 # i3 config file (v4)
24 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
25
26 # test 1, test 2
27 for_window [class="borderless$"] border none
28 for_window [title="special borderless title"] border none
29
30 # test 3
31 for_window [class="borderless3$" title="usethis"] border none
32 for_window [class="borderless3$"] border none
33 for_window [title="special borderless title"] border none
34 for_window [title="special mark title"] border none, mark bleh
35
36 # test 4
37 for_window [class="borderless4$" title="usethis"] border none
38
39 # test 5, test 6
40 for_window [class="foo$"] border 1pixel
41
42 # test 6
43 for_window [instance="foo6"] border none
44
45 # test 7
46 for_window [id="asdf"] border none
47
48 # test 8, test 9
49 for_window [window_role="i3test"] border none
50
51 # test 12
52 for_window [workspace="trigger"] floating enable, mark triggered
53 EOT
54
55 # test all window types
56 my %window_types = (
57     'normal'        => '_NET_WM_WINDOW_TYPE_NORMAL',
58     'dialog'        => '_NET_WM_WINDOW_TYPE_DIALOG',
59     'utility'       => '_NET_WM_WINDOW_TYPE_UTILITY',
60     'toolbar'       => '_NET_WM_WINDOW_TYPE_TOOLBAR',
61     'splash'        => '_NET_WM_WINDOW_TYPE_SPLASH',
62     'menu'          => '_NET_WM_WINDOW_TYPE_MENU',
63     'dropdown_menu' => '_NET_WM_WINDOW_TYPE_DROPDOWN_MENU',
64     'popup_menu'    => '_NET_WM_WINDOW_TYPE_POPUP_MENU',
65     'tooltip'       => '_NET_WM_WINDOW_TYPE_TOOLTIP',
66     'notification'  => '_NET_WM_WINDOW_TYPE_NOTIFICATION'
67 );
68
69 for my $window_type (keys %window_types) {
70     $config .= <<EOT;
71 for_window [window_type="$window_type"] floating enable, mark branded-$window_type
72 EOT
73 }
74
75 my $pid = launch_with_config($config);
76
77 ##############################################################
78 # 1: test the following directive:
79 #    for_window [class="borderless"] border none
80 # by first creating a window with a different class (should get
81 # the normal border), then creating a window with the class
82 # "borderless" (should get no border)
83 ##############################################################
84
85 my $tmp = fresh_workspace;
86
87 my $window = open_window(name => 'Border window');
88
89 my @content = @{get_ws_content($tmp)};
90 cmp_ok(@content, '==', 1, 'one node on this workspace now');
91 is($content[0]->{border}, 'normal', 'normal border');
92
93 $window->unmap;
94 wait_for_unmap $window;
95
96 @content = @{get_ws_content($tmp)};
97 cmp_ok(@content, '==', 0, 'no more nodes');
98 diag('content = '. Dumper(\@content));
99
100 $window = open_window(
101     name => 'Borderless window',
102     wm_class => 'borderless',
103 );
104
105 @content = @{get_ws_content($tmp)};
106 cmp_ok(@content, '==', 1, 'one node on this workspace now');
107 is($content[0]->{border}, 'none', 'no border');
108
109 $window->unmap;
110 wait_for_unmap $window;
111
112 @content = @{get_ws_content($tmp)};
113 cmp_ok(@content, '==', 0, 'no more nodes');
114
115 kill_all_windows;
116
117 ##############################################################
118 # 2: match on the title, check if for_window is really executed
119 # only once
120 ##############################################################
121
122 $tmp = fresh_workspace;
123
124 $window = open_window(name => 'special title');
125
126 @content = @{get_ws_content($tmp)};
127 cmp_ok(@content, '==', 1, 'one node on this workspace now');
128 is($content[0]->{border}, 'normal', 'normal border');
129
130 $window->name('special borderless title');
131 sync_with_i3;
132
133 @content = @{get_ws_content($tmp)};
134 is($content[0]->{border}, 'none', 'no border');
135
136 $window->name('special title');
137 sync_with_i3;
138
139 cmd 'border normal';
140
141 @content = @{get_ws_content($tmp)};
142 is($content[0]->{border}, 'normal', 'border reset to normal');
143
144 $window->name('special borderless title');
145 sync_with_i3;
146
147 @content = @{get_ws_content($tmp)};
148 is($content[0]->{border}, 'normal', 'still normal border');
149
150 $window->unmap;
151 wait_for_unmap $window;
152
153 @content = @{get_ws_content($tmp)};
154 cmp_ok(@content, '==', 0, 'no more nodes');
155
156 kill_all_windows;
157
158 ##############################################################
159 # 3: match on the title, set border style *and* a mark
160 ##############################################################
161
162 $tmp = fresh_workspace;
163
164 $window = open_window(name => 'special mark title');
165
166 @content = @{get_ws_content($tmp)};
167 cmp_ok(@content, '==', 1, 'one node on this workspace now');
168 is($content[0]->{border}, 'none', 'no border');
169
170 my $other = open_window;
171
172 @content = @{get_ws_content($tmp)};
173 cmp_ok(@content, '==', 2, 'two nodes');
174 is($content[0]->{border}, 'none', 'no border');
175 is($content[1]->{border}, 'normal', 'normal border');
176 ok(!$content[0]->{focused}, 'first one not focused');
177
178 cmd qq|[con_mark="bleh"] focus|;
179
180 @content = @{get_ws_content($tmp)};
181 ok($content[0]->{focused}, 'first node focused');
182
183 kill_all_windows;
184
185 ##############################################################
186 # 4: multiple criteria for the for_window command
187 ##############################################################
188
189 $tmp = fresh_workspace;
190
191 $window = open_window(
192     name => 'usethis',
193     wm_class => 'borderless4',
194 );
195
196 @content = @{get_ws_content($tmp)};
197 cmp_ok(@content, '==', 1, 'one node on this workspace now');
198 is($content[0]->{border}, 'none', 'no border');
199
200 cmd 'kill';
201 wait_for_unmap $window;
202 $window->destroy;
203
204 # give i3 a chance to delete the window from its tree
205 sync_with_i3;
206
207 @content = @{get_ws_content($tmp)};
208 cmp_ok(@content, '==', 0, 'no nodes on this workspace now');
209
210 $window->_create;
211 $window->wm_class('borderless4');
212 $window->name('notthis');
213 $window->map;
214 wait_for_map $window;
215
216 @content = @{get_ws_content($tmp)};
217 cmp_ok(@content, '==', 1, 'one node on this workspace now');
218 is($content[0]->{border}, 'normal', 'no border');
219
220 kill_all_windows;
221
222 ##############################################################
223 # 5: check that a class criterion does not match the instance
224 ##############################################################
225
226 $tmp = fresh_workspace;
227
228 $window = open_window(
229     name => 'usethis',
230     wm_class => 'bar',
231     instance => 'foo',
232 );
233
234 @content = @{get_ws_content($tmp)};
235 cmp_ok(@content, '==', 1, 'one node on this workspace now');
236 is($content[0]->{border}, 'normal', 'normal border, not matched');
237
238 kill_all_windows;
239
240 ##############################################################
241 # 6: check that the 'instance' criterion works
242 ##############################################################
243
244 $tmp = fresh_workspace;
245
246 $window = open_window(
247     name => 'usethis',
248     wm_class => 'bar',
249     instance => 'foo6',
250 );
251
252 @content = @{get_ws_content($tmp)};
253 cmp_ok(@content, '==', 1, 'one node on this workspace now');
254 is($content[0]->{border}, 'none', 'no border');
255
256 kill_all_windows;
257
258 ##############################################################
259 # 7: check that invalid criteria don’t end up matching all windows
260 ##############################################################
261
262 $tmp = fresh_workspace;
263
264 $window = open_window(
265     name => 'usethis',
266     wm_class => 'bar',
267     instance => 'foo',
268 );
269
270 @content = @{get_ws_content($tmp)};
271 cmp_ok(@content, '==', 1, 'one node on this workspace now');
272 is($content[0]->{border}, 'normal', 'normal border');
273
274 kill_all_windows;
275
276 ##############################################################
277 # 8: check that the role criterion works properly
278 ##############################################################
279
280 $tmp = fresh_workspace;
281
282 $window = open_window(
283     name => 'usethis',
284     before_map => sub {
285         my ($window) = @_;
286         my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
287         my $atomtype = $x->atom(name => 'STRING');
288         $x->change_property(
289             PROP_MODE_REPLACE,
290             $window->id,
291             $atomname->id,
292             $atomtype->id,
293             8,
294             length("i3test") + 1,
295             "i3test\x00"
296         );
297     },
298 );
299
300 @content = @{get_ws_content($tmp)};
301 cmp_ok(@content, '==', 1, 'one node on this workspace now');
302 is($content[0]->{border}, 'none', 'no border (window_role)');
303
304 kill_all_windows;
305
306 ##############################################################
307 # 9: another test for the window_role, but this time it changes
308 #    *after* the window has been mapped
309 ##############################################################
310
311 $tmp = fresh_workspace;
312
313 $window = open_window(name => 'usethis');
314
315 @content = @{get_ws_content($tmp)};
316 cmp_ok(@content, '==', 1, 'one node on this workspace now');
317 is($content[0]->{border}, 'normal', 'normal border (window_role 2)');
318
319 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
320 my $atomtype = $x->atom(name => 'STRING');
321 $x->change_property(
322   PROP_MODE_REPLACE,
323   $window->id,
324   $atomname->id,
325   $atomtype->id,
326   8,
327   length("i3test") + 1,
328   "i3test\x00"
329 );
330
331 $x->flush;
332
333 sync_with_i3;
334
335 @content = @{get_ws_content($tmp)};
336 cmp_ok(@content, '==', 1, 'one node on this workspace now');
337 is($content[0]->{border}, 'none', 'no border (window_role 2)');
338
339 kill_all_windows;
340
341 ##############################################################
342 # 10: check that the criterion 'window_type' works
343 ##############################################################
344
345 while (my ($window_type, $atom) = each %window_types) {
346     $tmp = fresh_workspace;
347
348     $window = open_window(window_type => $x->atom(name => $atom));
349
350     my @nodes = @{get_ws($tmp)->{floating_nodes}};
351     cmp_ok(@nodes, '==', 1, 'one floating container on this workspace');
352     is_deeply($nodes[0]->{nodes}[0]->{marks}, [ "branded-$window_type" ], "mark set (window_type = $atom)");
353
354     kill_all_windows;
355 }
356
357 ##############################################################
358 # 11: check that the criterion 'window_type' works if the
359 #     _NET_WM_WINDOW_TYPE is changed after managing.
360 ##############################################################
361
362 while (my ($window_type, $atom) = each %window_types) {
363     $tmp = fresh_workspace;
364
365     $window = open_window();
366
367     my $atomname = $x->atom(name => '_NET_WM_WINDOW_TYPE');
368     my $atomtype = $x->atom(name => 'ATOM');
369     $x->change_property(PROP_MODE_REPLACE, $window->id, $atomname->id, $atomtype->id,
370       32, 1, pack('L1', $x->atom(name => $atom)->id));
371     $x->flush;
372     sync_with_i3;
373
374     my @nodes = @{get_ws($tmp)->{floating_nodes}};
375     cmp_ok(@nodes, '==', 1, 'one floating container on this workspace');
376     is_deeply($nodes[0]->{nodes}[0]->{marks}, [ "branded-$window_type" ], "mark set (window_type = $atom)");
377
378     kill_all_windows;
379 }
380
381 ##############################################################
382 # 12: check that the criterion 'workspace' works
383 ##############################################################
384
385 cmd 'workspace trigger';
386 $window = open_window;
387
388 @nodes = @{get_ws('trigger')->{floating_nodes}};
389 cmp_ok(@nodes, '==', 1, 'one floating container on this workspace');
390 is_deeply($nodes[0]->{nodes}[0]->{marks}, [ 'triggered' ], "mark set for workspace criterion");
391
392 kill_all_windows;
393
394 ##############################################################
395
396 exit_gracefully($pid);
397
398 done_testing;