]> git.sur5r.net Git - i3/i3/blob - testcases/t/166-assign.t
Merge branch 'fix-fullscreen-confreq'
[i3/i3] / testcases / t / 166-assign.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests if assignments work
5 #
6 use i3test i3_autostart => 0;
7 use X11::XCB qw(PROP_MODE_REPLACE);
8
9 # TODO: move to X11::XCB
10 sub set_wm_class {
11     my ($id, $class, $instance) = @_;
12
13     # Add a _NET_WM_STRUT_PARTIAL hint
14     my $atomname = $x->atom(name => 'WM_CLASS');
15     my $atomtype = $x->atom(name => 'STRING');
16
17     $x->change_property(
18         PROP_MODE_REPLACE,
19         $id,
20         $atomname->id,
21         $atomtype->id,
22         8,
23         length($class) + length($instance) + 2,
24         "$instance\x00$class\x00"
25     );
26 }
27
28 sub open_special {
29     my %args = @_;
30     my $wm_class = delete($args{wm_class}) || 'special';
31     $args{name} //= 'special window';
32
33     # We use dont_map because i3 will not map the window on the current
34     # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
35     my $window = open_window(
36         %args,
37         before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
38         dont_map => 1,
39     );
40     $window->map;
41     return $window;
42 }
43
44 #####################################################################
45 # start a window and see that it does not get assigned with an empty config
46 #####################################################################
47
48 my $config = <<EOT;
49 # i3 config file (v4)
50 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
51 EOT
52
53 my $pid = launch_with_config($config);
54
55 my $tmp = fresh_workspace;
56
57 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
58
59 my $window = open_special;
60
61 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
62
63 exit_gracefully($pid);
64
65 $window->destroy;
66
67 #####################################################################
68 # start a window and see that it gets assigned to a formerly unused
69 # workspace
70 #####################################################################
71
72 $config = <<EOT;
73 # i3 config file (v4)
74 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
75 assign "special" → targetws
76 EOT
77
78 $pid = launch_with_config($config);
79
80 $tmp = fresh_workspace;
81
82 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
83 my $workspaces = get_workspace_names;
84 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
85
86 $window = open_special;
87
88 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
89 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
90
91 $window->destroy;
92
93 exit_gracefully($pid);
94
95 #####################################################################
96 # start a window and see that it gets assigned to a workspace which has content
97 # already, next to the existing node.
98 #####################################################################
99
100 $pid = launch_with_config($config);
101
102 # initialize the target workspace, then go to a fresh one
103 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
104 cmd 'workspace targetws';
105 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
106 cmd 'open';
107 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
108 $tmp = fresh_workspace;
109
110 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
111 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
112
113
114 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
115 # map the window -- it will be assigned to a different workspace and will only
116 # be mapped once you switch to that workspace
117 $window = open_special(dont_map => 1);
118 $window->map;
119 sync_with_i3;
120
121 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
122 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
123
124 exit_gracefully($pid);
125
126 #####################################################################
127 # start a window and see that it gets assigned to a workspace which has content
128 # already, next to the existing node.
129 #####################################################################
130
131 $config = <<EOT;
132 # i3 config file (v4)
133 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
134 assign "special" → ~
135 EOT
136
137 $pid = launch_with_config($config);
138
139 $tmp = fresh_workspace;
140
141 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
142 $workspaces = get_workspace_names;
143 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
144
145 $window = open_special;
146
147 my $content = get_ws($tmp);
148 ok(@{$content->{nodes}} == 0, 'no tiling cons');
149 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
150
151 $window->destroy;
152
153 exit_gracefully($pid);
154
155 #####################################################################
156 # make sure that assignments are case-insensitive in the old syntax.
157 #####################################################################
158
159 $config = <<EOT;
160 # i3 config file (v4)
161 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
162 assign "special" → ~
163 EOT
164
165 $pid = launch_with_config($config);
166
167 $tmp = fresh_workspace;
168
169 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
170 $workspaces = get_workspace_names;
171 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
172
173 $window = open_special(wm_class => 'SPEcial');
174 wait_for_map $window;
175
176 $content = get_ws($tmp);
177 ok(@{$content->{nodes}} == 0, 'no tiling cons');
178 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
179
180 $window->destroy;
181
182 exit_gracefully($pid);
183
184 #####################################################################
185 # regression test: dock clients with floating assignments should not crash
186 # (instead, nothing should happen - dock clients can’t float)
187 # ticket #501
188 #####################################################################
189
190 # Walks /proc to figure out whether a child process of $i3pid with the name
191 # 'i3-nagbar' exists.
192 sub i3nagbar_running {
193     my ($i3pid) = @_;
194
195     my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
196     for my $path (@procfiles) {
197         open(my $fh, '<', "$path/stat") or next;
198         my $line = <$fh>;
199         close($fh);
200         my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
201         return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
202     }
203     return 0;
204 }
205
206 $config = <<EOT;
207 # i3 config file (v4)
208 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
209 assign "special" → ~
210 EOT
211
212 $pid = launch_with_config($config);
213
214 # Ensure that i3-nagbar is running. It should be started pretty quickly, so we
215 # busy-loop with a short delay.
216 while (!i3nagbar_running($pid)) {
217     sleep 0.05;
218 }
219
220 $tmp = fresh_workspace;
221
222 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
223 my @docked = get_dock_clients;
224 # We expect i3-nagbar as the first dock client due to using the old assign
225 # syntax
226 is(@docked, 1, 'one dock client yet');
227
228 $window = open_special(
229     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
230 );
231
232 $content = get_ws($tmp);
233 ok(@{$content->{nodes}} == 0, 'no tiling cons');
234 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
235 @docked = get_dock_clients;
236 is(@docked, 2, 'two dock clients now');
237
238 $window->destroy;
239
240 does_i3_live;
241
242 exit_gracefully($pid);
243
244 done_testing;