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';
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');
208 exit_gracefully($pid);
210 #####################################################################
211 # regression test: dock clients with floating assignments should not crash
212 # (instead, nothing should happen - dock clients can’t float)
214 #####################################################################
216 # Walks /proc to figure out whether a child process of $i3pid with the name
217 # 'i3-nagbar' exists.
218 sub i3nagbar_running {
221 my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
222 for my $path (@procfiles) {
223 open(my $fh, '<', "$path/stat") or next;
226 my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
227 return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
233 # i3 config file (v4)
234 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
235 for_window [title="special"] floating enable
238 $pid = launch_with_config($config);
240 $tmp = fresh_workspace;
242 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
243 my @docked = get_dock_clients;
244 is(@docked, 0, 'no dock client yet');
246 $window = open_special(
247 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
251 $content = get_ws($tmp);
252 ok(@{$content->{nodes}} == 0, 'no tiling cons');
253 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
254 @docked = get_dock_clients;
255 is(@docked, 1, 'one dock client now');
261 exit_gracefully($pid);