2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
5 # Tests if assignments work
9 use X11::XCB::Connection;
12 my $x = X11::XCB::Connection->new;
14 # TODO: move to X11::XCB
16 my ($id, $class, $instance) = @_;
18 # Add a _NET_WM_STRUT_PARTIAL hint
19 my $atomname = $x->atom(name => 'WM_CLASS');
20 my $atomtype = $x->atom(name => 'STRING');
28 length($class) + length($instance) + 2,
29 "$instance\x00$class\x00"
34 #####################################################################
35 # start a window and see that it does not get assigned with an empty config
36 #####################################################################
40 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
43 my $pid = launch_with_config($config);
45 my $tmp = fresh_workspace;
47 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
49 my $window = $x->root->create_child(
50 class => WINDOW_CLASS_INPUT_OUTPUT,
51 rect => [ 0, 0, 30, 30 ],
52 background_color => '#0000ff',
53 event_mask => [ 'structure_notify' ],
57 set_wm_class($window->id, 'special', 'special');
58 $window->name('special window');
62 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
64 exit_gracefully($pid);
68 #####################################################################
69 # start a window and see that it gets assigned to a formerly unused
71 #####################################################################
75 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
76 assign "special" → targetws
79 $pid = launch_with_config($config);
81 $tmp = fresh_workspace;
83 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
84 my $workspaces = get_workspace_names;
85 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
87 my $window = $x->root->create_child(
88 class => WINDOW_CLASS_INPUT_OUTPUT,
89 rect => [ 0, 0, 30, 30 ],
90 background_color => '#0000ff',
91 event_mask => [ 'structure_notify' ],
95 set_wm_class($window->id, 'special', 'special');
96 $window->name('special window');
100 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
101 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
105 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');
127 my $window = $x->root->create_child(
128 class => WINDOW_CLASS_INPUT_OUTPUT,
129 rect => [ 0, 0, 30, 30 ],
130 background_color => '#0000ff',
131 event_mask => [ 'structure_notify' ],
135 set_wm_class($window->id, 'special', 'special');
136 $window->name('special window');
139 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
140 # map the window -- it will be assigned to a different workspace and will only
141 # be mapped once you switch to that workspace
144 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
145 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
147 exit_gracefully($pid);
149 #####################################################################
150 # start a window and see that it gets assigned to a workspace which has content
151 # already, next to the existing node.
152 #####################################################################
155 # i3 config file (v4)
156 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
160 $pid = launch_with_config($config);
162 $tmp = fresh_workspace;
164 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
165 my $workspaces = get_workspace_names;
166 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
168 my $window = $x->root->create_child(
169 class => WINDOW_CLASS_INPUT_OUTPUT,
170 rect => [ 0, 0, 30, 30 ],
171 background_color => '#0000ff',
172 event_mask => [ 'structure_notify' ],
176 set_wm_class($window->id, 'special', 'special');
177 $window->name('special window');
181 my $content = get_ws($tmp);
182 ok(@{$content->{nodes}} == 0, 'no tiling cons');
183 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
187 exit_gracefully($pid);
191 #####################################################################
192 # make sure that assignments are case-insensitive in the old syntax.
193 #####################################################################
196 # i3 config file (v4)
197 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
201 $pid = launch_with_config($config);
203 $tmp = fresh_workspace;
205 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
206 my $workspaces = get_workspace_names;
207 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
209 my $window = $x->root->create_child(
210 class => WINDOW_CLASS_INPUT_OUTPUT,
211 rect => [ 0, 0, 30, 30 ],
212 background_color => '#0000ff',
213 event_mask => [ 'structure_notify' ],
217 set_wm_class($window->id, 'SPEcial', 'SPEcial');
218 $window->name('special window');
222 my $content = get_ws($tmp);
223 ok(@{$content->{nodes}} == 0, 'no tiling cons');
224 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
228 exit_gracefully($pid);
232 #####################################################################
233 # regression test: dock clients with floating assignments should not crash
234 # (instead, nothing should happen - dock clients can’t float)
236 #####################################################################
239 # i3 config file (v4)
240 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
244 $pid = launch_with_config($config);
246 # TODO: replace this with checking the process hierarchy
247 # XXX: give i3-nagbar some time to start up
250 $tmp = fresh_workspace;
252 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
253 my @docked = get_dock_clients;
254 # We expect i3-nagbar as the first dock client due to using the old assign
256 is(@docked, 1, 'one dock client yet');
258 my $window = $x->root->create_child(
259 class => WINDOW_CLASS_INPUT_OUTPUT,
260 rect => [ 0, 0, 30, 30 ],
261 background_color => '#0000ff',
262 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
263 event_mask => [ 'structure_notify' ],
267 set_wm_class($window->id, 'special', 'special');
268 $window->name('special window');
272 my $content = get_ws($tmp);
273 ok(@{$content->{nodes}} == 0, 'no tiling cons');
274 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
275 @docked = get_dock_clients;
276 is(@docked, 2, 'two dock clients now');
282 exit_gracefully($pid);