2 # vim:ts=4:sw=4:expandtab
4 # Tests if assignments work
6 use i3test i3_autostart => 0;
7 use X11::XCB qw(PROP_MODE_REPLACE);
9 # TODO: move to X11::XCB
11 my ($id, $class, $instance) = @_;
13 # Add a _NET_WM_STRUT_PARTIAL hint
14 my $atomname = $x->atom(name => 'WM_CLASS');
15 my $atomtype = $x->atom(name => 'STRING');
23 length($class) + length($instance) + 2,
24 "$instance\x00$class\x00"
30 my $wm_class = delete($args{wm_class}) || 'special';
31 $args{name} //= 'special window';
33 # We use dont_map because i3 will not map the window on the current
34 # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
35 my $window = open_window(
37 before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
44 #####################################################################
45 # start a window and see that it does not get assigned with an empty config
46 #####################################################################
50 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
53 my $pid = launch_with_config($config);
55 my $tmp = fresh_workspace;
57 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
59 my $window = open_special;
61 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
63 exit_gracefully($pid);
67 #####################################################################
68 # start a window and see that it gets assigned to a formerly unused
70 #####################################################################
74 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
75 assign "special" → targetws
78 $pid = launch_with_config($config);
80 $tmp = fresh_workspace;
82 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
83 my $workspaces = get_workspace_names;
84 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
86 $window = open_special;
88 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
89 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
93 exit_gracefully($pid);
95 #####################################################################
96 # start a window and see that it gets assigned to a workspace which has content
97 # already, next to the existing node.
98 #####################################################################
100 $pid = launch_with_config($config);
102 # initialize the target workspace, then go to a fresh one
103 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
104 cmd 'workspace targetws';
105 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
107 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
108 $tmp = fresh_workspace;
110 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
111 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
114 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
115 # map the window -- it will be assigned to a different workspace and will only
116 # be mapped once you switch to that workspace
117 $window = open_special(dont_map => 1);
121 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
122 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
124 exit_gracefully($pid);
126 #####################################################################
127 # start a window and see that it gets assigned to a workspace which has content
128 # already, next to the existing node.
129 #####################################################################
132 # i3 config file (v4)
133 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
137 $pid = launch_with_config($config);
139 $tmp = fresh_workspace;
141 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
142 $workspaces = get_workspace_names;
143 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
145 $window = open_special;
147 my $content = get_ws($tmp);
148 ok(@{$content->{nodes}} == 0, 'no tiling cons');
149 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
153 exit_gracefully($pid);
155 #####################################################################
156 # make sure that assignments are case-insensitive in the old syntax.
157 #####################################################################
160 # i3 config file (v4)
161 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
165 $pid = launch_with_config($config);
167 $tmp = fresh_workspace;
169 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
170 $workspaces = get_workspace_names;
171 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
173 $window = open_special(wm_class => 'SPEcial');
174 wait_for_map $window;
176 $content = get_ws($tmp);
177 ok(@{$content->{nodes}} == 0, 'no tiling cons');
178 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
182 exit_gracefully($pid);
184 #####################################################################
185 # regression test: dock clients with floating assignments should not crash
186 # (instead, nothing should happen - dock clients can’t float)
188 #####################################################################
190 # Walks /proc to figure out whether a child process of $i3pid with the name
191 # 'i3-nagbar' exists.
192 sub i3nagbar_running {
195 my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
196 for my $path (@procfiles) {
197 open(my $fh, '<', "$path/stat") or next;
200 my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
201 return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
207 # i3 config file (v4)
208 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
212 $pid = launch_with_config($config);
214 # Ensure that i3-nagbar is running. It should be started pretty quickly, so we
215 # busy-loop with a short delay.
216 while (!i3nagbar_running($pid)) {
220 $tmp = fresh_workspace;
222 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
223 my @docked = get_dock_clients;
224 # We expect i3-nagbar as the first dock client due to using the old assign
226 is(@docked, 1, 'one dock client yet');
228 $window = open_special(
229 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
232 $content = get_ws($tmp);
233 ok(@{$content->{nodes}} == 0, 'no tiling cons');
234 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
235 @docked = get_dock_clients;
236 is(@docked, 2, 'two dock clients now');
242 exit_gracefully($pid);