2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
5 # Tests if assignments work
8 use X11::XCB qw(PROP_MODE_REPLACE WINDOW_CLASS_INPUT_OUTPUT);
10 # TODO: move to X11::XCB
12 my ($id, $class, $instance) = @_;
14 # Add a _NET_WM_STRUT_PARTIAL hint
15 my $atomname = $x->atom(name => 'WM_CLASS');
16 my $atomtype = $x->atom(name => 'STRING');
24 length($class) + length($instance) + 2,
25 "$instance\x00$class\x00"
30 #####################################################################
31 # start a window and see that it does not get assigned with an empty config
32 #####################################################################
36 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
39 my $pid = launch_with_config($config);
41 my $tmp = fresh_workspace;
43 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
45 my $window = $x->root->create_child(
46 class => WINDOW_CLASS_INPUT_OUTPUT,
47 rect => [ 0, 0, 30, 30 ],
48 background_color => '#0000ff',
49 event_mask => [ 'structure_notify' ],
53 set_wm_class($window->id, 'special', 'special');
54 $window->name('special window');
58 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
60 exit_gracefully($pid);
64 #####################################################################
65 # start a window and see that it gets assigned to a formerly unused
67 #####################################################################
71 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
72 assign "special" → targetws
75 $pid = launch_with_config($config);
77 $tmp = fresh_workspace;
79 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
80 my $workspaces = get_workspace_names;
81 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
83 $window = $x->root->create_child(
84 class => WINDOW_CLASS_INPUT_OUTPUT,
85 rect => [ 0, 0, 30, 30 ],
86 background_color => '#0000ff',
87 event_mask => [ 'structure_notify' ],
91 set_wm_class($window->id, 'special', 'special');
92 $window->name('special window');
96 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
97 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
101 exit_gracefully($pid);
105 #####################################################################
106 # start a window and see that it gets assigned to a workspace which has content
107 # already, next to the existing node.
108 #####################################################################
110 $pid = launch_with_config($config);
112 # initialize the target workspace, then go to a fresh one
113 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
114 cmd 'workspace targetws';
115 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
117 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
118 $tmp = fresh_workspace;
120 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
121 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
123 $window = $x->root->create_child(
124 class => WINDOW_CLASS_INPUT_OUTPUT,
125 rect => [ 0, 0, 30, 30 ],
126 background_color => '#0000ff',
127 event_mask => [ 'structure_notify' ],
131 set_wm_class($window->id, 'special', 'special');
132 $window->name('special window');
135 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
136 # map the window -- it will be assigned to a different workspace and will only
137 # be mapped once you switch to that workspace
140 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
141 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
143 exit_gracefully($pid);
145 #####################################################################
146 # start a window and see that it gets assigned to a workspace which has content
147 # already, next to the existing node.
148 #####################################################################
151 # i3 config file (v4)
152 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
156 $pid = launch_with_config($config);
158 $tmp = fresh_workspace;
160 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
161 $workspaces = get_workspace_names;
162 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
164 $window = $x->root->create_child(
165 class => WINDOW_CLASS_INPUT_OUTPUT,
166 rect => [ 0, 0, 30, 30 ],
167 background_color => '#0000ff',
168 event_mask => [ 'structure_notify' ],
172 set_wm_class($window->id, 'special', 'special');
173 $window->name('special window');
175 wait_for_map $window;
177 my $content = get_ws($tmp);
178 ok(@{$content->{nodes}} == 0, 'no tiling cons');
179 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
183 exit_gracefully($pid);
187 #####################################################################
188 # make sure that assignments are case-insensitive in the old syntax.
189 #####################################################################
192 # i3 config file (v4)
193 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
197 $pid = launch_with_config($config);
199 $tmp = fresh_workspace;
201 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
202 $workspaces = get_workspace_names;
203 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
205 $window = $x->root->create_child(
206 class => WINDOW_CLASS_INPUT_OUTPUT,
207 rect => [ 0, 0, 30, 30 ],
208 background_color => '#0000ff',
209 event_mask => [ 'structure_notify' ],
213 set_wm_class($window->id, 'SPEcial', 'SPEcial');
214 $window->name('special window');
216 wait_for_map $window;
218 $content = get_ws($tmp);
219 ok(@{$content->{nodes}} == 0, 'no tiling cons');
220 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
224 exit_gracefully($pid);
228 #####################################################################
229 # regression test: dock clients with floating assignments should not crash
230 # (instead, nothing should happen - dock clients can’t float)
232 #####################################################################
235 # i3 config file (v4)
236 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
240 $pid = launch_with_config($config);
242 # TODO: replace this with checking the process hierarchy
243 # XXX: give i3-nagbar some time to start up
246 $tmp = fresh_workspace;
248 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
249 my @docked = get_dock_clients;
250 # We expect i3-nagbar as the first dock client due to using the old assign
252 is(@docked, 1, 'one dock client yet');
254 $window = $x->root->create_child(
255 class => WINDOW_CLASS_INPUT_OUTPUT,
256 rect => [ 0, 0, 30, 30 ],
257 background_color => '#0000ff',
258 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
259 event_mask => [ 'structure_notify' ],
263 set_wm_class($window->id, 'special', 'special');
264 $window->name('special window');
266 wait_for_map $window;
268 $content = get_ws($tmp);
269 ok(@{$content->{nodes}} == 0, 'no tiling cons');
270 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
271 @docked = get_dock_clients;
272 is(@docked, 2, 'two dock clients now');
278 exit_gracefully($pid);