]> git.sur5r.net Git - i3/i3/blob - testcases/t/66-assign.t
t/66-assign: check if i3 crashes when assigning a dock window to floating
[i3/i3] / testcases / t / 66-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 $process = 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 );
54
55 $window->_create;
56 set_wm_class($window->id, 'special', 'special');
57 $window->name('special window');
58 $window->map;
59 sleep 0.25;
60
61 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
62
63 exit_gracefully($process->pid);
64
65 $window->destroy;
66
67 sleep 0.25;
68
69 #####################################################################
70 # start a window and see that it gets assigned to a formerly unused
71 # workspace
72 #####################################################################
73
74 $config = <<EOT;
75 # i3 config file (v4)
76 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
77 assign "special" → targetws
78 EOT
79
80 $process = launch_with_config($config);
81
82 $tmp = fresh_workspace;
83
84 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
85 my $workspaces = get_workspace_names;
86 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
87
88 my $window = $x->root->create_child(
89     class => WINDOW_CLASS_INPUT_OUTPUT,
90     rect => [ 0, 0, 30, 30 ],
91     background_color => '#0000ff',
92 );
93
94 $window->_create;
95 set_wm_class($window->id, 'special', 'special');
96 $window->name('special window');
97 $window->map;
98 sleep 0.25;
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($process->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 $process = 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 my $window = $x->root->create_child(
128     class => WINDOW_CLASS_INPUT_OUTPUT,
129     rect => [ 0, 0, 30, 30 ],
130     background_color => '#0000ff',
131 );
132
133 $window->_create;
134 set_wm_class($window->id, 'special', 'special');
135 $window->name('special window');
136 $window->map;
137 sleep 0.25;
138
139 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
140 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
141
142 exit_gracefully($process->pid);
143
144 #####################################################################
145 # start a window and see that it gets assigned to a workspace which has content
146 # already, next to the existing node.
147 #####################################################################
148
149 $config = <<EOT;
150 # i3 config file (v4)
151 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
152 assign "special" → ~
153 EOT
154
155 $process = launch_with_config($config);
156
157 $tmp = fresh_workspace;
158
159 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
160 my $workspaces = get_workspace_names;
161 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
162
163 my $window = $x->root->create_child(
164     class => WINDOW_CLASS_INPUT_OUTPUT,
165     rect => [ 0, 0, 30, 30 ],
166     background_color => '#0000ff',
167 );
168
169 $window->_create;
170 set_wm_class($window->id, 'special', 'special');
171 $window->name('special window');
172 $window->map;
173 sleep 0.25;
174
175 my $content = get_ws($tmp);
176 ok(@{$content->{nodes}} == 0, 'no tiling cons');
177 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
178
179 $window->destroy;
180
181 exit_gracefully($process->pid);
182
183 sleep 0.25;
184
185 #####################################################################
186 # regression test: dock clients with floating assignments should not crash
187 # (instead, nothing should happen - dock clients can’t float)
188 # ticket #501
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 $process = launch_with_config($config);
198
199 $tmp = fresh_workspace;
200
201 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
202 my @docked = get_dock_clients;
203 is(@docked, 0, 'no dock clients yet');
204
205 my $window = $x->root->create_child(
206     class => WINDOW_CLASS_INPUT_OUTPUT,
207     rect => [ 0, 0, 30, 30 ],
208     background_color => '#0000ff',
209     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
210 );
211
212 $window->_create;
213 set_wm_class($window->id, 'special', 'special');
214 $window->name('special window');
215 $window->map;
216 sleep 0.25;
217
218 my $content = get_ws($tmp);
219 ok(@{$content->{nodes}} == 0, 'no tiling cons');
220 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
221 @docked = get_dock_clients;
222 is(@docked, 1, 'no dock clients yet');
223
224 $window->destroy;
225
226 does_i3_live;
227
228 exit_gracefully($process->pid);
229
230 sleep 0.25;
231
232 done_testing;