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 the swap command.
19 use i3test i3_autostart => 0;
23 font font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
25 for_window[class="mark_A"] mark A
26 for_window[class="mark_B"] mark B
30 my ($ws, $ws1, $ws2, $ws3);
31 my ($nodes, $expected_focus, $A, $B, $F);
35 ###############################################################################
36 # Swap two containers next to each other.
37 # Focus should stay on B because both windows are on the focused workspace.
38 # The focused container is B.
40 # +---+---+ Layout: H1[ A B ]
41 # | A | B | Focus Stacks:
43 ###############################################################################
44 $pid = launch_with_config($config);
45 $ws = fresh_workspace;
47 $A = open_window(wm_class => 'mark_A');
48 $B = open_window(wm_class => 'mark_B');
49 $expected_focus = get_focused($ws);
51 cmd '[con_mark=B] swap container with mark A';
53 $nodes = get_ws_content($ws);
54 is($nodes->[0]->{window}, $B->{id}, 'B is on the left');
55 is($nodes->[1]->{window}, $A->{id}, 'A is on the right');
56 is(get_focused($ws), $expected_focus, 'B is still focused');
58 exit_gracefully($pid);
60 ###############################################################################
61 # Swap two containers with different parents.
62 # In this test, the focus head of the left v-split container is A.
63 # The focused container is B.
65 # +---+---+ Layout: H1[ V1[ A Y ] V2[ X B ] ]
66 # | A | X | Focus Stacks:
67 # +---+---+ H1: V2, V1
70 ###############################################################################
71 $pid = launch_with_config($config);
72 $ws = fresh_workspace;
74 $A = open_window(wm_class => 'mark_A');
75 $B = open_window(wm_class => 'mark_B');
78 cmd 'move up, focus left';
81 cmd 'focus up, focus right, focus down';
82 $expected_focus = get_focused($ws);
84 cmd '[con_mark=B] swap container with mark A';
86 $nodes = get_ws_content($ws);
87 is($nodes->[0]->{nodes}->[0]->{window}, $B->{id}, 'B is on the top left');
88 is($nodes->[1]->{nodes}->[1]->{window}, $A->{id}, 'A is on the bottom right');
89 is(get_focused($ws), $expected_focus, 'B is still focused');
91 exit_gracefully($pid);
93 ###############################################################################
94 # Swap two containers with different parents.
95 # In this test, the focus head of the left v-split container is _not_ A.
96 # The focused container is B.
98 # +---+---+ Layout: H1[ V1[ A Y ] V2[ X B ] ]
99 # | A | X | Focus Stacks:
100 # +---+---+ H1: V2, V1
103 ###############################################################################
104 $pid = launch_with_config($config);
105 $ws = fresh_workspace;
107 $A = open_window(wm_class => 'mark_A');
108 $B = open_window(wm_class => 'mark_B');
111 cmd 'move up, focus left';
114 cmd 'focus right, focus down';
115 $expected_focus = get_focused($ws);
117 cmd '[con_mark=B] swap container with mark A';
119 $nodes = get_ws_content($ws);
120 is($nodes->[0]->{nodes}->[0]->{window}, $B->{id}, 'B is on the top left');
121 is($nodes->[1]->{nodes}->[1]->{window}, $A->{id}, 'A is on the bottom right');
122 is(get_focused($ws), $expected_focus, 'B is still focused');
124 exit_gracefully($pid);
126 ###############################################################################
127 # Swap two containers with one being on a different workspace.
128 # The focused container is B.
130 # Layout: O1[ W1[ H1 ] W2[ H2 ] ]
134 # +---+---+ Layout: H1[ A X ]
135 # | A | X | Focus Stacks:
138 # +---+---+ Layout: H2[ Y, B ]
139 # | Y | B | Focus Stacks:
141 ###############################################################################
142 $pid = launch_with_config($config);
144 $ws1 = fresh_workspace;
145 $A = open_window(wm_class => 'mark_A');
146 $expected_focus = get_focused($ws1);
150 $ws2 = fresh_workspace;
152 $B = open_window(wm_class => 'mark_B');
154 cmd '[con_mark=B] swap container with mark A';
156 $nodes = get_ws_content($ws1);
157 is($nodes->[0]->{window}, $B->{id}, 'B is on ws1:left');
159 $nodes = get_ws_content($ws2);
160 is($nodes->[1]->{window}, $A->{id}, 'A is on ws1:right');
161 is(get_focused($ws2), $expected_focus, 'A is focused');
163 exit_gracefully($pid);
165 ###############################################################################
166 # Swap two non-focused containers within the same workspace.
168 # +---+---+ Layout: H1[ V1[ A X ] V2[ F B ] ]
169 # | A | F | Focus Stacks:
170 # +---+---+ H1: V2, V1
173 ###############################################################################
174 $pid = launch_with_config($config);
175 $ws = fresh_workspace;
177 $A = open_window(wm_class => 'mark_A');
178 $B = open_window(wm_class => 'mark_B');
181 cmd 'move up, focus left';
184 cmd 'focus up, focus right';
185 $expected_focus = get_focused($ws);
187 cmd '[con_mark=B] swap container with mark A';
189 $nodes = get_ws_content($ws);
190 is($nodes->[0]->{nodes}->[0]->{window}, $B->{id}, 'B is on the top left');
191 is($nodes->[1]->{nodes}->[1]->{window}, $A->{id}, 'A is on the bottom right');
192 is(get_focused($ws), $expected_focus, 'F is still focused');
194 exit_gracefully($pid);
196 ###############################################################################
197 # Swap two non-focused containers which are both on different workspaces.
199 # Layout: O1[ W1[ A ] W2[ B ] W3[ F ] ]
214 ###############################################################################
215 $pid = launch_with_config($config);
217 $ws1 = fresh_workspace;
218 $A = open_window(wm_class => 'mark_A');
220 $ws2 = fresh_workspace;
221 $B = open_window(wm_class => 'mark_B');
223 $ws3 = fresh_workspace;
225 $expected_focus = get_focused($ws3);
227 cmd '[con_mark=B] swap container with mark A';
229 $nodes = get_ws_content($ws1);
230 is($nodes->[0]->{window}, $B->{id}, 'B is on the first workspace');
232 $nodes = get_ws_content($ws2);
233 is($nodes->[0]->{window}, $A->{id}, 'A is on the second workspace');
235 is(get_focused($ws3), $expected_focus, 'F is still focused');
237 exit_gracefully($pid);
239 ###############################################################################
240 # Swap two non-focused containers with one being on a different workspace.
242 # Layout: O1[ W1[ A ] W2[ H2 ] ]
250 # +---+---+ Layout: H2[ B, F ]
251 # | B | F | Focus Stacks:
253 ###############################################################################
254 $pid = launch_with_config($config);
256 $ws1 = fresh_workspace;
257 $A = open_window(wm_class => 'mark_A');
259 $ws2 = fresh_workspace;
260 $B = open_window(wm_class => 'mark_B');
262 $expected_focus = get_focused($ws2);
264 cmd '[con_mark=B] swap container with mark A';
266 $nodes = get_ws_content($ws1);
267 is($nodes->[0]->{window}, $B->{id}, 'B is on the first workspace');
269 $nodes = get_ws_content($ws2);
270 is($nodes->[0]->{window}, $A->{id}, 'A is on the left of the second workspace');
271 is(get_focused($ws2), $expected_focus, 'F is still focused');
273 exit_gracefully($pid);
275 ###############################################################################
276 # 1. A container cannot be swapped with its parent.
277 # 2. A container cannot be swapped with one of its children.
280 # +---+---+ Layout: H1[ X V1[ Y B ] ]
281 # | | Y | (with A := V1)
285 ###############################################################################
286 $pid = launch_with_config($config);
288 $ws = fresh_workspace;
292 $B = open_window(wm_class => 'mark_B');
293 cmd 'focus parent, mark A, focus child';
295 $result = cmd '[con_mark=B] swap container with mark A';
296 is($result->[0]->{success}, 0, 'B cannot be swappd with its parent');
298 $result = cmd '[con_mark=A] swap container with mark B';
299 is($result->[0]->{success}, 0, 'A cannot be swappd with one of its children');
301 exit_gracefully($pid);
303 ###############################################################################
304 # Swapping two containers preserves the geometry of the container they are
305 # being swapped with.
316 ###############################################################################
317 $pid = launch_with_config($config);
319 $ws = fresh_workspace;
320 $A = open_window(wm_class => 'mark_A');
321 $B = open_window(wm_class => 'mark_B');
322 cmd 'resize grow width 0 or 25 ppt';
325 $nodes = get_ws_content($ws);
326 cmp_float($nodes->[0]->{percent}, 0.25, 'A has 25% width');
327 cmp_float($nodes->[1]->{percent}, 0.75, 'B has 75% width');
329 cmd '[con_mark=B] swap container with mark A';
331 $nodes = get_ws_content($ws);
332 cmp_float($nodes->[0]->{percent}, 0.25, 'B has 25% width');
333 cmp_float($nodes->[1]->{percent}, 0.75, 'A has 75% width');
335 exit_gracefully($pid);
337 ###############################################################################
338 # Swapping containers not sharing the same parent preserves the geometry of
339 # the container they are swapped with.
358 ###############################################################################
359 $pid = launch_with_config($config);
360 $ws = fresh_workspace;
362 $A = open_window(wm_class => 'mark_A');
363 $B = open_window(wm_class => 'mark_B');
366 cmd 'focus up, resize grow height 0 or 25 ppt';
367 cmd 'focus left, split v';
369 cmd 'resize grow height 0 or 25 ppt';
372 $nodes = get_ws_content($ws);
373 cmp_float($nodes->[0]->{nodes}->[0]->{percent}, 0.25, 'A has 25% height');
374 cmp_float($nodes->[1]->{nodes}->[0]->{percent}, 0.75, 'B has 75% height');
376 cmd '[con_mark=B] swap container with mark A';
378 $nodes = get_ws_content($ws);
379 cmp_float($nodes->[0]->{nodes}->[0]->{percent}, 0.25, 'B has 25% height');
380 cmp_float($nodes->[1]->{nodes}->[0]->{percent}, 0.75, 'A has 75% height');
382 exit_gracefully($pid);
384 ###############################################################################
385 # Swapping containers moves the urgency hint correctly.
386 ###############################################################################
387 $pid = launch_with_config($config);
389 $ws1 = fresh_workspace;
390 $A = open_window(wm_class => 'mark_A');
391 $ws2 = fresh_workspace;
392 $B = open_window(wm_class => 'mark_B');
395 $B->add_hint('urgency');
398 cmd '[con_mark=B] swap container with mark A';
400 @urgent = grep { $_->{urgent} } @{get_ws_content($ws1)};
401 is(@urgent, 1, 'B is marked urgent');
402 is(get_ws($ws1)->{urgent}, 1, 'the first workspace is marked urgent');
404 @urgent = grep { $_->{urgent} } @{get_ws_content($ws2)};
405 is(@urgent, 0, 'A is not marked urgent');
406 is(get_ws($ws2)->{urgent}, 0, 'the second workspace is not marked urgent');
408 exit_gracefully($pid);
410 ###############################################################################