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);
24 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
27 for_window [class="borderless$"] border none
28 for_window [title="special borderless title"] border none
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
37 for_window [class="borderless4$" title="usethis"] border none
40 for_window [class="foo$"] border 1pixel
43 for_window [instance="foo6"] border none
46 for_window [id="asdf"] border none
49 for_window [window_role="i3test"] border none
52 for_window [workspace="trigger"] floating enable, mark triggered
55 # test all 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'
69 for my $window_type (keys %window_types) {
71 for_window [window_type="$window_type"] floating enable, mark branded-$window_type
75 my $pid = launch_with_config($config);
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 ##############################################################
85 my $tmp = fresh_workspace;
87 my $window = open_window(name => 'Border window');
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');
94 wait_for_unmap $window;
96 @content = @{get_ws_content($tmp)};
97 cmp_ok(@content, '==', 0, 'no more nodes');
98 diag('content = '. Dumper(\@content));
100 $window = open_window(
101 name => 'Borderless window',
102 wm_class => 'borderless',
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');
110 wait_for_unmap $window;
112 @content = @{get_ws_content($tmp)};
113 cmp_ok(@content, '==', 0, 'no more nodes');
117 ##############################################################
118 # 2: match on the title, check if for_window is really executed
120 ##############################################################
122 $tmp = fresh_workspace;
124 $window = open_window(name => 'special title');
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');
130 $window->name('special borderless title');
133 @content = @{get_ws_content($tmp)};
134 is($content[0]->{border}, 'none', 'no border');
136 $window->name('special title');
141 @content = @{get_ws_content($tmp)};
142 is($content[0]->{border}, 'normal', 'border reset to normal');
144 $window->name('special borderless title');
147 @content = @{get_ws_content($tmp)};
148 is($content[0]->{border}, 'normal', 'still normal border');
151 wait_for_unmap $window;
153 @content = @{get_ws_content($tmp)};
154 cmp_ok(@content, '==', 0, 'no more nodes');
158 ##############################################################
159 # 3: match on the title, set border style *and* a mark
160 ##############################################################
162 $tmp = fresh_workspace;
164 $window = open_window(name => 'special mark title');
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');
170 my $other = open_window;
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');
178 cmd qq|[con_mark="bleh"] focus|;
180 @content = @{get_ws_content($tmp)};
181 ok($content[0]->{focused}, 'first node focused');
185 ##############################################################
186 # 4: multiple criteria for the for_window command
187 ##############################################################
189 $tmp = fresh_workspace;
191 $window = open_window(
193 wm_class => 'borderless4',
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');
201 wait_for_unmap $window;
204 # give i3 a chance to delete the window from its tree
207 @content = @{get_ws_content($tmp)};
208 cmp_ok(@content, '==', 0, 'no nodes on this workspace now');
211 $window->wm_class('borderless4');
212 $window->name('notthis');
214 wait_for_map $window;
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');
222 ##############################################################
223 # 5: check that a class criterion does not match the instance
224 ##############################################################
226 $tmp = fresh_workspace;
228 $window = open_window(
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');
240 ##############################################################
241 # 6: check that the 'instance' criterion works
242 ##############################################################
244 $tmp = fresh_workspace;
246 $window = open_window(
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');
258 ##############################################################
259 # 7: check that invalid criteria don’t end up matching all windows
260 ##############################################################
262 $tmp = fresh_workspace;
264 $window = open_window(
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');
276 ##############################################################
277 # 8: check that the role criterion works properly
278 ##############################################################
280 $tmp = fresh_workspace;
282 $window = open_window(
286 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
287 my $atomtype = $x->atom(name => 'STRING');
294 length("i3test") + 1,
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)');
306 ##############################################################
307 # 9: another test for the window_role, but this time it changes
308 # *after* the window has been mapped
309 ##############################################################
311 $tmp = fresh_workspace;
313 $window = open_window(name => 'usethis');
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)');
319 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
320 my $atomtype = $x->atom(name => 'STRING');
327 length("i3test") + 1,
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)');
341 ##############################################################
342 # 10: check that the criterion 'window_type' works
343 ##############################################################
345 while (my ($window_type, $atom) = each %window_types) {
346 $tmp = fresh_workspace;
348 $window = open_window(window_type => $x->atom(name => $atom));
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)");
357 ##############################################################
358 # 11: check that the criterion 'window_type' works if the
359 # _NET_WM_WINDOW_TYPE is changed after managing.
360 ##############################################################
362 while (my ($window_type, $atom) = each %window_types) {
363 $tmp = fresh_workspace;
365 $window = open_window();
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));
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)");
381 ##############################################################
382 # 12: check that the criterion 'workspace' works
383 ##############################################################
385 cmd 'workspace trigger';
386 $window = open_window;
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");
394 ##############################################################
396 exit_gracefully($pid);