2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://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 resizing tiling containers
21 my $tmp = fresh_workspace;
25 my $top = open_window;
26 my $bottom = open_window;
28 diag("top = " . $top->id . ", bottom = " . $bottom->id);
30 is($x->input_focus, $bottom->id, 'Bottom window focused');
32 ############################################################
34 ############################################################
36 cmd 'resize grow up 10 px or 25 ppt';
38 my ($nodes, $focus) = get_ws_content($tmp);
40 cmp_float($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
41 cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
44 ############################################################
45 # split and check if the 'percent' factor is still correct
46 ############################################################
50 ($nodes, $focus) = get_ws_content($tmp);
52 cmp_float($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
53 cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
55 ############################################################
56 # checks that resizing within stacked/tabbed cons works
57 ############################################################
59 $tmp = fresh_workspace;
64 $bottom = open_window;
69 ($nodes, $focus) = get_ws_content($tmp);
70 cmp_float($nodes->[0]->{percent}, 0.5, 'top window got 50%');
71 cmp_float($nodes->[1]->{percent}, 0.5, 'bottom window got 50%');
73 cmd 'resize grow up 10 px or 25 ppt';
75 ($nodes, $focus) = get_ws_content($tmp);
76 cmp_float($nodes->[0]->{percent}, 0.25, 'top window got 25%');
77 cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
79 ############################################################
80 # Checks that resizing in the parent's parent's orientation works.
81 # Take for example a horizontal workspace with one window on the left side and
82 # a v-split container with two windows on the right side. Focus is on the
83 # bottom right window, use 'resize left'.
84 ############################################################
86 $tmp = fresh_workspace;
94 $bottom = open_window;
96 ($nodes, $focus) = get_ws_content($tmp);
97 cmp_float($nodes->[0]->{percent}, 0.5, 'left window got 50%');
98 cmp_float($nodes->[1]->{percent}, 0.5, 'right window got 50%');
100 cmd 'resize grow left 10 px or 25 ppt';
102 ($nodes, $focus) = get_ws_content($tmp);
103 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
104 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
106 ################################################################################
107 # Check that the resize grow/shrink width/height syntax works.
108 ################################################################################
111 $tmp = fresh_workspace;
114 $right = open_window;
116 cmd 'resize grow width 10 px or 25 ppt';
118 ($nodes, $focus) = get_ws_content($tmp);
119 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
120 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
122 # Now test it with four windows
123 $tmp = fresh_workspace;
125 open_window for (1..4);
127 cmd 'resize grow width 10 px or 25 ppt';
129 ($nodes, $focus) = get_ws_content($tmp);
130 cmp_float($nodes->[0]->{percent}, 0.166666666666667, 'first window got 16%');
131 cmp_float($nodes->[1]->{percent}, 0.166666666666667, 'second window got 16%');
132 cmp_float($nodes->[2]->{percent}, 0.166666666666667, 'third window got 16%');
133 cmp_float($nodes->[3]->{percent}, 0.50, 'fourth window got 50%');
135 # height should be a no-op in this situation
136 cmd 'resize grow height 10 px or 25 ppt';
138 ($nodes, $focus) = get_ws_content($tmp);
139 cmp_float($nodes->[0]->{percent}, 0.166666666666667, 'first window got 16%');
140 cmp_float($nodes->[1]->{percent}, 0.166666666666667, 'second window got 16%');
141 cmp_float($nodes->[2]->{percent}, 0.166666666666667, 'third window got 16%');
142 cmp_float($nodes->[3]->{percent}, 0.50, 'fourth window got 50%');
144 ################################################################################
145 # Same but using pixels instead of ppt.
146 ################################################################################
149 $tmp = fresh_workspace;
152 $right = open_window;
154 ($nodes, $focus) = get_ws_content($tmp);
155 my @widths = ($nodes->[0]->{rect}->{width}, $nodes->[1]->{rect}->{width});
157 cmd 'resize grow width 10 px';
159 ($nodes, $focus) = get_ws_content($tmp);
160 cmp_float($nodes->[0]->{rect}->{width}, $widths[0] - 10, 'left window is 10px smaller');
161 cmp_float($nodes->[1]->{rect}->{width}, $widths[1] + 10, 'right window is 10px larger');
163 # Now test it with four windows
164 $tmp = fresh_workspace;
166 open_window for (1..4);
168 ($nodes, $focus) = get_ws_content($tmp);
169 my $width = $nodes->[0]->{rect}->{width};
171 cmd 'resize grow width 10 px';
173 ($nodes, $focus) = get_ws_content($tmp);
174 cmp_float($nodes->[3]->{rect}->{width}, $width + 10, 'last window is 10px larger');
176 ################################################################################
177 # Same but for height
178 ################################################################################
181 $tmp = fresh_workspace;
185 $right = open_window;
187 ($nodes, $focus) = get_ws_content($tmp);
188 my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});
190 cmd 'resize grow height 10 px';
192 ($nodes, $focus) = get_ws_content($tmp);
193 cmp_float($nodes->[0]->{rect}->{height}, $heights[0] - 10, 'left window is 10px smaller');
194 cmp_float($nodes->[1]->{rect}->{height}, $heights[1] + 10, 'right window is 10px larger');
196 # Now test it with four windows
197 $tmp = fresh_workspace;
200 open_window for (1..4);
202 ($nodes, $focus) = get_ws_content($tmp);
203 my $height = $nodes->[0]->{rect}->{height};
205 cmd 'resize grow height 10 px';
207 ($nodes, $focus) = get_ws_content($tmp);
208 cmp_float($nodes->[3]->{rect}->{height}, $height + 10, 'last window is 10px larger');
210 ################################################################################
211 # Check that we can grow tiled windows by pixels
212 ################################################################################
214 $tmp = fresh_workspace;
217 $right = open_window;
219 ($nodes, $focus) = get_ws_content($tmp);
220 cmp_float($nodes->[0]->{rect}->{width}, 640, 'left window is 640px');
221 cmp_float($nodes->[1]->{rect}->{width}, 640, 'right window is 640px');
223 cmd 'resize grow left 10px';
224 ($nodes, $focus) = get_ws_content($tmp);
225 cmp_float($nodes->[0]->{rect}->{width}, 630, 'left window is 630px');
226 cmp_float($nodes->[1]->{rect}->{width}, 650, 'right window is 650px');
228 ################################################################################
229 # Check that we can shrink tiled windows by pixels
230 ################################################################################
232 $tmp = fresh_workspace;
235 $right = open_window;
237 ($nodes, $focus) = get_ws_content($tmp);
238 cmp_float($nodes->[0]->{rect}->{width}, 640, 'left window is 640px');
239 cmp_float($nodes->[1]->{rect}->{width}, 640, 'right window is 640px');
241 cmd 'resize shrink left 10px';
242 ($nodes, $focus) = get_ws_content($tmp);
243 cmp_float($nodes->[0]->{rect}->{width}, 650, 'left window is 650px');
244 cmp_float($nodes->[1]->{rect}->{width}, 630, 'right window is 630px');
247 ################################################################################
248 # Check that we can shrink vertical tiled windows by pixels
249 ################################################################################
251 $tmp = fresh_workspace;
256 $bottom = open_window;
258 ($nodes, $focus) = get_ws_content($tmp);
259 my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});
261 cmd 'resize grow up 10px';
262 ($nodes, $focus) = get_ws_content($tmp);
263 cmp_float($nodes->[0]->{rect}->{height}, $heights[0] - 10, 'top window is 10px larger');
264 cmp_float($nodes->[1]->{rect}->{height}, $heights[1] + 10, 'bottom window is 10px smaller');
266 ################################################################################
267 # Check that we can shrink vertical tiled windows by pixels
268 ################################################################################
270 $tmp = fresh_workspace;
275 $bottom = open_window;
277 ($nodes, $focus) = get_ws_content($tmp);
278 my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});
280 cmd 'resize shrink up 10px';
281 ($nodes, $focus) = get_ws_content($tmp);
282 cmp_float($nodes->[0]->{rect}->{height}, $heights[0] + 10, 'top window is 10px smaller');
283 cmp_float($nodes->[1]->{rect}->{height}, $heights[1] - 10, 'bottom window is 10px larger');
285 ################################################################################
286 # Check that the resize grow/shrink width/height syntax works if a nested split
287 # was set on the container, but no sibling has been opened yet. See #2015.
288 ################################################################################
290 $tmp = fresh_workspace;
292 $right = open_window;
295 cmd 'resize grow width 10px or 25 ppt';
297 ($nodes, $focus) = get_ws_content($tmp);
298 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
299 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
301 ############################################################
302 # checks that resizing floating windows works
303 ############################################################
305 $tmp = fresh_workspace;
309 cmd 'floating enable';
311 my @content = @{get_ws($tmp)->{floating_nodes}};
312 cmp_ok(@content, '==', 1, 'one floating node on this ws');
315 my $oldrect = $content[0]->{rect};
317 cmd 'resize grow up 10 px or 25 ppt';
319 @content = @{get_ws($tmp)->{floating_nodes}};
320 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
321 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 10, 'y exactly 10 px smaller');
322 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
323 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
324 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 10, 'height exactly 10 px higher');
325 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
327 # up, but with a different amount of px
328 $oldrect = $content[0]->{rect};
330 cmd 'resize grow up 12 px or 25 ppt';
332 @content = @{get_ws($tmp)->{floating_nodes}};
333 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
334 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 12, 'y exactly 10 px smaller');
335 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
336 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
337 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 12, 'height exactly 10 px higher');
338 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
341 $oldrect = $content[0]->{rect};
343 cmd 'resize grow left 10 px or 25 ppt';
345 @content = @{get_ws($tmp)->{floating_nodes}};
346 cmp_ok($content[0]->{rect}->{x}, '<', $oldrect->{x}, 'x smaller than before');
347 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
350 $oldrect = $content[0]->{rect};
352 cmd 'resize grow right 10 px or 25 ppt';
354 @content = @{get_ws($tmp)->{floating_nodes}};
355 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
356 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
357 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
358 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
361 $oldrect = $content[0]->{rect};
363 cmd 'resize grow down 10 px or 25 ppt';
365 @content = @{get_ws($tmp)->{floating_nodes}};
366 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
367 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
368 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
369 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
372 $oldrect = $content[0]->{rect};
374 cmd 'resize grow width 10px or 10ppt';
376 @content = @{get_ws($tmp)->{floating_nodes}};
377 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
378 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
379 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
380 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
383 $oldrect = $content[0]->{rect};
385 cmd 'resize shrink width 10px or 10ppt';
387 @content = @{get_ws($tmp)->{floating_nodes}};
388 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
389 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
390 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
391 cmp_ok($content[0]->{rect}->{width}, '<', $oldrect->{width}, 'width smaller than before');
394 $oldrect = $content[0]->{rect};
396 cmd 'resize grow height 10px or 10ppt';
398 @content = @{get_ws($tmp)->{floating_nodes}};
399 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
400 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
401 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
402 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
405 $oldrect = $content[0]->{rect};
407 cmd 'resize shrink height 10px or 10ppt';
409 @content = @{get_ws($tmp)->{floating_nodes}};
410 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
411 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
412 cmp_ok($content[0]->{rect}->{height}, '<', $oldrect->{height}, 'height smaller than before');
413 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
415 ################################################################################
416 # Check that resizing with criteria works
417 ################################################################################
419 $tmp = fresh_workspace;
421 $left = open_floating_window;
422 $right = open_floating_window;
424 sub get_floating_rect {
425 my ($window_id) = @_;
427 my $floating_nodes = get_ws($tmp)->{floating_nodes};
428 for my $floating_node (@$floating_nodes) {
429 # Get all the windows within that floating container
430 my @window_ids = map { $_->{window} } @{$floating_node->{nodes}};
431 if ($window_id ~~ @window_ids) {
432 return $floating_node->{rect};
439 # focus is on the right window, so we resize the left one using criteria
440 my $leftold = get_floating_rect($left->id);
441 my $rightold = get_floating_rect($right->id);
442 cmd '[id="' . $left->id . '"] resize grow height 10px or 10ppt';
444 my $leftnew = get_floating_rect($left->id);
445 my $rightnew = get_floating_rect($right->id);
446 is($rightnew->{height}, $rightold->{height}, 'height of right container unchanged');
447 is($leftnew->{height}, $leftold->{height} + 10, 'height of left container changed');