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;
20 use X11::XCB qw(PROP_MODE_REPLACE);
22 # TODO: move to X11::XCB
24 my ($id, $class, $instance) = @_;
26 # Add a _NET_WM_STRUT_PARTIAL hint
27 my $atomname = $x->atom(name => 'WM_CLASS');
28 my $atomtype = $x->atom(name => 'STRING');
36 length($class) + length($instance) + 2,
37 "$instance\x00$class\x00"
43 my $wm_class = delete($args{wm_class}) || 'special';
44 $args{name} //= 'special window';
46 # We use dont_map because i3 will not map the window on the current
47 # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
48 my $window = open_window(
50 before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
57 #####################################################################
58 # start a window and see that it does not get assigned with an empty config
59 #####################################################################
63 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
66 my $pid = launch_with_config($config);
68 my $tmp = fresh_workspace;
70 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
72 my $window = open_special;
73 wait_for_map($window);
75 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
77 exit_gracefully($pid);
81 #####################################################################
82 # start a window and see that it gets assigned to a formerly unused
84 #####################################################################
88 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
89 assign "special" → targetws
92 $pid = launch_with_config($config);
94 $tmp = fresh_workspace;
96 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
97 my $workspaces = get_workspace_names;
98 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
100 $window = open_special;
102 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
103 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
107 exit_gracefully($pid);
109 #####################################################################
110 # start a window and see that it gets assigned to a workspace which has content
111 # already, next to the existing node.
112 #####################################################################
114 $pid = launch_with_config($config);
116 # initialize the target workspace, then go to a fresh one
117 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
118 cmd 'workspace targetws';
119 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
121 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
122 $tmp = fresh_workspace;
124 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
125 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
128 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
129 # map the window -- it will be assigned to a different workspace and will only
130 # be mapped once you switch to that workspace
131 $window = open_special(dont_map => 1);
135 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
136 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
138 exit_gracefully($pid);
140 #####################################################################
141 # start a window and see that it gets assigned to a workspace which has content
142 # already, next to the existing node.
143 #####################################################################
146 # i3 config file (v4)
147 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
151 $pid = launch_with_config($config);
153 $tmp = fresh_workspace;
155 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
156 $workspaces = get_workspace_names;
157 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
159 $window = open_special;
161 my $content = get_ws($tmp);
162 ok(@{$content->{nodes}} == 0, 'no tiling cons');
163 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
167 exit_gracefully($pid);
169 #####################################################################
170 # make sure that assignments are case-insensitive in the old syntax.
171 #####################################################################
174 # i3 config file (v4)
175 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
179 $pid = launch_with_config($config);
181 $tmp = fresh_workspace;
183 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
184 $workspaces = get_workspace_names;
185 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
187 $window = open_special(wm_class => 'SPEcial');
188 wait_for_map $window;
190 $content = get_ws($tmp);
191 ok(@{$content->{nodes}} == 0, 'no tiling cons');
192 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
196 exit_gracefully($pid);
198 #####################################################################
199 # regression test: dock clients with floating assignments should not crash
200 # (instead, nothing should happen - dock clients can’t float)
202 #####################################################################
204 # Walks /proc to figure out whether a child process of $i3pid with the name
205 # 'i3-nagbar' exists.
206 sub i3nagbar_running {
209 my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
210 for my $path (@procfiles) {
211 open(my $fh, '<', "$path/stat") or next;
214 my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
215 return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
221 # i3 config file (v4)
222 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
223 for_window [title="special"] floating enable
226 $pid = launch_with_config($config);
228 $tmp = fresh_workspace;
230 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
231 my @docked = get_dock_clients;
232 is(@docked, 0, 'one dock client yet');
234 $window = open_special(
235 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
238 $content = get_ws($tmp);
239 ok(@{$content->{nodes}} == 0, 'no tiling cons');
240 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
241 @docked = get_dock_clients;
242 is(@docked, 1, 'one dock client now');
248 exit_gracefully($pid);