]> git.sur5r.net Git - i3/i3/blob - testcases/t/166-assign.t
testcases: correctly enable lexical pragmata
[i3/i3] / testcases / t / 166-assign.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
4 #
5 # Tests if assignments work
6 #
7 use i3test;
8 use X11::XCB qw(:all);
9 use X11::XCB::Connection;
10 use v5.10;
11
12 my $x = X11::XCB::Connection->new;
13
14 # TODO: move to X11::XCB
15 sub set_wm_class {
16     my ($id, $class, $instance) = @_;
17
18     # Add a _NET_WM_STRUT_PARTIAL hint
19     my $atomname = $x->atom(name => 'WM_CLASS');
20     my $atomtype = $x->atom(name => 'STRING');
21
22     $x->change_property(
23         PROP_MODE_REPLACE,
24         $id,
25         $atomname->id,
26         $atomtype->id,
27         8,
28         length($class) + length($instance) + 2,
29         "$instance\x00$class\x00"
30     );
31 }
32
33
34 #####################################################################
35 # start a window and see that it does not get assigned with an empty config
36 #####################################################################
37
38 my $config = <<EOT;
39 # i3 config file (v4)
40 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
41 EOT
42
43 my $pid = launch_with_config($config);
44
45 my $tmp = fresh_workspace;
46
47 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
48
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' ],
54 );
55
56 $window->_create;
57 set_wm_class($window->id, 'special', 'special');
58 $window->name('special window');
59 $window->map;
60 wait_for_map $x;
61
62 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
63
64 exit_gracefully($pid);
65
66 $window->destroy;
67
68 #####################################################################
69 # start a window and see that it gets assigned to a formerly unused
70 # workspace
71 #####################################################################
72
73 $config = <<EOT;
74 # i3 config file (v4)
75 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
76 assign "special" → targetws
77 EOT
78
79 $pid = launch_with_config($config);
80
81 $tmp = fresh_workspace;
82
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');
86
87 $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' ],
92 );
93
94 $window->_create;
95 set_wm_class($window->id, 'special', 'special');
96 $window->name('special window');
97 $window->map;
98 wait_for_map $x;
99
100 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
101 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
102
103 $window->destroy;
104
105 exit_gracefully($pid);
106
107 sleep 0.25;
108
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 #####################################################################
113
114 $pid = launch_with_config($config);
115
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');
120 cmd 'open';
121 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
122 $tmp = fresh_workspace;
123
124 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
125 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
126
127 $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' ],
132 );
133
134 $window->_create;
135 set_wm_class($window->id, 'special', 'special');
136 $window->name('special window');
137 $window->map;
138
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
142 sync_with_i3 $x;
143
144 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
145 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
146
147 exit_gracefully($pid);
148
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 #####################################################################
153
154 $config = <<EOT;
155 # i3 config file (v4)
156 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
157 assign "special" → ~
158 EOT
159
160 $pid = launch_with_config($config);
161
162 $tmp = fresh_workspace;
163
164 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
165 $workspaces = get_workspace_names;
166 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
167
168 $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' ],
173 );
174
175 $window->_create;
176 set_wm_class($window->id, 'special', 'special');
177 $window->name('special window');
178 $window->map;
179 wait_for_map $x;
180
181 my $content = get_ws($tmp);
182 ok(@{$content->{nodes}} == 0, 'no tiling cons');
183 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
184
185 $window->destroy;
186
187 exit_gracefully($pid);
188
189 sleep 0.25;
190
191 #####################################################################
192 # make sure that assignments are case-insensitive in the old syntax.
193 #####################################################################
194
195 $config = <<EOT;
196 # i3 config file (v4)
197 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
198 assign "special" → ~
199 EOT
200
201 $pid = launch_with_config($config);
202
203 $tmp = fresh_workspace;
204
205 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
206 $workspaces = get_workspace_names;
207 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
208
209 $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' ],
214 );
215
216 $window->_create;
217 set_wm_class($window->id, 'SPEcial', 'SPEcial');
218 $window->name('special window');
219 $window->map;
220 wait_for_map $x;
221
222 $content = get_ws($tmp);
223 ok(@{$content->{nodes}} == 0, 'no tiling cons');
224 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
225
226 $window->destroy;
227
228 exit_gracefully($pid);
229
230 sleep 0.25;
231
232 #####################################################################
233 # regression test: dock clients with floating assignments should not crash
234 # (instead, nothing should happen - dock clients can’t float)
235 # ticket #501
236 #####################################################################
237
238 $config = <<EOT;
239 # i3 config file (v4)
240 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
241 assign "special" → ~
242 EOT
243
244 $pid = launch_with_config($config);
245
246 # TODO: replace this with checking the process hierarchy
247 # XXX: give i3-nagbar some time to start up
248 sleep 1;
249
250 $tmp = fresh_workspace;
251
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
255 # syntax
256 is(@docked, 1, 'one dock client yet');
257
258 $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' ],
264 );
265
266 $window->_create;
267 set_wm_class($window->id, 'special', 'special');
268 $window->name('special window');
269 $window->map;
270 wait_for_map $x;
271
272 $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');
277
278 $window->destroy;
279
280 does_i3_live;
281
282 exit_gracefully($pid);
283
284 sleep 0.25;
285
286 done_testing;