2 # vim:ts=4:sw=4:expandtab
4 use i3test i3_autostart => 0;
5 use X11::XCB qw(PROP_MODE_REPLACE);
7 ##############################################################
8 # 1: test the following directive:
9 # for_window [class="borderless"] border none
10 # by first creating a window with a different class (should get
11 # the normal border), then creating a window with the class
12 # "borderless" (should get no border)
13 ##############################################################
17 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
18 for_window [class="borderless"] border none
19 for_window [title="special borderless title"] border none
22 my $pid = launch_with_config($config);
24 my $tmp = fresh_workspace;
26 my $window = open_window(name => 'Border window');
28 my @content = @{get_ws_content($tmp)};
29 cmp_ok(@content, '==', 1, 'one node on this workspace now');
30 is($content[0]->{border}, 'normal', 'normal border');
33 wait_for_unmap $window;
35 @content = @{get_ws_content($tmp)};
36 cmp_ok(@content, '==', 0, 'no more nodes');
37 diag('content = '. Dumper(\@content));
40 # TODO: move this to X11::XCB::Window
42 my ($id, $class, $instance) = @_;
44 # Add a _NET_WM_STRUT_PARTIAL hint
45 my $atomname = $x->atom(name => 'WM_CLASS');
46 my $atomtype = $x->atom(name => 'STRING');
54 length($class) + length($instance) + 2,
55 "$instance\x00$class\x00"
59 $window = open_window(
60 name => 'Borderless window',
61 before_map => sub { set_wm_class($_->id, 'borderless', 'borderless') },
64 @content = @{get_ws_content($tmp)};
65 cmp_ok(@content, '==', 1, 'one node on this workspace now');
66 is($content[0]->{border}, 'none', 'no border');
69 wait_for_unmap $window;
71 @content = @{get_ws_content($tmp)};
72 cmp_ok(@content, '==', 0, 'no more nodes');
74 exit_gracefully($pid);
76 ##############################################################
77 # 2: match on the title, check if for_window is really executed
79 ##############################################################
83 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
84 for_window [class="borderless"] border none
85 for_window [title="special borderless title"] border none
88 $pid = launch_with_config($config);
90 $tmp = fresh_workspace;
92 $window = open_window(name => 'special title');
94 @content = @{get_ws_content($tmp)};
95 cmp_ok(@content, '==', 1, 'one node on this workspace now');
96 is($content[0]->{border}, 'normal', 'normal border');
98 $window->name('special borderless title');
101 @content = @{get_ws_content($tmp)};
102 is($content[0]->{border}, 'none', 'no border');
104 $window->name('special title');
109 @content = @{get_ws_content($tmp)};
110 is($content[0]->{border}, 'normal', 'border reset to normal');
112 $window->name('special borderless title');
115 @content = @{get_ws_content($tmp)};
116 is($content[0]->{border}, 'normal', 'still normal border');
119 wait_for_unmap $window;
121 @content = @{get_ws_content($tmp)};
122 cmp_ok(@content, '==', 0, 'no more nodes');
124 exit_gracefully($pid);
126 ##############################################################
127 # 3: match on the title, set border style *and* a mark
128 ##############################################################
131 # i3 config file (v4)
132 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
133 for_window [class="borderless" title="usethis"] border none
134 for_window [class="borderless"] border none
135 for_window [title="special borderless title"] border none
136 for_window [title="special mark title"] border none, mark bleh
139 $pid = launch_with_config($config);
141 $tmp = fresh_workspace;
143 $window = open_window(name => 'special mark title');
145 @content = @{get_ws_content($tmp)};
146 cmp_ok(@content, '==', 1, 'one node on this workspace now');
147 is($content[0]->{border}, 'none', 'no border');
149 my $other = open_window;
151 @content = @{get_ws_content($tmp)};
152 cmp_ok(@content, '==', 2, 'two nodes');
153 is($content[0]->{border}, 'none', 'no border');
154 is($content[1]->{border}, 'normal', 'normal border');
155 ok(!$content[0]->{focused}, 'first one not focused');
157 cmd qq|[con_mark="bleh"] focus|;
159 @content = @{get_ws_content($tmp)};
160 ok($content[0]->{focused}, 'first node focused');
162 exit_gracefully($pid);
164 ##############################################################
165 # 4: multiple criteria for the for_window command
166 ##############################################################
169 # i3 config file (v4)
170 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
171 for_window [class="borderless" title="usethis"] border none
174 $pid = launch_with_config($config);
176 $tmp = fresh_workspace;
178 $window = open_window(
180 before_map => sub { set_wm_class($_->id, 'borderless', 'borderless') },
183 @content = @{get_ws_content($tmp)};
184 cmp_ok(@content, '==', 1, 'one node on this workspace now');
185 is($content[0]->{border}, 'none', 'no border');
188 wait_for_unmap $window;
191 # give i3 a chance to delete the window from its tree
194 @content = @{get_ws_content($tmp)};
195 cmp_ok(@content, '==', 0, 'no nodes on this workspace now');
199 set_wm_class($window->id, 'borderless', 'borderless');
200 $window->name('notthis');
202 wait_for_map $window;
204 @content = @{get_ws_content($tmp)};
205 cmp_ok(@content, '==', 1, 'one node on this workspace now');
206 is($content[0]->{border}, 'normal', 'no border');
209 exit_gracefully($pid);
211 ##############################################################
212 # 5: check that a class criterion does not match the instance
213 ##############################################################
216 # i3 config file (v4)
217 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
218 for_window [class="foo"] border 1pixel
221 $pid = launch_with_config($config);
223 $tmp = fresh_workspace;
226 $window = open_window(
228 before_map => sub { set_wm_class($_->id, 'bar', 'foo') },
231 @content = @{get_ws_content($tmp)};
232 cmp_ok(@content, '==', 1, 'one node on this workspace now');
233 is($content[0]->{border}, 'normal', 'normal border, not matched');
235 exit_gracefully($pid);
237 ##############################################################
238 # 6: check that the 'instance' criterion works
239 ##############################################################
242 # i3 config file (v4)
243 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
244 for_window [class="foo"] border 1pixel
245 for_window [instance="foo"] border none
248 $pid = launch_with_config($config);
250 $tmp = fresh_workspace;
252 $window = open_window(
254 before_map => sub { set_wm_class($_->id, 'bar', 'foo') },
257 @content = @{get_ws_content($tmp)};
258 cmp_ok(@content, '==', 1, 'one node on this workspace now');
259 is($content[0]->{border}, 'none', 'no border');
261 exit_gracefully($pid);
263 ##############################################################
264 # 7: check that invalid criteria don’t end up matching all windows
265 ##############################################################
267 # this configuration is broken because "asdf" is not a valid integer
268 # the for_window should therefore recognize this error and don’t add the
271 # i3 config file (v4)
272 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
273 for_window [id="asdf"] border none
276 $pid = launch_with_config($config);
278 $tmp = fresh_workspace;
280 $window = open_window(
282 before_map => sub { set_wm_class($_->id, 'bar', 'foo') },
285 @content = @{get_ws_content($tmp)};
286 cmp_ok(@content, '==', 1, 'one node on this workspace now');
287 is($content[0]->{border}, 'normal', 'normal border');
289 exit_gracefully($pid);
291 ##############################################################
292 # 8: check that the role criterion works properly
293 ##############################################################
295 # this configuration is broken because "asdf" is not a valid integer
296 # the for_window should therefore recognize this error and don’t add the
299 # i3 config file (v4)
300 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
301 for_window [window_role="i3test"] border none
304 $pid = launch_with_config($config);
306 $tmp = fresh_workspace;
308 $window = open_window(
312 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
313 my $atomtype = $x->atom(name => 'STRING');
320 length("i3test") + 1,
326 @content = @{get_ws_content($tmp)};
327 cmp_ok(@content, '==', 1, 'one node on this workspace now');
328 is($content[0]->{border}, 'none', 'no border (window_role)');
330 exit_gracefully($pid);
332 ##############################################################
333 # 9: another test for the window_role, but this time it changes
334 # *after* the window has been mapped
335 ##############################################################
337 # this configuration is broken because "asdf" is not a valid integer
338 # the for_window should therefore recognize this error and don’t add the
341 # i3 config file (v4)
342 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
343 for_window [window_role="i3test"] border none
346 $pid = launch_with_config($config);
348 $tmp = fresh_workspace;
350 $window = open_window(name => 'usethis');
352 @content = @{get_ws_content($tmp)};
353 cmp_ok(@content, '==', 1, 'one node on this workspace now');
354 is($content[0]->{border}, 'normal', 'normal border (window_role 2)');
356 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
357 my $atomtype = $x->atom(name => 'STRING');
364 length("i3test") + 1,
372 @content = @{get_ws_content($tmp)};
373 cmp_ok(@content, '==', 1, 'one node on this workspace now');
374 is($content[0]->{border}, 'none', 'no border (window_role 2)');
376 exit_gracefully($pid);