2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Checks if the 'move [window/container] to workspace' command works correctly
21 my $i3 = i3(get_socket_path());
23 # We move the pointer out of our way to avoid a bug where the focus will
24 # be set to the window under the cursor
26 $x->root->warp_pointer(0, 0);
29 sub move_workspace_test {
32 my $tmp = get_unused_workspace();
33 my $tmp2 = get_unused_workspace();
36 is_num_children($tmp, 0, 'no containers yet');
38 my $first = open_empty_con($i3);
39 my $second = open_empty_con($i3);
40 is_num_children($tmp, 2, 'two containers on first ws');
42 cmd "workspace $tmp2";
43 is_num_children($tmp2, 0, 'no containers on second ws yet');
48 is_num_children($tmp, 1, 'one container on first ws anymore');
49 is_num_children($tmp2, 1, 'one container on second ws');
50 my ($nodes, $focus) = get_ws_content($tmp2);
52 is($focus->[0], $second, 'same container on different ws');
54 ($nodes, $focus) = get_ws_content($tmp);
55 ok($nodes->[0]->{focused}, 'first container focused on first ws');
58 move_workspace_test('move workspace'); # supported for legacy reasons
59 move_workspace_test('move to workspace');
60 # Those are just synonyms and more verbose ways of saying the same thing:
61 move_workspace_test('move window to workspace');
62 move_workspace_test('move container to workspace');
64 ################################################################################
65 # Check that 'move to workspace number <number>' works to move a window to
66 # named workspaces which start with <number>.
67 ################################################################################
69 cmd 'workspace 13: meh';
71 is_num_children('13: meh', 1, 'one container on 13: meh');
73 ok(!workspace_exists('13'), 'workspace 13 does not exist yet');
78 cmd 'move to workspace number 13';
79 is_num_children('13: meh', 2, 'one container on 13: meh');
80 is_num_children('12', 0, 'no container on 12 anymore');
82 ok(!workspace_exists('13'), 'workspace 13 does still not exist');
84 ################################################################################
85 # Check that 'move to workspace number <number><name>' works to move a window to
86 # named workspaces which start with <number>.
87 ################################################################################
89 cmd 'workspace 15: meh';
91 is_num_children('15: meh', 1, 'one container on 15: meh');
93 ok(!workspace_exists('15'), 'workspace 15 does not exist yet');
94 ok(!workspace_exists('15: duh'), 'workspace 15: duh does not exist yet');
99 cmd 'move to workspace number 15: duh';
100 is_num_children('15: meh', 2, 'two containers on 15: meh');
101 is_num_children('14', 0, 'no container on 14 anymore');
103 ok(!workspace_exists('15'), 'workspace 15 does still not exist');
104 ok(!workspace_exists('15: duh'), 'workspace 15 does still not exist');
106 ###################################################################
107 # check if 'move workspace next' and 'move workspace prev' work
108 ###################################################################
110 # Open two containers on the first workspace, one container on the second
111 # workspace. Because the workspaces are named, they will be sorted by order of
113 my $tmp = get_unused_workspace();
114 my $tmp2 = get_unused_workspace();
115 cmd "workspace $tmp";
116 is_num_children($tmp, 0, 'no containers yet');
117 my $first = open_empty_con($i3);
118 my $second = open_empty_con($i3);
119 is_num_children($tmp, 2, 'two containers');
121 cmd "workspace $tmp2";
122 is_num_children($tmp2, 0, 'no containers yet');
123 my $third = open_empty_con($i3);
124 is_num_children($tmp2, 1, 'one container on second ws');
126 # go back to the first workspace, move one of the containers to the next one
127 cmd "workspace $tmp";
128 cmd 'move workspace next';
129 is_num_children($tmp, 1, 'one container on first ws');
130 is_num_children($tmp2, 2, 'two containers on second ws');
132 # go to the second workspace and move two containers to the first one
133 cmd "workspace $tmp2";
134 cmd 'move workspace prev';
135 cmd 'move workspace prev';
136 is_num_children($tmp, 3, 'three containers on first ws');
137 is_num_children($tmp2, 0, 'no containers on second ws');
139 ###################################################################
140 # check if 'move workspace current' works
141 ###################################################################
143 $tmp = get_unused_workspace();
144 $tmp2 = get_unused_workspace();
146 cmd "workspace $tmp";
147 $first = open_window(name => 'win-name');
148 is_num_children($tmp, 1, 'one container on first ws');
150 cmd "workspace $tmp2";
151 is_num_children($tmp2, 0, 'no containers yet');
153 cmd qq|[title="win-name"] move workspace $tmp2|;
154 is_num_children($tmp2, 1, 'one container on second ws');
156 cmd qq|[title="win-name"] move workspace $tmp|;
157 is_num_children($tmp2, 0, 'no containers on second ws');
159 ###################################################################
160 # check if floating cons are moved to new workspaces properly
161 # (that is, if they are floating on the target ws, too)
162 ###################################################################
164 $tmp = get_unused_workspace();
165 $tmp2 = get_unused_workspace();
166 cmd "workspace $tmp";
169 cmd "floating toggle";
171 my $ws = get_ws($tmp);
172 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
173 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
175 cmd "move workspace $tmp2";
178 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
179 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
181 ################################################################################
182 # Check that 'move workspace number' works correctly.
183 ################################################################################
185 $tmp = get_unused_workspace();
190 is_num_children('16', 1, 'one node on ws 16');
192 cmd "workspace $tmp";
194 cmd 'move workspace number 16';
195 is_num_children('16', 2, 'two nodes on ws 16');
197 ok(!workspace_exists('17'), 'workspace 17 does not exist yet');
199 cmd 'move workspace number 17';
200 ok(workspace_exists('17'), 'workspace 17 created by moving');
201 is(@{get_ws('17')->{nodes}}, 1, 'one node on ws 16');
203 ################################################################################
204 # The following four tests verify the various 'move workspace' commands when
205 # the selection is itself a workspace.
206 ################################################################################
208 # borrowed from 122-split.t
209 # recursively sums up all nodes and their children
213 return 0 if !@{$nodes};
215 my @children = (map { @{$_->{nodes}} } @{$nodes},
216 map { @{$_->{'floating_nodes'}} } @{$nodes});
218 return @{$nodes} + sum_nodes(\@children);
221 ############################################################
222 # move workspace 'next|prev'
223 ############################################################
224 $tmp = get_unused_workspace();
225 $tmp2 = get_unused_workspace();
227 cmd "workspace $tmp";
229 is_num_children($tmp, 1, 'one container on first ws');
231 cmd "workspace $tmp2";
233 is_num_children($tmp2, 1, 'one container on second ws');
235 is_num_children($tmp2, 2, 'two containers on second ws');
238 cmd 'move workspace prev';
240 is_num_children($tmp, 2, 'two child containers on first ws');
241 is(sum_nodes(get_ws_content($tmp)), 4, 'four total containers on first ws');
242 is_num_children($tmp2, 0, 'no containers on second ws');
244 ############################################################
245 # move workspace current
246 # This is a special case that should be a no-op.
247 ############################################################
248 $tmp = fresh_workspace();
251 is_num_children($tmp, 1, 'one container on first ws');
252 my $tmpcount = sum_nodes(get_ws_content($tmp));
255 cmd "move workspace $tmp";
257 is(sum_nodes(get_ws_content($tmp)), $tmpcount, 'number of containers in first ws unchanged');
259 ############################################################
260 # move workspace '<name>'
261 ############################################################
262 $tmp2 = get_unused_workspace();
263 $tmp = fresh_workspace();
266 is_num_children($tmp, 1, 'one container on first ws');
268 cmd "workspace $tmp2";
270 is_num_children($tmp2, 1, 'one container on second ws');
272 is_num_children($tmp2, 2, 'two containers on second ws');
275 cmd "move workspace $tmp";
277 is_num_children($tmp, 2, 'two child containers on first ws');
278 is(sum_nodes(get_ws_content($tmp)), 4, 'four total containers on first ws');
279 is_num_children($tmp2, 0, 'no containers on second ws');
281 ############################################################
282 # move workspace number '<number>'
283 ############################################################
286 is_num_children('18', 1, 'one container on ws 18');
290 is_num_children('19', 1, 'one container on ws 19');
292 is_num_children('19', 2, 'two containers on ws 19');
295 cmd 'move workspace number 18';
297 is_num_children('18', 2, 'two child containers on ws 18');
298 is(sum_nodes(get_ws_content('18')), 4, 'four total containers on ws 18');
299 is_num_children('19', 0, 'no containers on ws 19');
301 ###################################################################
302 # move workspace '<name>' with a floating child
303 ###################################################################
304 $tmp2 = get_unused_workspace();
305 $tmp = fresh_workspace();
307 cmd 'floating toggle';
309 cmd 'floating toggle';
313 is_num_children($tmp, 1, 'one container on first workspace');
314 is(@{$ws->{floating_nodes}}, 2, 'two floating nodes on first workspace');
317 cmd "move workspace $tmp2";
320 is_num_children($tmp2, 1, 'one container on second workspace');
321 is(@{$ws->{floating_nodes}}, 2, 'two floating nodes on second workspace');
323 ###################################################################
324 # same as the above, but with only floating children
325 ###################################################################
326 $tmp2 = get_unused_workspace();
327 $tmp = fresh_workspace();
329 cmd 'floating toggle';
332 is_num_children($tmp, 0, 'no regular nodes on first workspace');
333 is(@{$ws->{floating_nodes}}, 1, 'one floating node on first workspace');
336 cmd "move workspace $tmp2";
339 is_num_children($tmp2, 0, 'no regular nodes on second workspace');
340 is(@{$ws->{floating_nodes}}, 1, 'one floating node on second workspace');