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