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 # Tests if assignments work
19 use i3test i3_autostart => 0;
23 $args{name} //= 'special window';
25 # We use dont_map because i3 will not map the window on the current
26 # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
27 my $window = open_window(
29 wm_class => 'special',
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(dont_map => 1);
57 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
58 ok(@{get_ws_content($target_ws)} == 2, "two containers on $target_ws");
63 #####################################################################
64 # start a window and see that it does not get assigned with an empty config
65 #####################################################################
69 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
72 my $pid = launch_with_config($config);
74 my $tmp = fresh_workspace;
76 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
78 my $window = open_special;
79 wait_for_map($window);
81 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
83 exit_gracefully($pid);
87 #####################################################################
88 # start a window and see that it gets assigned to a formerly unused
90 #####################################################################
94 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
95 assign [class="special"] → targetws
98 $pid = launch_with_config($config);
100 $tmp = fresh_workspace;
102 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
103 my $workspaces = get_workspace_names;
104 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
106 $window = open_special;
109 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
110 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
114 exit_gracefully($pid);
116 #####################################################################
117 # start a window and see that it gets assigned to a formerly unused
119 #####################################################################
121 my $config_numbered = <<EOT;
122 # i3 config file (v4)
123 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
124 assign [class="special"] → workspace number 2
127 $pid = launch_with_config($config_numbered);
129 $tmp = fresh_workspace;
131 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
132 $workspaces = get_workspace_names;
133 ok(!("2" ~~ @{$workspaces}), 'workspace number 2 does not exist yet');
135 $window = open_special;
138 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
139 ok("2" ~~ @{get_workspace_names()}, 'workspace number 2 exists');
143 exit_gracefully($pid);
145 #####################################################################
146 # start a window and see that it gets assigned to a numbered
147 # workspace which has content already, next to the existing node.
148 #####################################################################
150 $pid = launch_with_config($config_numbered);
152 $window = test_workspace_assignment("2");
155 exit_gracefully($pid);
157 #####################################################################
158 # start a window and see that it gets assigned to a numbered workspace with
159 # a name which has content already, next to the existing node.
160 #####################################################################
162 $pid = launch_with_config($config_numbered);
164 cmd 'workspace 2'; # Make sure that we are not testing for "2" again.
165 $window = test_workspace_assignment("2: targetws");
168 exit_gracefully($pid);
170 #####################################################################
171 # start a window and see that it gets assigned to a workspace which
172 # has content already, next to the existing node.
173 #####################################################################
175 $pid = launch_with_config($config);
177 test_workspace_assignment("targetws");
179 exit_gracefully($pid);
181 #####################################################################
182 # start a window and see that it gets assigned to a workspace which has content
183 # already, next to the existing node.
184 #####################################################################
187 # i3 config file (v4)
188 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
189 for_window [class="special"] floating enable
192 $pid = launch_with_config($config);
194 $tmp = fresh_workspace;
196 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
197 $workspaces = get_workspace_names;
198 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
200 $window = open_special;
203 my $content = get_ws($tmp);
204 ok(@{$content->{nodes}} == 0, 'no tiling cons');
205 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
209 exit_gracefully($pid);
211 #####################################################################
212 # regression test: dock clients with floating assignments should not crash
213 # (instead, nothing should happen - dock clients can’t float)
215 #####################################################################
217 # Walks /proc to figure out whether a child process of $i3pid with the name
218 # 'i3-nagbar' exists.
219 sub i3nagbar_running {
222 my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
223 for my $path (@procfiles) {
224 open(my $fh, '<', "$path/stat") or next;
227 my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
228 return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
234 # i3 config file (v4)
235 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
236 for_window [title="special"] floating enable
239 $pid = launch_with_config($config);
241 $tmp = fresh_workspace;
243 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
244 my @docked = get_dock_clients;
245 is(@docked, 0, 'one dock client yet');
247 $window = open_special(
248 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
252 $content = get_ws($tmp);
253 ok(@{$content->{nodes}} == 0, 'no tiling cons');
254 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
255 @docked = get_dock_clients;
256 is(@docked, 1, 'one dock client now');
262 exit_gracefully($pid);