2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://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 # Tests if assignments work
19 use i3test i3_autostart => 0;
23 $args{name} //= 'special window';
24 $args{wm_class} //= 'special';
26 # We use dont_map because i3 will not map the window on the current
27 # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
28 my $window = open_window(
36 sub test_workspace_assignment {
39 # initialize the target workspace, then go to a fresh one
40 ok(!($target_ws ~~ @{get_workspace_names()}), "$target_ws does not exist yet");
41 cmd "workspace $target_ws";
42 cmp_ok(@{get_ws_content($target_ws)}, '==', 0, "no containers on $target_ws yet");
44 cmp_ok(@{get_ws_content($target_ws)}, '==', 1, "one container on $target_ws");
45 my $tmp = fresh_workspace;
47 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
48 ok($target_ws ~~ @{get_workspace_names()}, "$target_ws does not exist yet");
50 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
51 # map the window -- it will be assigned to a different workspace and will only
52 # be mapped once you switch to that workspace
53 my $window = open_special;
56 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
57 ok(@{get_ws_content($target_ws)} == 2, "two containers on $target_ws");
62 #####################################################################
63 # start a window and see that it does not get assigned with an empty config
64 #####################################################################
68 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
71 my $pid = launch_with_config($config);
73 my $tmp = fresh_workspace;
75 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
77 my $window = open_special;
78 wait_for_map($window);
80 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
82 exit_gracefully($pid);
86 #####################################################################
87 # start a window and see that it gets assigned to a formerly unused
89 #####################################################################
93 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
94 assign [class="special"] → targetws
97 $pid = launch_with_config($config);
99 $tmp = fresh_workspace;
101 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
102 my $workspaces = get_workspace_names;
103 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
105 $window = open_special;
108 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
109 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
113 exit_gracefully($pid);
115 #####################################################################
116 # start a window and see that it gets assigned to a formerly unused
118 #####################################################################
120 my $config_numbered = <<EOT;
121 # i3 config file (v4)
122 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
123 assign [class="special"] → workspace number 2
126 $pid = launch_with_config($config_numbered);
128 $tmp = fresh_workspace;
130 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
131 $workspaces = get_workspace_names;
132 ok(!("2" ~~ @{$workspaces}), 'workspace number 2 does not exist yet');
134 $window = open_special;
137 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
138 ok("2" ~~ @{get_workspace_names()}, 'workspace number 2 exists');
142 exit_gracefully($pid);
144 #####################################################################
145 # start a window and see that it gets assigned to a numbered
146 # workspace which has content already, next to the existing node.
147 #####################################################################
149 $pid = launch_with_config($config_numbered);
151 $window = test_workspace_assignment("2");
154 exit_gracefully($pid);
156 #####################################################################
157 # start a window and see that it gets assigned to a numbered workspace with
158 # a name which has content already, next to the existing node.
159 #####################################################################
161 $pid = launch_with_config($config_numbered);
163 cmd 'workspace 2'; # Make sure that we are not testing for "2" again.
164 $window = test_workspace_assignment("2: targetws");
167 exit_gracefully($pid);
169 #####################################################################
170 # start a window and see that it gets assigned to a workspace which
171 # has content already, next to the existing node.
172 #####################################################################
174 $pid = launch_with_config($config);
176 test_workspace_assignment("targetws");
178 exit_gracefully($pid);
180 #####################################################################
181 # start a window and see that it gets assigned to a workspace which has content
182 # already, next to the existing node.
183 #####################################################################
186 # i3 config file (v4)
187 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
188 for_window [class="special"] floating enable
191 $pid = launch_with_config($config);
193 $tmp = fresh_workspace;
195 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
196 $workspaces = get_workspace_names;
197 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
199 $window = open_special;
202 my $content = get_ws($tmp);
203 ok(@{$content->{nodes}} == 0, 'no tiling cons');
204 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
207 exit_gracefully($pid);
209 #####################################################################
210 # test assignments to named outputs
211 #####################################################################
213 # i3 config file (v4)
214 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
216 fake-outputs 1024x768+0+0,1024x768+1024+0,1024x768+1024+768,1024x768+0+768
218 workspace ws-0 output fake-0
219 workspace ws-1 output fake-1
220 workspace ws-2 output fake-2
221 workspace ws-3 output fake-3
223 assign [class="special-0"] → output fake-0
224 assign [class="special-1"] → output fake-1
225 assign [class="special-2"] → output fake-2
226 assign [class="special-3"] → output fake-3
227 assign [class="special-4"] → output invalid
231 $pid = launch_with_config($config);
234 my ($num, $expected_count) = @_;
236 my $class = "special-$num";
237 my $output = "fake-$num";
239 is_num_children($ws, $expected_count - 1,
240 "before: " . ($expected_count - 1) . " containers on output $output");
241 $window = open_special(wm_class => $class);
243 is_num_children($ws, $expected_count,
244 "after: $expected_count containers on output $output");
247 cmd "workspace ws-0";
248 open_in_output(0, 1);
249 my $focused = $x->input_focus;
251 open_in_output(1, 1);
252 is($x->input_focus, $focused, 'focus remains on output fake-0');
254 open_in_output(2, 1);
255 is($x->input_focus, $focused, 'focus remains on output fake-0');
258 open_in_output(3, $i);
259 is($x->input_focus, $focused, 'focus remains on output fake-0');
262 # Check invalid output
263 $tmp = fresh_workspace;
264 open_special(wm_class => "special-4");
266 is_num_children($tmp, 1, 'window assigned to invalid output opened in current workspace');
267 open_special(wm_class => "special-3");
269 is_num_children($tmp, 1, 'but window assigned to valid output did not');
272 exit_gracefully($pid);
274 #####################################################################
275 # Test assignments to outputs with relative names
276 #####################################################################
278 # i3 config file (v4)
279 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
281 fake-outputs 1024x768+0+0,1024x768+1024+0,1024x768+1024+768,1024x768+0+768
283 workspace left-top output fake-0
284 workspace right-top output fake-1
285 workspace right-bottom output fake-2
286 workspace left-bottom output fake-3
288 assign [class="current"] → output current
289 assign [class="left"] → output left
290 assign [class="right"] → output right
291 assign [class="up"] → output up
292 assign [class="down"] → output down
295 $pid = launch_with_config($config);
297 cmd 'workspace left-top';
299 is_num_children('left-top', 0, 'no childreon on left-top');
301 open_special(wm_class => 'current');
304 is_num_children('left-top', 5, 'windows opened in current workspace');
306 is_num_children('right-top', 0, 'no children on right-top');
307 open_special(wm_class => 'right');
309 is_num_children('right-top', 1, 'one child on right-top');
311 is_num_children('left-bottom', 0, 'no children on left-bottom');
312 open_special(wm_class => 'down');
314 is_num_children('left-bottom', 1, 'one child on left-bottom');
316 cmd 'workspace right-bottom';
318 open_special(wm_class => 'up');
320 is_num_children('right-top', 2, 'two children on right-top');
322 open_special(wm_class => 'left');
324 is_num_children('left-bottom', 2, 'two children on left-bottom');
327 exit_gracefully($pid);
329 #####################################################################
330 # regression test: dock clients with floating assignments should not crash
331 # (instead, nothing should happen - dock clients can’t float)
333 #####################################################################
335 # Walks /proc to figure out whether a child process of $i3pid with the name
336 # 'i3-nagbar' exists.
337 sub i3nagbar_running {
340 my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
341 for my $path (@procfiles) {
342 open(my $fh, '<', "$path/stat") or next;
345 my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
346 return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
352 # i3 config file (v4)
353 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
354 for_window [title="special"] floating enable
357 $pid = launch_with_config($config);
359 $tmp = fresh_workspace;
361 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
362 my @docked = get_dock_clients;
363 is(@docked, 0, 'no dock client yet');
365 $window = open_special(
366 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
370 $content = get_ws($tmp);
371 ok(@{$content->{nodes}} == 0, 'no tiling cons');
372 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
373 @docked = get_dock_clients;
374 is(@docked, 1, 'one dock client now');
380 exit_gracefully($pid);