]> git.sur5r.net Git - i3/i3/blob - testcases/t/243-move-to-mark.t
Added testcase for moving a window to a workspace holding the mark
[i3/i3] / testcases / t / 243-move-to-mark.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Tests for the 'move [window|container] to mark' command
18 # Ticket: #1643
19 use i3test;
20
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.
24
25 my ($A, $B, $S, $M, $F, $source_ws, $target_ws, $ws);
26 my ($nodes, $focus);
27 my $cmd_result;
28
29 ###############################################################################
30 # Given 'M' and 'S' in a horizontal split, when 'S' is moved to 'M', then
31 # verify that nothing changed.
32 ###############################################################################
33
34 $ws = fresh_workspace;
35 $M = open_window;
36 cmd 'mark target';
37 $S = open_window;
38
39 cmd 'move container to mark target';
40 sync_with_i3;
41
42 ($nodes, $focus) = get_ws_content($ws);
43 is(@{$nodes}, 2, 'there are two containers');
44 is($nodes->[0]->{window}, $M->{id}, 'M is left of S');
45 is($nodes->[1]->{window}, $S->{id}, 'S is right of M');
46
47 ###############################################################################
48 # Given 'S' and 'M' in a horizontal split, when 'S' is moved to 'M', then
49 # both containers switch places.
50 ###############################################################################
51
52 $ws = fresh_workspace;
53 $S = open_window;
54 $M = open_window;
55 cmd 'mark target';
56 cmd 'focus left';
57
58 cmd 'move container to mark target';
59 sync_with_i3;
60
61 ($nodes, $focus) = get_ws_content($ws);
62 is(@{$nodes}, 2, 'there are two containers');
63 is($nodes->[0]->{window}, $M->{id}, 'M is left of S');
64 is($nodes->[1]->{window}, $S->{id}, 'S is right of M');
65
66 ###############################################################################
67 # Given 'S' and no container 'M' exists, when 'S' is moved to 'M', then
68 # the command is unsuccessful.
69 ###############################################################################
70
71 $ws = fresh_workspace;
72 $S = open_window;
73
74 $cmd_result = cmd 'move container to mark absent';
75
76 is($cmd_result->[0]->{success}, 0, 'command was unsuccessful');
77
78 ###############################################################################
79 # Given 'S' and 'M' on different workspaces, when 'S' is moved to 'M', then
80 # 'S' ends up on the same workspace as 'M'.
81 ###############################################################################
82
83 $source_ws = fresh_workspace;
84 $S = open_window;
85 $target_ws = fresh_workspace;
86 $M = open_window;
87 cmd 'mark target';
88
89 cmd '[id="' . $S->{id} . '"] move container to mark target';
90 sync_with_i3;
91
92 ($nodes, $focus) = get_ws_content($source_ws);
93 is(@{$nodes}, 0, 'source workspace is empty');
94
95 ($nodes, $focus) = get_ws_content($target_ws);
96 is(@{$nodes}, 2, 'both containers are on the target workspace');
97 is($nodes->[0]->{window}, $M->{id}, 'M is left of S');
98 is($nodes->[1]->{window}, $S->{id}, 'S is right of M');
99
100 ###############################################################################
101 # Given 'S' and 'M' on different workspaces and 'S' is urgent, when 'S' is 
102 # moved to 'M', then the urgency flag is transferred to the target workspace.
103 ###############################################################################
104
105 # TODO
106
107 ###############################################################################
108 # Given 'S' and 'M' where 'M' is inside a tabbed container, when 'S' is moved
109 # to 'M', then 'S' ends up as a new tab.
110 ###############################################################################
111
112 $source_ws = fresh_workspace;
113 $S = open_window;
114
115 # open tabbed container ['A' 'M' 'B']
116 $target_ws = fresh_workspace;
117 $A = open_window;
118 cmd 'layout tabbed';
119 $M = open_window;
120 cmd 'mark target';
121 $B = open_window;
122
123 cmd '[id="' . $S->{id} . '"] move container to mark target';
124 sync_with_i3;
125
126 ($nodes, $focus) = get_ws_content($target_ws);
127 is(@{$nodes}, 1, 'there is a tabbed container');
128
129 $nodes = $nodes->[0]->{nodes};
130 is(@{$nodes}, 4, 'all four containers are on the target workspace');
131 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
132 is($nodes->[1]->{window}, $M->{id}, 'M is the second tab');
133 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
134 is($nodes->[3]->{window}, $B->{id}, 'B is the fourth tab');
135
136 ###############################################################################
137 # Given 'S' and 'M' where 'M' is a tabbed container where the currently focused
138 # tab is a nested layout, when 'S' is moved to 'M', then 'S' is a new tab
139 # within 'M'.
140 ###############################################################################
141
142 $source_ws = fresh_workspace;
143 $S = open_window;
144
145 $target_ws = fresh_workspace;
146 $A = open_window;
147 cmd 'layout tabbed';
148 cmd 'focus parent';
149 cmd 'mark target';
150 cmd 'focus child';
151 $B = open_window;
152 cmd 'split h';
153 $F = open_window;
154
155 cmd '[id="' . $S->{id} . '"] move container to mark target';
156 sync_with_i3;
157
158 ($nodes, $focus) = get_ws_content($target_ws);
159 is(@{$nodes}, 1, 'there is a tabbed container');
160
161 $nodes = $nodes->[0]->{nodes};
162 is(@{$nodes}, 3, 'there are three tabs');
163
164 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
165 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
166
167 ###############################################################################
168 # Given 'S' and 'M' where 'M' is inside a split container inside a tabbed
169 # container, when 'S' is moved to 'M', then 'S' ends up as a container
170 # within the same tab as 'M'.
171 ###############################################################################
172
173 $source_ws = fresh_workspace;
174 $S = open_window;
175
176 # open tabbed container ['A'['B' 'M']]
177 $target_ws = fresh_workspace;
178 $A = open_window;
179 cmd 'layout tabbed';
180 $B = open_window;
181 cmd 'split h';
182 $M = open_window;
183 cmd 'mark target';
184
185 cmd '[id="' . $S->{id} . '"] move container to mark target';
186 sync_with_i3;
187
188 ($nodes, $focus) = get_ws_content($target_ws);
189 is(@{$nodes}, 1, 'there is a tabbed container');
190
191 $nodes = $nodes->[0]->{nodes};
192 is(@{$nodes}, 2, 'there are two tabs');
193
194 $nodes = $nodes->[1]->{nodes};
195 is(@{$nodes}, 3, 'the tab with the marked children has three children');
196 is($nodes->[0]->{window}, $B->{id}, 'B is the first tab');
197 is($nodes->[1]->{window}, $M->{id}, 'M is the second tab');
198 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
199
200 ###############################################################################
201 # Given 'S', 'A' and 'B' where 'A' and 'B' are inside the tabbed container 'M',
202 # when 'S' is moved to 'M', then 'S' ends up as a new tab in 'M'.
203 ###############################################################################
204
205 $source_ws = fresh_workspace;
206 $S = open_window;
207 $target_ws = fresh_workspace;
208 $A = open_window;
209 cmd 'layout tabbed';
210 $B = open_window;
211 cmd 'focus parent';
212 cmd 'mark target';
213 cmd 'focus child';
214
215 cmd '[id="' . $S->{id} . '"] move container to mark target';
216 sync_with_i3;
217
218 ($nodes, $focus) = get_ws_content($target_ws);
219 is(@{$nodes}, 1, 'there is a tabbed container');
220
221 $nodes = $nodes->[0]->{nodes};
222 is(@{$nodes}, 3, 'there are three tabs');
223
224 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
225 is($nodes->[1]->{window}, $B->{id}, 'B is the second tab');
226 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
227
228 ###############################################################################
229 # Given 'S', 'A', 'F' and 'M', where 'M' is a workspace containing a tabbed
230 # container, when 'S' is moved to 'M', then 'S' does not end up as a tab, but
231 # rather as a new window next to the tabbed container.
232 ###############################################################################
233
234 $source_ws = fresh_workspace;
235 $S = open_window;
236 $target_ws = fresh_workspace;
237 $A = open_window;
238 cmd 'layout tabbed';
239 $F = open_window;
240 $M = $target_ws;
241 cmd 'focus parent';
242 cmd 'focus parent';
243 cmd 'mark target';
244 cmd 'focus ' . $source_ws;
245
246 cmd '[id="' . $S->{id} . '"] move container to mark target';
247 sync_with_i3;
248
249 ($nodes, $focus) = get_ws_content($target_ws);
250 is(@{$nodes}, 2, 'there is a tabbed container and a window');
251 is($nodes->[1]->{window}, $S->{id}, 'S is the second window');
252
253 ###############################################################################
254 # Given 'S', 'F' and 'M' where 'F' and 'M' are containers inside the same
255 # tabbed container and where 'F' has the focus within that container, when
256 # 'S' is moved to 'M', then 'S' ends up behind 'F'.
257 ###############################################################################
258
259 # TODO needs to be clarified whether this is the behavior we want
260
261 ###############################################################################
262 # Given 'S' and 'M' where 'S' is floating and 'M' on a different workspace,
263 # when 'S' is moved to 'M', then 'S' is a floating container on the same
264 # workspaces as 'M'.
265 ###############################################################################
266
267 $source_ws = fresh_workspace;
268 $S = open_floating_window;
269 $target_ws = fresh_workspace;
270 $M = open_window;
271 cmd 'mark target';
272
273 cmd '[id="' . $S->{id} . '"] move container to mark target';
274 sync_with_i3;
275
276 is(@{get_ws($target_ws)->{floating_nodes}}, 1, 'target workspace has the container now');
277
278 ###############################################################################
279 # Given 'S' and 'M' where 'M' is floating and on a different workspace,
280 # when 'S' is moved to 'M', then 'S' ends up as a tiling container on the
281 # same workspace as 'M'.
282 ###############################################################################
283
284 $source_ws = fresh_workspace;
285 $S = open_window;
286 $target_ws = fresh_workspace;
287 $M = open_floating_window;
288 cmd 'mark target';
289
290 cmd '[id="' . $S->{id} . '"] move container to mark target';
291 sync_with_i3;
292
293 ($nodes, $focus) = get_ws_content($target_ws);
294 is(@{$nodes}, 1, 'tiling container moved to the target workspace');
295
296 ###############################################################################
297 # Given 'S' and 'M' are the same container, when 'S' is moved to 'M', then
298 # the command is ignored.
299 ###############################################################################
300
301 $ws = fresh_workspace;
302 $S = open_window;
303 $M = $S;
304 cmd 'mark target';
305
306 cmd '[id="' . $S->{id} . '"] move container to mark target';
307 sync_with_i3;
308
309 does_i3_live;
310
311 ###############################################################################
312
313 done_testing;