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');
115 ##############################################################
116 # 2: match on the title, check if for_window is really executed
118 ##############################################################
120 $tmp = fresh_workspace;
122 $window = open_window(name => 'special title');
124 @content = @{get_ws_content($tmp)};
125 cmp_ok(@content, '==', 1, 'one node on this workspace now');
126 is($content[0]->{border}, 'normal', 'normal border');
128 $window->name('special borderless title');
131 @content = @{get_ws_content($tmp)};
132 is($content[0]->{border}, 'none', 'no border');
134 $window->name('special title');
139 @content = @{get_ws_content($tmp)};
140 is($content[0]->{border}, 'normal', 'border reset to normal');
142 $window->name('special borderless title');
145 @content = @{get_ws_content($tmp)};
146 is($content[0]->{border}, 'normal', 'still normal border');
149 wait_for_unmap $window;
151 @content = @{get_ws_content($tmp)};
152 cmp_ok(@content, '==', 0, 'no more nodes');
154 ##############################################################
155 # 3: match on the title, set border style *and* a mark
156 ##############################################################
158 $tmp = fresh_workspace;
160 $window = open_window(name => 'special mark title');
162 @content = @{get_ws_content($tmp)};
163 cmp_ok(@content, '==', 1, 'one node on this workspace now');
164 is($content[0]->{border}, 'none', 'no border');
166 my $other = open_window;
168 @content = @{get_ws_content($tmp)};
169 cmp_ok(@content, '==', 2, 'two nodes');
170 is($content[0]->{border}, 'none', 'no border');
171 is($content[1]->{border}, 'normal', 'normal border');
172 ok(!$content[0]->{focused}, 'first one not focused');
174 cmd qq|[con_mark="bleh"] focus|;
176 @content = @{get_ws_content($tmp)};
177 ok($content[0]->{focused}, 'first node focused');
179 ##############################################################
180 # 4: multiple criteria for the for_window command
181 ##############################################################
183 $tmp = fresh_workspace;
185 $window = open_window(
187 wm_class => 'borderless4',
190 @content = @{get_ws_content($tmp)};
191 cmp_ok(@content, '==', 1, 'one node on this workspace now');
192 is($content[0]->{border}, 'none', 'no border');
195 wait_for_unmap $window;
198 # give i3 a chance to delete the window from its tree
201 @content = @{get_ws_content($tmp)};
202 cmp_ok(@content, '==', 0, 'no nodes on this workspace now');
205 $window->wm_class('borderless4');
206 $window->name('notthis');
208 wait_for_map $window;
210 @content = @{get_ws_content($tmp)};
211 cmp_ok(@content, '==', 1, 'one node on this workspace now');
212 is($content[0]->{border}, 'normal', 'no border');
214 ##############################################################
215 # 5: check that a class criterion does not match the instance
216 ##############################################################
218 $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 ##############################################################
231 # 6: check that the 'instance' criterion works
232 ##############################################################
234 $tmp = fresh_workspace;
236 $window = open_window(
242 @content = @{get_ws_content($tmp)};
243 cmp_ok(@content, '==', 1, 'one node on this workspace now');
244 is($content[0]->{border}, 'none', 'no border');
246 ##############################################################
247 # 7: check that invalid criteria don’t end up matching all windows
248 ##############################################################
250 $tmp = fresh_workspace;
252 $window = open_window(
258 @content = @{get_ws_content($tmp)};
259 cmp_ok(@content, '==', 1, 'one node on this workspace now');
260 is($content[0]->{border}, 'normal', 'normal border');
262 ##############################################################
263 # 8: check that the role criterion works properly
264 ##############################################################
266 $tmp = fresh_workspace;
268 $window = open_window(
272 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
273 my $atomtype = $x->atom(name => 'STRING');
280 length("i3test") + 1,
286 @content = @{get_ws_content($tmp)};
287 cmp_ok(@content, '==', 1, 'one node on this workspace now');
288 is($content[0]->{border}, 'none', 'no border (window_role)');
290 ##############################################################
291 # 9: another test for the window_role, but this time it changes
292 # *after* the window has been mapped
293 ##############################################################
295 $tmp = fresh_workspace;
297 $window = open_window(name => 'usethis');
299 @content = @{get_ws_content($tmp)};
300 cmp_ok(@content, '==', 1, 'one node on this workspace now');
301 is($content[0]->{border}, 'normal', 'normal border (window_role 2)');
303 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
304 my $atomtype = $x->atom(name => 'STRING');
311 length("i3test") + 1,
319 @content = @{get_ws_content($tmp)};
320 cmp_ok(@content, '==', 1, 'one node on this workspace now');
321 is($content[0]->{border}, 'none', 'no border (window_role 2)');
323 ##############################################################
324 # 10: check that the criterion 'window_type' works
325 ##############################################################
327 while (my ($window_type, $atom) = each %window_types) {
328 $tmp = fresh_workspace;
330 $window = open_window(window_type => $x->atom(name => $atom));
332 my @nodes = @{get_ws($tmp)->{floating_nodes}};
333 cmp_ok(@nodes, '==', 1, 'one floating container on this workspace');
334 is_deeply($nodes[0]->{nodes}[0]->{marks}, [ "branded-$window_type" ], "mark set (window_type = $atom)");
337 ##############################################################
338 # 11: check that the criterion 'window_type' works if the
339 # _NET_WM_WINDOW_TYPE is changed after managing.
340 ##############################################################
342 while (my ($window_type, $atom) = each %window_types) {
343 $tmp = fresh_workspace;
345 $window = open_window();
347 my $atomname = $x->atom(name => '_NET_WM_WINDOW_TYPE');
348 my $atomtype = $x->atom(name => 'ATOM');
349 $x->change_property(PROP_MODE_REPLACE, $window->id, $atomname->id, $atomtype->id,
350 32, 1, pack('L1', $x->atom(name => $atom)->id));
354 my @nodes = @{get_ws($tmp)->{floating_nodes}};
355 cmp_ok(@nodes, '==', 1, 'one floating container on this workspace');
356 is_deeply($nodes[0]->{nodes}[0]->{marks}, [ "branded-$window_type" ], "mark set (window_type = $atom)");
359 ##############################################################
360 # 12: check that the criterion 'workspace' works
361 ##############################################################
363 cmd 'workspace trigger';
364 $window = open_window;
366 @nodes = @{get_ws('trigger')->{floating_nodes}};
367 cmp_ok(@nodes, '==', 1, 'one floating container on this workspace');
368 is_deeply($nodes[0]->{nodes}[0]->{marks}, [ 'triggered' ], "mark set for workspace criterion");
370 ##############################################################
372 exit_gracefully($pid);