]> git.sur5r.net Git - i3/i3/blob - testcases/t/166-assign.t
Merge branch 'master' into next
[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     return open_window(
34         %args,
35         before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
36     );
37 }
38
39 #####################################################################
40 # start a window and see that it does not get assigned with an empty config
41 #####################################################################
42
43 my $config = <<EOT;
44 # i3 config file (v4)
45 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
46 EOT
47
48 my $pid = launch_with_config($config);
49
50 my $tmp = fresh_workspace;
51
52 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
53
54 my $window = open_special;
55
56 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
57
58 exit_gracefully($pid);
59
60 $window->destroy;
61
62 #####################################################################
63 # start a window and see that it gets assigned to a formerly unused
64 # workspace
65 #####################################################################
66
67 $config = <<EOT;
68 # i3 config file (v4)
69 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
70 assign "special" → targetws
71 EOT
72
73 $pid = launch_with_config($config);
74
75 $tmp = fresh_workspace;
76
77 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
78 my $workspaces = get_workspace_names;
79 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
80
81 $window = open_special;
82
83 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
84 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
85
86 $window->destroy;
87
88 exit_gracefully($pid);
89
90 sleep 0.25;
91
92 #####################################################################
93 # start a window and see that it gets assigned to a workspace which has content
94 # already, next to the existing node.
95 #####################################################################
96
97 $pid = launch_with_config($config);
98
99 # initialize the target workspace, then go to a fresh one
100 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
101 cmd 'workspace targetws';
102 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
103 cmd 'open';
104 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
105 $tmp = fresh_workspace;
106
107 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
108 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
109
110
111 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
112 # map the window -- it will be assigned to a different workspace and will only
113 # be mapped once you switch to that workspace
114 $window = open_special(dont_map => 1);
115 $window->map;
116 sync_with_i3;
117
118 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
119 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
120
121 exit_gracefully($pid);
122
123 #####################################################################
124 # start a window and see that it gets assigned to a workspace which has content
125 # already, next to the existing node.
126 #####################################################################
127
128 $config = <<EOT;
129 # i3 config file (v4)
130 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
131 assign "special" → ~
132 EOT
133
134 $pid = launch_with_config($config);
135
136 $tmp = fresh_workspace;
137
138 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
139 $workspaces = get_workspace_names;
140 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
141
142 $window = open_special;
143
144 my $content = get_ws($tmp);
145 ok(@{$content->{nodes}} == 0, 'no tiling cons');
146 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
147
148 $window->destroy;
149
150 exit_gracefully($pid);
151
152 sleep 0.25;
153
154 #####################################################################
155 # make sure that assignments are case-insensitive in the old syntax.
156 #####################################################################
157
158 $config = <<EOT;
159 # i3 config file (v4)
160 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
161 assign "special" → ~
162 EOT
163
164 $pid = launch_with_config($config);
165
166 $tmp = fresh_workspace;
167
168 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
169 $workspaces = get_workspace_names;
170 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
171
172 $window = open_special(wm_class => 'SPEcial');
173
174 $content = get_ws($tmp);
175 ok(@{$content->{nodes}} == 0, 'no tiling cons');
176 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
177
178 $window->destroy;
179
180 exit_gracefully($pid);
181
182 sleep 0.25;
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 $config = <<EOT;
191 # i3 config file (v4)
192 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
193 assign "special" → ~
194 EOT
195
196 $pid = launch_with_config($config);
197
198 # TODO: replace this with checking the process hierarchy
199 # XXX: give i3-nagbar some time to start up
200 sleep 1;
201
202 $tmp = fresh_workspace;
203
204 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
205 my @docked = get_dock_clients;
206 # We expect i3-nagbar as the first dock client due to using the old assign
207 # syntax
208 is(@docked, 1, 'one dock client yet');
209
210 $window = open_special(
211     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
212 );
213
214 $content = get_ws($tmp);
215 ok(@{$content->{nodes}} == 0, 'no tiling cons');
216 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
217 @docked = get_dock_clients;
218 is(@docked, 2, 'two dock clients now');
219
220 $window->destroy;
221
222 does_i3_live;
223
224 exit_gracefully($pid);
225
226 done_testing;