]> git.sur5r.net Git - i3/i3/blob - testcases/t/243-move-to-mark.t
Remove trailing whitespace from Perl scripts
[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 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://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 my $_NET_WM_STATE_REMOVE = 0;
30 my $_NET_WM_STATE_ADD = 1;
31 my $_NET_WM_STATE_TOGGLE = 2;
32
33 sub set_urgency {
34     my ($win, $urgent_flag) = @_;
35     my $msg = pack "CCSLLLLLL",
36         X11::XCB::CLIENT_MESSAGE, # response_type
37         32, # format
38         0, # sequence
39         $win->id, # window
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]
43         0, # data32[2]
44         0, # data32[3]
45         0; # data32[4]
46
47     $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
48 }
49
50 ###############################################################################
51 # Given 'M' and 'S' in a horizontal split, when 'S' is moved to 'M', then
52 # verify that nothing changed.
53 ###############################################################################
54
55 $ws = fresh_workspace;
56 $M = open_window;
57 cmd 'mark target';
58 $S = open_window;
59
60 cmd 'move container to mark target';
61 sync_with_i3;
62
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');
67
68 ###############################################################################
69 # Given 'S' and 'M' in a horizontal split, when 'S' is moved to 'M', then
70 # both containers switch places.
71 ###############################################################################
72
73 $ws = fresh_workspace;
74 $S = open_window;
75 $M = open_window;
76 cmd 'mark target';
77 cmd 'focus left';
78
79 cmd 'move container to mark target';
80 sync_with_i3;
81
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');
86
87 ###############################################################################
88 # Given 'S' and no container 'M' exists, when 'S' is moved to 'M', then
89 # the command is unsuccessful.
90 ###############################################################################
91
92 $ws = fresh_workspace;
93 $S = open_window;
94
95 $cmd_result = cmd 'move container to mark absent';
96
97 is($cmd_result->[0]->{success}, 0, 'command was unsuccessful');
98
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 ###############################################################################
103
104 $source_ws = fresh_workspace;
105 $S = open_window;
106 $target_ws = fresh_workspace;
107 $M = open_window;
108 cmd 'mark target';
109
110 cmd '[id="' . $S->{id} . '"] move container to mark target';
111 sync_with_i3;
112
113 ($nodes, $focus) = get_ws_content($source_ws);
114 is(@{$nodes}, 0, 'source workspace is empty');
115
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');
120
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 ###############################################################################
125
126 $source_ws = fresh_workspace;
127 $S = open_window;
128 $F = open_window;
129 $target_ws = fresh_workspace;
130 $M = open_window;
131 cmd 'mark target';
132 cmd 'workspace ' . $source_ws;
133 set_urgency($S, 1);
134
135 cmd '[id="' . $S->{id} . '"] move container to mark target';
136 sync_with_i3;
137
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');
142
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 ###############################################################################
147
148 $source_ws = fresh_workspace;
149 $S = open_window;
150
151 # open tabbed container ['A' 'M' 'B']
152 $target_ws = fresh_workspace;
153 $A = open_window;
154 cmd 'layout tabbed';
155 $M = open_window;
156 cmd 'mark target';
157 $B = open_window;
158
159 cmd '[id="' . $S->{id} . '"] move container to mark target';
160 sync_with_i3;
161
162 ($nodes, $focus) = get_ws_content($target_ws);
163 is(@{$nodes}, 1, 'there is a tabbed container');
164
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');
171
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
175 # within 'M'.
176 ###############################################################################
177
178 $source_ws = fresh_workspace;
179 $S = open_window;
180
181 $target_ws = fresh_workspace;
182 $A = open_window;
183 cmd 'layout tabbed';
184 cmd 'focus parent';
185 cmd 'mark target';
186 cmd 'focus child';
187 $B = open_window;
188 cmd 'split h';
189 $F = open_window;
190
191 cmd '[id="' . $S->{id} . '"] move container to mark target';
192 sync_with_i3;
193
194 ($nodes, $focus) = get_ws_content($target_ws);
195 is(@{$nodes}, 1, 'there is a tabbed container');
196
197 $nodes = $nodes->[0]->{nodes};
198 is(@{$nodes}, 3, 'there are three tabs');
199
200 is($nodes->[0]->{window}, $A->{id}, 'A is the first tab');
201 is($nodes->[2]->{window}, $S->{id}, 'S is the third tab');
202
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 ###############################################################################
208
209 $source_ws = fresh_workspace;
210 $S = open_window;
211
212 # open tabbed container ['A'['B' 'M']]
213 $target_ws = fresh_workspace;
214 $A = open_window;
215 cmd 'layout tabbed';
216 $B = open_window;
217 cmd 'split h';
218 $M = open_window;
219 cmd 'mark target';
220
221 cmd '[id="' . $S->{id} . '"] move container to mark target';
222 sync_with_i3;
223
224 ($nodes, $focus) = get_ws_content($target_ws);
225 is(@{$nodes}, 1, 'there is a tabbed container');
226
227 $nodes = $nodes->[0]->{nodes};
228 is(@{$nodes}, 2, 'there are two tabs');
229
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');
235
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 ###############################################################################
240
241 $source_ws = fresh_workspace;
242 $S = open_window;
243 $target_ws = fresh_workspace;
244 $A = open_window;
245 cmd 'layout tabbed';
246 $B = open_window;
247 cmd 'focus parent';
248 cmd 'mark target';
249 cmd 'focus child';
250
251 cmd '[id="' . $S->{id} . '"] move container to mark target';
252 sync_with_i3;
253
254 ($nodes, $focus) = get_ws_content($target_ws);
255 is(@{$nodes}, 1, 'there is a tabbed container');
256
257 $nodes = $nodes->[0]->{nodes};
258 is(@{$nodes}, 3, 'there are three tabs');
259
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');
263
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 ###############################################################################
269
270 $source_ws = fresh_workspace;
271 $S = open_window;
272 $target_ws = fresh_workspace;
273 $A = open_window;
274 cmd 'layout tabbed';
275 $F = open_window;
276 $M = $target_ws;
277 cmd 'focus parent';
278 cmd 'focus parent';
279 cmd 'mark target';
280 cmd 'focus ' . $source_ws;
281
282 cmd '[id="' . $S->{id} . '"] move container to mark target';
283 sync_with_i3;
284
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');
288
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
292 # workspaces as 'M'.
293 ###############################################################################
294
295 $source_ws = fresh_workspace;
296 $S = open_floating_window;
297 $target_ws = fresh_workspace;
298 $M = open_window;
299 cmd 'mark target';
300
301 cmd '[id="' . $S->{id} . '"] move container to mark target';
302 sync_with_i3;
303
304 is(@{get_ws($target_ws)->{floating_nodes}}, 1, 'target workspace has the container now');
305
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 ###############################################################################
311
312 $source_ws = fresh_workspace;
313 $S = open_window;
314 $target_ws = fresh_workspace;
315 $M = open_floating_window;
316 cmd 'mark target';
317
318 cmd '[id="' . $S->{id} . '"] move container to mark target';
319 sync_with_i3;
320
321 ($nodes, $focus) = get_ws_content($target_ws);
322 is(@{$nodes}, 1, 'tiling container moved to the target workspace');
323
324 ###############################################################################
325 # Given 'S' and 'M' are the same container, when 'S' is moved to 'M', then
326 # the command is ignored.
327 ###############################################################################
328
329 $ws = fresh_workspace;
330 $S = open_window;
331 $M = $S;
332 cmd 'mark target';
333
334 cmd '[id="' . $S->{id} . '"] move container to mark target';
335 sync_with_i3;
336
337 does_i3_live;
338
339 ###############################################################################
340
341 done_testing;