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 # Tests for the 'move [window|container] to mark' command
21 # In the following tests descriptions, we will always use the following names:
22 # * 'S' for the source container which is going to be moved,
23 # * 'M' for the marked target container to which 'S' will be moved.
25 my ($A, $B, $S, $M, $F, $source_ws, $target_ws, $ws);
29 my $_NET_WM_STATE_REMOVE = 0;
30 my $_NET_WM_STATE_ADD = 1;
31 my $_NET_WM_STATE_TOGGLE = 2;
34 my ($win, $urgent_flag) = @_;
35 my $msg = pack "CCSLLLLLL",
36 X11::XCB::CLIENT_MESSAGE, # response_type
40 $x->atom(name => '_NET_WM_STATE')->id, # message type
41 ($urgent_flag ? $_NET_WM_STATE_ADD : $_NET_WM_STATE_REMOVE), # data32[0]
42 $x->atom(name => '_NET_WM_STATE_DEMANDS_ATTENTION')->id, # data32[1]
47 $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
50 ###############################################################################
51 # Given 'M' and 'S' in a horizontal split, when 'S' is moved to 'M', then
52 # verify that nothing changed.
53 ###############################################################################
55 $ws = fresh_workspace;
60 cmd 'move container to mark target';
63 ($nodes, $focus) = get_ws_content($ws);
64 is(@{$nodes}, 2, 'there are two containers');
65 is($nodes->[0]->{window}, $M->{id}, 'M is left of S');
66 is($nodes->[1]->{window}, $S->{id}, 'S is right of M');
68 ###############################################################################
69 # Given 'S' and 'M' in a horizontal split, when 'S' is moved to 'M', then
70 # both containers switch places.
71 ###############################################################################
73 $ws = fresh_workspace;
79 cmd 'move container to mark target';
82 ($nodes, $focus) = get_ws_content($ws);
83 is(@{$nodes}, 2, 'there are two containers');
84 is($nodes->[0]->{window}, $M->{id}, 'M is left of S');
85 is($nodes->[1]->{window}, $S->{id}, 'S is right of M');
87 ###############################################################################
88 # Given 'S' and no container 'M' exists, when 'S' is moved to 'M', then
89 # the command is unsuccessful.
90 ###############################################################################
92 $ws = fresh_workspace;
95 $cmd_result = cmd 'move container to mark absent';
97 is($cmd_result->[0]->{success}, 0, 'command was unsuccessful');
99 ###############################################################################
100 # Given 'S' and 'M' on different workspaces, when 'S' is moved to 'M', then
101 # 'S' ends up on the same workspace as 'M'.
102 ###############################################################################
104 $source_ws = fresh_workspace;
106 $target_ws = fresh_workspace;
110 cmd '[id="' . $S->{id} . '"] move container to mark target';
113 ($nodes, $focus) = get_ws_content($source_ws);
114 is(@{$nodes}, 0, 'source workspace is empty');
116 ($nodes, $focus) = get_ws_content($target_ws);
117 is(@{$nodes}, 2, 'both containers are on the target workspace');
118 is($nodes->[0]->{window}, $M->{id}, 'M is left of S');
119 is($nodes->[1]->{window}, $S->{id}, 'S is right of M');
121 ###############################################################################
122 # Given 'S' and 'M' on different workspaces and 'S' is urgent, when 'S' is
123 # moved to 'M', then the urgency flag is transferred to the target workspace.
124 ###############################################################################
126 $source_ws = fresh_workspace;
129 $target_ws = fresh_workspace;
132 cmd 'workspace ' . $source_ws;
135 cmd '[id="' . $S->{id} . '"] move container to mark target';
138 $source_ws = get_ws($source_ws);
139 $target_ws = get_ws($target_ws);
140 ok(!$source_ws->{urgent}, 'source workspace is no longer urgent');
141 ok($target_ws->{urgent}, 'target workspace is urgent');
143 ###############################################################################
144 # Given 'S' and 'M' where 'M' is inside a tabbed container, when 'S' is moved
145 # to 'M', then 'S' ends up as a new tab.
146 ###############################################################################
148 $source_ws = fresh_workspace;
151 # open tabbed container ['A' 'M' 'B']
152 $target_ws = fresh_workspace;
159 cmd '[id="' . $S->{id} . '"] move container to mark target';
162 ($nodes, $focus) = get_ws_content($target_ws);
163 is(@{$nodes}, 1, 'there is a tabbed container');
165 $nodes = $nodes->[0]->{nodes};
166 is(@{$nodes}, 4, 'all four containers are on the target workspace');
167 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
168 is($nodes->[1]->{window}, $M->{id}, 'M is the second tab');
169 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
170 is($nodes->[3]->{window}, $B->{id}, 'B is the fourth tab');
172 ###############################################################################
173 # Given 'S' and 'M' where 'M' is a tabbed container where the currently focused
174 # tab is a nested layout, when 'S' is moved to 'M', then 'S' is a new tab
176 ###############################################################################
178 $source_ws = fresh_workspace;
181 $target_ws = fresh_workspace;
191 cmd '[id="' . $S->{id} . '"] move container to mark target';
194 ($nodes, $focus) = get_ws_content($target_ws);
195 is(@{$nodes}, 1, 'there is a tabbed container');
197 $nodes = $nodes->[0]->{nodes};
198 is(@{$nodes}, 3, 'there are three tabs');
200 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
201 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
203 ###############################################################################
204 # Given 'S' and 'M' where 'M' is inside a split container inside a tabbed
205 # container, when 'S' is moved to 'M', then 'S' ends up as a container
206 # within the same tab as 'M'.
207 ###############################################################################
209 $source_ws = fresh_workspace;
212 # open tabbed container ['A'['B' 'M']]
213 $target_ws = fresh_workspace;
221 cmd '[id="' . $S->{id} . '"] move container to mark target';
224 ($nodes, $focus) = get_ws_content($target_ws);
225 is(@{$nodes}, 1, 'there is a tabbed container');
227 $nodes = $nodes->[0]->{nodes};
228 is(@{$nodes}, 2, 'there are two tabs');
230 $nodes = $nodes->[1]->{nodes};
231 is(@{$nodes}, 3, 'the tab with the marked children has three children');
232 is($nodes->[0]->{window}, $B->{id}, 'B is the first tab');
233 is($nodes->[1]->{window}, $M->{id}, 'M is the second tab');
234 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
236 ###############################################################################
237 # Given 'S', 'A' and 'B' where 'A' and 'B' are inside the tabbed container 'M',
238 # when 'S' is moved to 'M', then 'S' ends up as a new tab in 'M'.
239 ###############################################################################
241 $source_ws = fresh_workspace;
243 $target_ws = fresh_workspace;
251 cmd '[id="' . $S->{id} . '"] move container to mark target';
254 ($nodes, $focus) = get_ws_content($target_ws);
255 is(@{$nodes}, 1, 'there is a tabbed container');
257 $nodes = $nodes->[0]->{nodes};
258 is(@{$nodes}, 3, 'there are three tabs');
260 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
261 is($nodes->[1]->{window}, $B->{id}, 'B is the second tab');
262 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
264 ###############################################################################
265 # Given 'S', 'A', 'F' and 'M', where 'M' is a workspace containing a tabbed
266 # container, when 'S' is moved to 'M', then 'S' does not end up as a tab, but
267 # rather as a new window next to the tabbed container.
268 ###############################################################################
270 $source_ws = fresh_workspace;
272 $target_ws = fresh_workspace;
280 cmd 'focus ' . $source_ws;
282 cmd '[id="' . $S->{id} . '"] move container to mark target';
285 ($nodes, $focus) = get_ws_content($target_ws);
286 is(@{$nodes}, 2, 'there is a tabbed container and a window');
287 is($nodes->[1]->{window}, $S->{id}, 'S is the second window');
289 ###############################################################################
290 # Given 'S' and 'M' where 'S' is floating and 'M' on a different workspace,
291 # when 'S' is moved to 'M', then 'S' is a floating container on the same
293 ###############################################################################
295 $source_ws = fresh_workspace;
296 $S = open_floating_window;
297 $target_ws = fresh_workspace;
301 cmd '[id="' . $S->{id} . '"] move container to mark target';
304 is(@{get_ws($target_ws)->{floating_nodes}}, 1, 'target workspace has the container now');
306 ###############################################################################
307 # Given 'S' and 'M' where 'M' is floating and on a different workspace,
308 # when 'S' is moved to 'M', then 'S' ends up as a tiling container on the
309 # same workspace as 'M'.
310 ###############################################################################
312 $source_ws = fresh_workspace;
314 $target_ws = fresh_workspace;
315 $M = open_floating_window;
318 cmd '[id="' . $S->{id} . '"] move container to mark target';
321 ($nodes, $focus) = get_ws_content($target_ws);
322 is(@{$nodes}, 1, 'tiling container moved to the target workspace');
324 ###############################################################################
325 # Given 'S' and 'M' are the same container, when 'S' is moved to 'M', then
326 # the command is ignored.
327 ###############################################################################
329 $ws = fresh_workspace;
334 cmd '[id="' . $S->{id} . '"] move container to mark target';
339 ###############################################################################