]> git.sur5r.net Git - i3/i3/blob - testcases/t/165-for_window.t
165-for_window: merge config and re-use i3 instance, split remainder
[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 ##############################################################
116 # 2: match on the title, check if for_window is really executed
117 # only once
118 ##############################################################
119
120 $tmp = fresh_workspace;
121
122 $window = open_window(name => 'special title');
123
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');
127
128 $window->name('special borderless title');
129 sync_with_i3;
130
131 @content = @{get_ws_content($tmp)};
132 is($content[0]->{border}, 'none', 'no border');
133
134 $window->name('special title');
135 sync_with_i3;
136
137 cmd 'border normal';
138
139 @content = @{get_ws_content($tmp)};
140 is($content[0]->{border}, 'normal', 'border reset to normal');
141
142 $window->name('special borderless title');
143 sync_with_i3;
144
145 @content = @{get_ws_content($tmp)};
146 is($content[0]->{border}, 'normal', 'still normal border');
147
148 $window->unmap;
149 wait_for_unmap $window;
150
151 @content = @{get_ws_content($tmp)};
152 cmp_ok(@content, '==', 0, 'no more nodes');
153
154 ##############################################################
155 # 3: match on the title, set border style *and* a mark
156 ##############################################################
157
158 $tmp = fresh_workspace;
159
160 $window = open_window(name => 'special mark title');
161
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');
165
166 my $other = open_window;
167
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');
173
174 cmd qq|[con_mark="bleh"] focus|;
175
176 @content = @{get_ws_content($tmp)};
177 ok($content[0]->{focused}, 'first node focused');
178
179 ##############################################################
180 # 4: multiple criteria for the for_window command
181 ##############################################################
182
183 $tmp = fresh_workspace;
184
185 $window = open_window(
186     name => 'usethis',
187     wm_class => 'borderless4',
188 );
189
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');
193
194 cmd 'kill';
195 wait_for_unmap $window;
196 $window->destroy;
197
198 # give i3 a chance to delete the window from its tree
199 sync_with_i3;
200
201 @content = @{get_ws_content($tmp)};
202 cmp_ok(@content, '==', 0, 'no nodes on this workspace now');
203
204 $window->_create;
205 $window->wm_class('borderless4');
206 $window->name('notthis');
207 $window->map;
208 wait_for_map $window;
209
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');
213
214 ##############################################################
215 # 5: check that a class criterion does not match the instance
216 ##############################################################
217
218 $tmp = fresh_workspace;
219
220 $window = open_window(
221     name => 'usethis',
222     wm_class => 'bar',
223     instance => 'foo',
224 );
225
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');
229
230 ##############################################################
231 # 6: check that the 'instance' criterion works
232 ##############################################################
233
234 $tmp = fresh_workspace;
235
236 $window = open_window(
237     name => 'usethis',
238     wm_class => 'bar',
239     instance => 'foo6',
240 );
241
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');
245
246 ##############################################################
247 # 7: check that invalid criteria don’t end up matching all windows
248 ##############################################################
249
250 $tmp = fresh_workspace;
251
252 $window = open_window(
253     name => 'usethis',
254     wm_class => 'bar',
255     instance => 'foo',
256 );
257
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');
261
262 ##############################################################
263 # 8: check that the role criterion works properly
264 ##############################################################
265
266 $tmp = fresh_workspace;
267
268 $window = open_window(
269     name => 'usethis',
270     before_map => sub {
271         my ($window) = @_;
272         my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
273         my $atomtype = $x->atom(name => 'STRING');
274         $x->change_property(
275             PROP_MODE_REPLACE,
276             $window->id,
277             $atomname->id,
278             $atomtype->id,
279             8,
280             length("i3test") + 1,
281             "i3test\x00"
282         );
283     },
284 );
285
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)');
289
290 ##############################################################
291 # 9: another test for the window_role, but this time it changes
292 #    *after* the window has been mapped
293 ##############################################################
294
295 $tmp = fresh_workspace;
296
297 $window = open_window(name => 'usethis');
298
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)');
302
303 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
304 my $atomtype = $x->atom(name => 'STRING');
305 $x->change_property(
306   PROP_MODE_REPLACE,
307   $window->id,
308   $atomname->id,
309   $atomtype->id,
310   8,
311   length("i3test") + 1,
312   "i3test\x00"
313 );
314
315 $x->flush;
316
317 sync_with_i3;
318
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)');
322
323 ##############################################################
324 # 10: check that the criterion 'window_type' works
325 ##############################################################
326
327 while (my ($window_type, $atom) = each %window_types) {
328     $tmp = fresh_workspace;
329
330     $window = open_window(window_type => $x->atom(name => $atom));
331
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)");
335 }
336
337 ##############################################################
338 # 11: check that the criterion 'window_type' works if the
339 #     _NET_WM_WINDOW_TYPE is changed after managing.
340 ##############################################################
341
342 while (my ($window_type, $atom) = each %window_types) {
343     $tmp = fresh_workspace;
344
345     $window = open_window();
346
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));
351     $x->flush;
352     sync_with_i3;
353
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)");
357 }
358
359 ##############################################################
360 # 12: check that the criterion 'workspace' works
361 ##############################################################
362
363 cmd 'workspace trigger';
364 $window = open_window;
365
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");
369
370 ##############################################################
371
372 exit_gracefully($pid);
373
374 done_testing;