]> git.sur5r.net Git - i3/i3/blob - testcases/t/166-assign.t
testcases: let i3test.pm export $x, adapt testcases
[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(PROP_MODE_REPLACE WINDOW_CLASS_INPUT_OUTPUT);
9
10 # TODO: move to X11::XCB
11 sub set_wm_class {
12     my ($id, $class, $instance) = @_;
13
14     # Add a _NET_WM_STRUT_PARTIAL hint
15     my $atomname = $x->atom(name => 'WM_CLASS');
16     my $atomtype = $x->atom(name => 'STRING');
17
18     $x->change_property(
19         PROP_MODE_REPLACE,
20         $id,
21         $atomname->id,
22         $atomtype->id,
23         8,
24         length($class) + length($instance) + 2,
25         "$instance\x00$class\x00"
26     );
27 }
28
29
30 #####################################################################
31 # start a window and see that it does not get assigned with an empty config
32 #####################################################################
33
34 my $config = <<EOT;
35 # i3 config file (v4)
36 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
37 EOT
38
39 my $pid = launch_with_config($config);
40
41 my $tmp = fresh_workspace;
42
43 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
44
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' ],
50 );
51
52 $window->_create;
53 set_wm_class($window->id, 'special', 'special');
54 $window->name('special window');
55 $window->map;
56 wait_for_map $x;
57
58 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
59
60 exit_gracefully($pid);
61
62 $window->destroy;
63
64 #####################################################################
65 # start a window and see that it gets assigned to a formerly unused
66 # workspace
67 #####################################################################
68
69 $config = <<EOT;
70 # i3 config file (v4)
71 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
72 assign "special" → targetws
73 EOT
74
75 $pid = launch_with_config($config);
76
77 $tmp = fresh_workspace;
78
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');
82
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' ],
88 );
89
90 $window->_create;
91 set_wm_class($window->id, 'special', 'special');
92 $window->name('special window');
93 $window->map;
94 wait_for_map $x;
95
96 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
97 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
98
99 $window->destroy;
100
101 exit_gracefully($pid);
102
103 sleep 0.25;
104
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 #####################################################################
109
110 $pid = launch_with_config($config);
111
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');
116 cmd 'open';
117 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
118 $tmp = fresh_workspace;
119
120 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
121 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
122
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' ],
128 );
129
130 $window->_create;
131 set_wm_class($window->id, 'special', 'special');
132 $window->name('special window');
133 $window->map;
134
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
138 sync_with_i3 $x;
139
140 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
141 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
142
143 exit_gracefully($pid);
144
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 #####################################################################
149
150 $config = <<EOT;
151 # i3 config file (v4)
152 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
153 assign "special" → ~
154 EOT
155
156 $pid = launch_with_config($config);
157
158 $tmp = fresh_workspace;
159
160 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
161 $workspaces = get_workspace_names;
162 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
163
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' ],
169 );
170
171 $window->_create;
172 set_wm_class($window->id, 'special', 'special');
173 $window->name('special window');
174 $window->map;
175 wait_for_map $x;
176
177 my $content = get_ws($tmp);
178 ok(@{$content->{nodes}} == 0, 'no tiling cons');
179 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
180
181 $window->destroy;
182
183 exit_gracefully($pid);
184
185 sleep 0.25;
186
187 #####################################################################
188 # make sure that assignments are case-insensitive in the old syntax.
189 #####################################################################
190
191 $config = <<EOT;
192 # i3 config file (v4)
193 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
194 assign "special" → ~
195 EOT
196
197 $pid = launch_with_config($config);
198
199 $tmp = fresh_workspace;
200
201 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
202 $workspaces = get_workspace_names;
203 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
204
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' ],
210 );
211
212 $window->_create;
213 set_wm_class($window->id, 'SPEcial', 'SPEcial');
214 $window->name('special window');
215 $window->map;
216 wait_for_map $x;
217
218 $content = get_ws($tmp);
219 ok(@{$content->{nodes}} == 0, 'no tiling cons');
220 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
221
222 $window->destroy;
223
224 exit_gracefully($pid);
225
226 sleep 0.25;
227
228 #####################################################################
229 # regression test: dock clients with floating assignments should not crash
230 # (instead, nothing should happen - dock clients can’t float)
231 # ticket #501
232 #####################################################################
233
234 $config = <<EOT;
235 # i3 config file (v4)
236 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
237 assign "special" → ~
238 EOT
239
240 $pid = launch_with_config($config);
241
242 # TODO: replace this with checking the process hierarchy
243 # XXX: give i3-nagbar some time to start up
244 sleep 1;
245
246 $tmp = fresh_workspace;
247
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
251 # syntax
252 is(@docked, 1, 'one dock client yet');
253
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' ],
260 );
261
262 $window->_create;
263 set_wm_class($window->id, 'special', 'special');
264 $window->name('special window');
265 $window->map;
266 wait_for_map $x;
267
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');
273
274 $window->destroy;
275
276 does_i3_live;
277
278 exit_gracefully($pid);
279
280 sleep 0.25;
281
282 done_testing;