2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 use i3test i3_autostart => 0;
18 use X11::XCB qw(PROP_MODE_REPLACE);
22 ##############################################################
23 # 1: test the following directive:
24 # for_window [class="borderless"] border none
25 # by first creating a window with a different class (should get
26 # the normal border), then creating a window with the class
27 # "borderless" (should get no border)
28 ##############################################################
32 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
33 for_window [class="borderless"] border none
34 for_window [title="special borderless title"] border none
37 my $pid = launch_with_config($config);
39 my $tmp = fresh_workspace;
41 my $window = open_window(name => 'Border window');
43 my @content = @{get_ws_content($tmp)};
44 cmp_ok(@content, '==', 1, 'one node on this workspace now');
45 is($content[0]->{border}, 'normal', 'normal border');
48 wait_for_unmap $window;
50 @content = @{get_ws_content($tmp)};
51 cmp_ok(@content, '==', 0, 'no more nodes');
52 diag('content = '. Dumper(\@content));
54 $window = open_window(
55 name => 'Borderless window',
56 wm_class => 'borderless',
59 @content = @{get_ws_content($tmp)};
60 cmp_ok(@content, '==', 1, 'one node on this workspace now');
61 is($content[0]->{border}, 'none', 'no border');
64 wait_for_unmap $window;
66 @content = @{get_ws_content($tmp)};
67 cmp_ok(@content, '==', 0, 'no more nodes');
69 exit_gracefully($pid);
71 ##############################################################
72 # 2: match on the title, check if for_window is really executed
74 ##############################################################
78 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
79 for_window [class="borderless"] border none
80 for_window [title="special borderless title"] border none
83 $pid = launch_with_config($config);
85 $tmp = fresh_workspace;
87 $window = open_window(name => 'special title');
89 @content = @{get_ws_content($tmp)};
90 cmp_ok(@content, '==', 1, 'one node on this workspace now');
91 is($content[0]->{border}, 'normal', 'normal border');
93 $window->name('special borderless title');
96 @content = @{get_ws_content($tmp)};
97 is($content[0]->{border}, 'none', 'no border');
99 $window->name('special title');
104 @content = @{get_ws_content($tmp)};
105 is($content[0]->{border}, 'normal', 'border reset to normal');
107 $window->name('special borderless title');
110 @content = @{get_ws_content($tmp)};
111 is($content[0]->{border}, 'normal', 'still normal border');
114 wait_for_unmap $window;
116 @content = @{get_ws_content($tmp)};
117 cmp_ok(@content, '==', 0, 'no more nodes');
119 exit_gracefully($pid);
121 ##############################################################
122 # 3: match on the title, set border style *and* a mark
123 ##############################################################
126 # i3 config file (v4)
127 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
128 for_window [class="borderless" title="usethis"] border none
129 for_window [class="borderless"] border none
130 for_window [title="special borderless title"] border none
131 for_window [title="special mark title"] border none, mark bleh
134 $pid = launch_with_config($config);
136 $tmp = fresh_workspace;
138 $window = open_window(name => 'special mark title');
140 @content = @{get_ws_content($tmp)};
141 cmp_ok(@content, '==', 1, 'one node on this workspace now');
142 is($content[0]->{border}, 'none', 'no border');
144 my $other = open_window;
146 @content = @{get_ws_content($tmp)};
147 cmp_ok(@content, '==', 2, 'two nodes');
148 is($content[0]->{border}, 'none', 'no border');
149 is($content[1]->{border}, 'normal', 'normal border');
150 ok(!$content[0]->{focused}, 'first one not focused');
152 cmd qq|[con_mark="bleh"] focus|;
154 @content = @{get_ws_content($tmp)};
155 ok($content[0]->{focused}, 'first node focused');
157 exit_gracefully($pid);
159 ##############################################################
160 # 4: multiple criteria for the for_window command
161 ##############################################################
164 # i3 config file (v4)
165 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
166 for_window [class="borderless" title="usethis"] border none
169 $pid = launch_with_config($config);
171 $tmp = fresh_workspace;
173 $window = open_window(
175 wm_class => 'borderless',
178 @content = @{get_ws_content($tmp)};
179 cmp_ok(@content, '==', 1, 'one node on this workspace now');
180 is($content[0]->{border}, 'none', 'no border');
183 wait_for_unmap $window;
186 # give i3 a chance to delete the window from its tree
189 @content = @{get_ws_content($tmp)};
190 cmp_ok(@content, '==', 0, 'no nodes on this workspace now');
193 $window->wm_class('borderless');
194 $window->name('notthis');
196 wait_for_map $window;
198 @content = @{get_ws_content($tmp)};
199 cmp_ok(@content, '==', 1, 'one node on this workspace now');
200 is($content[0]->{border}, 'normal', 'no border');
203 exit_gracefully($pid);
205 ##############################################################
206 # 5: check that a class criterion does not match the instance
207 ##############################################################
210 # i3 config file (v4)
211 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
212 for_window [class="foo"] border 1pixel
215 $pid = launch_with_config($config);
217 $tmp = fresh_workspace;
220 $window = open_window(
226 @content = @{get_ws_content($tmp)};
227 cmp_ok(@content, '==', 1, 'one node on this workspace now');
228 is($content[0]->{border}, 'normal', 'normal border, not matched');
230 exit_gracefully($pid);
232 ##############################################################
233 # 6: check that the 'instance' criterion works
234 ##############################################################
237 # i3 config file (v4)
238 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
239 for_window [class="foo"] border 1pixel
240 for_window [instance="foo"] border none
243 $pid = launch_with_config($config);
245 $tmp = fresh_workspace;
247 $window = open_window(
253 @content = @{get_ws_content($tmp)};
254 cmp_ok(@content, '==', 1, 'one node on this workspace now');
255 is($content[0]->{border}, 'none', 'no border');
257 exit_gracefully($pid);
259 ##############################################################
260 # 7: check that invalid criteria don’t end up matching all windows
261 ##############################################################
263 # this configuration is broken because "asdf" is not a valid integer
264 # the for_window should therefore recognize this error and don’t add the
267 # i3 config file (v4)
268 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
269 for_window [id="asdf"] border none
272 $pid = launch_with_config($config);
274 $tmp = fresh_workspace;
276 $window = open_window(
282 @content = @{get_ws_content($tmp)};
283 cmp_ok(@content, '==', 1, 'one node on this workspace now');
284 is($content[0]->{border}, 'normal', 'normal border');
286 exit_gracefully($pid);
288 ##############################################################
289 # 8: check that the role criterion works properly
290 ##############################################################
293 # i3 config file (v4)
294 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
295 for_window [window_role="i3test"] border none
298 $pid = launch_with_config($config);
300 $tmp = fresh_workspace;
302 $window = open_window(
306 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
307 my $atomtype = $x->atom(name => 'STRING');
314 length("i3test") + 1,
320 @content = @{get_ws_content($tmp)};
321 cmp_ok(@content, '==', 1, 'one node on this workspace now');
322 is($content[0]->{border}, 'none', 'no border (window_role)');
324 exit_gracefully($pid);
326 ##############################################################
327 # 9: another test for the window_role, but this time it changes
328 # *after* the window has been mapped
329 ##############################################################
332 # i3 config file (v4)
333 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
334 for_window [window_role="i3test"] border none
337 $pid = launch_with_config($config);
339 $tmp = fresh_workspace;
341 $window = open_window(name => 'usethis');
343 @content = @{get_ws_content($tmp)};
344 cmp_ok(@content, '==', 1, 'one node on this workspace now');
345 is($content[0]->{border}, 'normal', 'normal border (window_role 2)');
347 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
348 my $atomtype = $x->atom(name => 'STRING');
355 length("i3test") + 1,
363 @content = @{get_ws_content($tmp)};
364 cmp_ok(@content, '==', 1, 'one node on this workspace now');
365 is($content[0]->{border}, 'none', 'no border (window_role 2)');
367 exit_gracefully($pid);
369 ##############################################################
370 # 10: check that the criterion 'window_type' works
371 ##############################################################
373 # test all window types
375 'normal' => '_NET_WM_WINDOW_TYPE_NORMAL',
376 'dialog' => '_NET_WM_WINDOW_TYPE_DIALOG',
377 'utility' => '_NET_WM_WINDOW_TYPE_UTILITY',
378 'toolbar' => '_NET_WM_WINDOW_TYPE_TOOLBAR',
379 'splash' => '_NET_WM_WINDOW_TYPE_SPLASH',
380 'menu' => '_NET_WM_WINDOW_TYPE_MENU',
381 'dropdown_menu' => '_NET_WM_WINDOW_TYPE_DROPDOWN_MENU',
382 'popup_menu' => '_NET_WM_WINDOW_TYPE_POPUP_MENU',
383 'tooltip' => '_NET_WM_WINDOW_TYPE_TOOLTIP',
384 'notification' => '_NET_WM_WINDOW_TYPE_NOTIFICATION'
387 while (my ($window_type, $atom) = each %window_types) {
390 # i3 config file (v4)
391 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
392 for_window [window_type="$window_type"] floating enable, mark branded
395 $pid = launch_with_config($config);
396 $tmp = fresh_workspace;
398 $window = open_window(window_type => $x->atom(name => $atom));
400 my @nodes = @{get_ws($tmp)->{floating_nodes}};
401 cmp_ok(@nodes, '==', 1, 'one floating container on this workspace');
402 is_deeply($nodes[0]->{nodes}[0]->{marks}, [ 'branded' ], "mark set (window_type = $atom)");
404 exit_gracefully($pid);
408 ##############################################################
409 # 11: check that the criterion 'window_type' works if the
410 # _NET_WM_WINDOW_TYPE is changed after managing.
411 ##############################################################
413 while (my ($window_type, $atom) = each %window_types) {
416 # i3 config file (v4)
417 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
418 for_window [window_type="$window_type"] floating enable, mark branded
421 $pid = launch_with_config($config);
422 $tmp = fresh_workspace;
424 $window = open_window();
426 my $atomname = $x->atom(name => '_NET_WM_WINDOW_TYPE');
427 my $atomtype = $x->atom(name => 'ATOM');
428 $x->change_property(PROP_MODE_REPLACE, $window->id, $atomname->id, $atomtype->id,
429 32, 1, pack('L1', $x->atom(name => $atom)->id));
433 my @nodes = @{get_ws($tmp)->{floating_nodes}};
434 cmp_ok(@nodes, '==', 1, 'one floating container on this workspace');
435 is_deeply($nodes[0]->{nodes}[0]->{marks}, [ 'branded' ], "mark set (window_type = $atom)");
437 exit_gracefully($pid);
441 ##############################################################
442 # 12: check that the criterion 'workspace' works
443 ##############################################################
446 # i3 config file (v4)
447 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
448 for_window [workspace="trigger"] floating enable, mark triggered
451 $pid = launch_with_config($config);
453 cmd 'workspace trigger';
454 $window = open_window;
456 @nodes = @{get_ws('trigger')->{floating_nodes}};
457 cmp_ok(@nodes, '==', 1, 'one floating container on this workspace');
458 is_deeply($nodes[0]->{nodes}[0]->{marks}, [ 'triggered' ], "mark set for workspace criterion");
460 exit_gracefully($pid);
462 ##############################################################