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);
97 #####################################################################
98 # start a window and see that it gets assigned to a workspace which has content
99 # already, next to the existing node.
100 #####################################################################
102 $pid = launch_with_config($config);
104 # initialize the target workspace, then go to a fresh one
105 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
106 cmd 'workspace targetws';
107 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
109 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
110 $tmp = fresh_workspace;
112 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
113 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
116 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
117 # map the window -- it will be assigned to a different workspace and will only
118 # be mapped once you switch to that workspace
119 $window = open_special(dont_map => 1);
123 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
124 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
126 exit_gracefully($pid);
128 #####################################################################
129 # start a window and see that it gets assigned to a workspace which has content
130 # already, next to the existing node.
131 #####################################################################
134 # i3 config file (v4)
135 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
139 $pid = launch_with_config($config);
141 $tmp = fresh_workspace;
143 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
144 $workspaces = get_workspace_names;
145 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
147 $window = open_special;
149 my $content = get_ws($tmp);
150 ok(@{$content->{nodes}} == 0, 'no tiling cons');
151 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
155 exit_gracefully($pid);
159 #####################################################################
160 # make sure that assignments are case-insensitive in the old syntax.
161 #####################################################################
164 # i3 config file (v4)
165 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
169 $pid = launch_with_config($config);
171 $tmp = fresh_workspace;
173 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
174 $workspaces = get_workspace_names;
175 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
177 $window = open_special(wm_class => 'SPEcial');
179 $content = get_ws($tmp);
180 ok(@{$content->{nodes}} == 0, 'no tiling cons');
181 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
185 exit_gracefully($pid);
189 #####################################################################
190 # regression test: dock clients with floating assignments should not crash
191 # (instead, nothing should happen - dock clients can’t float)
193 #####################################################################
195 # Walks /proc to figure out whether a child process of $i3pid with the name
196 # 'i3-nagbar' exists.
197 sub i3nagbar_running {
200 my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
201 for my $path (@procfiles) {
202 open(my $fh, '<', "$path/stat") or next;
205 my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
206 return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
212 # i3 config file (v4)
213 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
217 $pid = launch_with_config($config);
219 # Ensure that i3-nagbar is running. It should be started pretty quickly, so we
220 # busy-loop with a short delay.
221 while (!i3nagbar_running($pid)) {
225 $tmp = fresh_workspace;
227 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
228 my @docked = get_dock_clients;
229 # We expect i3-nagbar as the first dock client due to using the old assign
231 is(@docked, 1, 'one dock client yet');
233 $window = open_special(
234 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
237 $content = get_ws($tmp);
238 ok(@{$content->{nodes}} == 0, 'no tiling cons');
239 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
240 @docked = get_dock_clients;
241 is(@docked, 2, 'two dock clients now');
247 exit_gracefully($pid);