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
25 $x->root->warp_pointer(0, 0);
28 sub move_workspace_test {
31 my $tmp = get_unused_workspace();
32 my $tmp2 = get_unused_workspace();
35 is_num_children($tmp, 0, 'no containers yet');
37 my $first = open_empty_con($i3);
38 my $second = open_empty_con($i3);
39 is_num_children($tmp, 2, 'two containers on first ws');
41 cmd "workspace $tmp2";
42 is_num_children($tmp2, 0, 'no containers on second ws yet');
47 is_num_children($tmp, 1, 'one container on first ws anymore');
48 is_num_children($tmp2, 1, 'one container on second ws');
49 my ($nodes, $focus) = get_ws_content($tmp2);
51 is($focus->[0], $second, 'same container on different ws');
53 ($nodes, $focus) = get_ws_content($tmp);
54 ok($nodes->[0]->{focused}, 'first container focused on first ws');
57 move_workspace_test('move workspace'); # supported for legacy reasons
58 move_workspace_test('move to workspace');
59 # Those are just synonyms and more verbose ways of saying the same thing:
60 move_workspace_test('move window to workspace');
61 move_workspace_test('move container to workspace');
63 ################################################################################
64 # Check that 'move to workspace number <number>' works to move a window to
65 # named workspaces which start with <number>.
66 ################################################################################
68 cmd 'workspace 13: meh';
70 is_num_children('13: meh', 1, 'one container on 13: meh');
72 ok(!workspace_exists('13'), 'workspace 13 does not exist yet');
77 cmd 'move to workspace number 13';
78 is_num_children('13: meh', 2, 'one container on 13: meh');
79 is_num_children('12', 0, 'no container on 12 anymore');
81 ok(!workspace_exists('13'), 'workspace 13 does still not exist');
83 ################################################################################
84 # Check that 'move to workspace number <number><name>' works to move a window to
85 # named workspaces which start with <number>.
86 ################################################################################
88 cmd 'workspace 15: meh';
90 is_num_children('15: meh', 1, 'one container on 15: meh');
92 ok(!workspace_exists('15'), 'workspace 15 does not exist yet');
93 ok(!workspace_exists('15: duh'), 'workspace 15: duh does not exist yet');
98 cmd 'move to workspace number 15: duh';
99 is_num_children('15: meh', 2, 'two containers on 15: meh');
100 is_num_children('14', 0, 'no container on 14 anymore');
102 ok(!workspace_exists('15'), 'workspace 15 does still not exist');
103 ok(!workspace_exists('15: duh'), 'workspace 15 does still not exist');
105 ###################################################################
106 # check if 'move workspace next' and 'move workspace prev' work
107 ###################################################################
109 # Open two containers on the first workspace, one container on the second
110 # workspace. Because the workspaces are named, they will be sorted by order of
112 my $tmp = get_unused_workspace();
113 my $tmp2 = get_unused_workspace();
114 cmd "workspace $tmp";
115 is_num_children($tmp, 0, 'no containers yet');
116 my $first = open_empty_con($i3);
117 my $second = open_empty_con($i3);
118 is_num_children($tmp, 2, 'two containers');
120 cmd "workspace $tmp2";
121 is_num_children($tmp2, 0, 'no containers yet');
122 my $third = open_empty_con($i3);
123 is_num_children($tmp2, 1, 'one container on second ws');
125 # go back to the first workspace, move one of the containers to the next one
126 cmd "workspace $tmp";
127 cmd 'move workspace next';
128 is_num_children($tmp, 1, 'one container on first ws');
129 is_num_children($tmp2, 2, 'two containers on second ws');
131 # go to the second workspace and move two containers to the first one
132 cmd "workspace $tmp2";
133 cmd 'move workspace prev';
134 cmd 'move workspace prev';
135 is_num_children($tmp, 3, 'three containers on first ws');
136 is_num_children($tmp2, 0, 'no containers on second ws');
138 ###################################################################
139 # check if 'move workspace current' works
140 ###################################################################
142 $tmp = get_unused_workspace();
143 $tmp2 = get_unused_workspace();
145 cmd "workspace $tmp";
146 $first = open_window(name => 'win-name');
147 is_num_children($tmp, 1, 'one container on first ws');
149 cmd "workspace $tmp2";
150 is_num_children($tmp2, 0, 'no containers yet');
152 cmd qq|[title="win-name"] move workspace $tmp2|;
153 is_num_children($tmp2, 1, 'one container on second ws');
155 cmd qq|[title="win-name"] move workspace $tmp|;
156 is_num_children($tmp2, 0, 'no containers on second ws');
158 ###################################################################
159 # check if floating cons are moved to new workspaces properly
160 # (that is, if they are floating on the target ws, too)
161 ###################################################################
163 $tmp = get_unused_workspace();
164 $tmp2 = get_unused_workspace();
165 cmd "workspace $tmp";
168 cmd "floating toggle";
170 my $ws = get_ws($tmp);
171 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
172 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
174 cmd "move workspace $tmp2";
177 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
178 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
180 ################################################################################
181 # Check that 'move workspace number' works correctly.
182 ################################################################################
184 $tmp = get_unused_workspace();
189 is_num_children('16', 1, 'one node on ws 16');
191 cmd "workspace $tmp";
193 cmd 'move workspace number 16';
194 is_num_children('16', 2, 'two nodes on ws 16');
196 ok(!workspace_exists('17'), 'workspace 17 does not exist yet');
198 cmd 'move workspace number 17';
199 ok(workspace_exists('17'), 'workspace 17 created by moving');
200 is(@{get_ws('17')->{nodes}}, 1, 'one node on ws 16');
202 ################################################################################
203 # The following four tests verify the various 'move workspace' commands when
204 # the selection is itself a workspace.
205 ################################################################################
207 # borrowed from 122-split.t
208 # recursively sums up all nodes and their children
212 return 0 if !@{$nodes};
214 my @children = (map { @{$_->{nodes}} } @{$nodes},
215 map { @{$_->{'floating_nodes'}} } @{$nodes});
217 return @{$nodes} + sum_nodes(\@children);
220 ############################################################
221 # move workspace 'next|prev'
222 ############################################################
223 $tmp = get_unused_workspace();
224 $tmp2 = get_unused_workspace();
226 cmd "workspace $tmp";
228 is_num_children($tmp, 1, 'one container on first ws');
230 cmd "workspace $tmp2";
232 is_num_children($tmp2, 1, 'one container on second ws');
234 is_num_children($tmp2, 2, 'two containers on second ws');
237 cmd 'move workspace prev';
239 is_num_children($tmp, 2, 'two child containers on first ws');
240 is(sum_nodes(get_ws_content($tmp)), 4, 'four total containers on first ws');
241 is_num_children($tmp2, 0, 'no containers on second ws');
243 ############################################################
244 # move workspace current
245 # This is a special case that should be a no-op.
246 ############################################################
247 $tmp = fresh_workspace();
250 is_num_children($tmp, 1, 'one container on first ws');
251 my $tmpcount = sum_nodes(get_ws_content($tmp));
254 cmd "move workspace $tmp";
256 is(sum_nodes(get_ws_content($tmp)), $tmpcount, 'number of containers in first ws unchanged');
258 ############################################################
259 # move workspace '<name>'
260 ############################################################
261 $tmp2 = get_unused_workspace();
262 $tmp = fresh_workspace();
265 is_num_children($tmp, 1, 'one container on first ws');
267 cmd "workspace $tmp2";
269 is_num_children($tmp2, 1, 'one container on second ws');
271 is_num_children($tmp2, 2, 'two containers on second ws');
274 cmd "move workspace $tmp";
276 is_num_children($tmp, 2, 'two child containers on first ws');
277 is(sum_nodes(get_ws_content($tmp)), 4, 'four total containers on first ws');
278 is_num_children($tmp2, 0, 'no containers on second ws');
280 ############################################################
281 # move workspace number '<number>'
282 ############################################################
285 is_num_children('18', 1, 'one container on ws 18');
289 is_num_children('19', 1, 'one container on ws 19');
291 is_num_children('19', 2, 'two containers on ws 19');
294 cmd 'move workspace number 18';
296 is_num_children('18', 2, 'two child containers on ws 18');
297 is(sum_nodes(get_ws_content('18')), 4, 'four total containers on ws 18');
298 is_num_children('19', 0, 'no containers on ws 19');
300 ###################################################################
301 # move workspace '<name>' with a floating child
302 ###################################################################
303 $tmp2 = get_unused_workspace();
304 $tmp = fresh_workspace();
306 cmd 'floating toggle';
308 cmd 'floating toggle';
312 is_num_children($tmp, 1, 'one container on first workspace');
313 is(@{$ws->{floating_nodes}}, 2, 'two floating nodes on first workspace');
316 cmd "move workspace $tmp2";
319 is_num_children($tmp2, 1, 'one container on second workspace');
320 is(@{$ws->{floating_nodes}}, 2, 'two floating nodes on second workspace');
322 ###################################################################
323 # same as the above, but with only floating children
324 ###################################################################
325 $tmp2 = get_unused_workspace();
326 $tmp = fresh_workspace();
328 cmd 'floating toggle';
331 is_num_children($tmp, 0, 'no regular nodes on first workspace');
332 is(@{$ws->{floating_nodes}}, 1, 'one floating node on first workspace');
335 cmd "move workspace $tmp2";
338 is_num_children($tmp2, 0, 'no regular nodes on second workspace');
339 is(@{$ws->{floating_nodes}}, 1, 'one floating node on second workspace');