]> git.sur5r.net Git - i3/i3/blob - testcases/t/141-resize.t
5a264169c4367b9471cc34082592a62473a42465
[i3/i3] / testcases / t / 141-resize.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 resizing tiling containers
18 use i3test;
19
20 my ($left, $right);
21 my $tmp = fresh_workspace;
22
23 cmd 'split v';
24
25 my $top = open_window;
26 my $bottom = open_window;
27
28 diag("top = " . $top->id . ", bottom = " . $bottom->id);
29
30 is($x->input_focus, $bottom->id, 'Bottom window focused');
31
32 ############################################################
33 # resize
34 ############################################################
35
36 cmd 'resize grow up 10 px or 25 ppt';
37
38 my ($nodes, $focus) = get_ws_content($tmp);
39
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%');
42
43
44 ############################################################
45 # split and check if the 'percent' factor is still correct
46 ############################################################
47
48 cmd 'split h';
49
50 ($nodes, $focus) = get_ws_content($tmp);
51
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%');
54
55 ############################################################
56 # checks that resizing within stacked/tabbed cons works
57 ############################################################
58
59 $tmp = fresh_workspace;
60
61 cmd 'split v';
62
63 $top = open_window;
64 $bottom = open_window;
65
66 cmd 'split h';
67 cmd 'layout stacked';
68
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%');
72
73 cmd 'resize grow up 10 px or 25 ppt';
74
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%');
78
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 ############################################################
85
86 $tmp = fresh_workspace;
87
88 $left = open_window;
89 $right = open_window;
90
91 cmd 'split v';
92
93 $top = open_window;
94 $bottom = open_window;
95
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%');
99
100 cmd 'resize grow left 10 px or 25 ppt';
101
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%');
105
106 ################################################################################
107 # Check that the resize grow/shrink width/height syntax works.
108 ################################################################################
109
110 # Use two windows
111 $tmp = fresh_workspace;
112
113 $left = open_window;
114 $right = open_window;
115
116 cmd 'resize grow width 10 px or 25 ppt';
117
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%');
121
122 # Now test it with four windows
123 $tmp = fresh_workspace;
124
125 open_window for (1..4);
126
127 cmd 'resize grow width 10 px or 25 ppt';
128
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%');
134
135 # height should be a no-op in this situation
136 cmd 'resize grow height 10 px or 25 ppt';
137
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%');
143
144 ################################################################################
145 # Same but using pixels instead of ppt.
146 ################################################################################
147
148 # Use two windows
149 $tmp = fresh_workspace;
150
151 $left = open_window;
152 $right = open_window;
153
154 ($nodes, $focus) = get_ws_content($tmp);
155 my @widths = ($nodes->[0]->{rect}->{width}, $nodes->[1]->{rect}->{width});
156
157 cmd 'resize grow width 10 px';
158
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');
162
163 # Now test it with four windows
164 $tmp = fresh_workspace;
165
166 open_window for (1..4);
167
168 ($nodes, $focus) = get_ws_content($tmp);
169 my $width = $nodes->[0]->{rect}->{width};
170
171 cmd 'resize grow width 10 px';
172
173 ($nodes, $focus) = get_ws_content($tmp);
174 cmp_float($nodes->[3]->{rect}->{width}, $width + 10, 'last window is 10px larger');
175
176 ################################################################################
177 # Same but for height
178 ################################################################################
179
180 # Use two windows
181 $tmp = fresh_workspace;
182 cmd 'split v';
183
184 $left = open_window;
185 $right = open_window;
186
187 ($nodes, $focus) = get_ws_content($tmp);
188 my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});
189
190 cmd 'resize grow height 10 px';
191
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');
195
196 # Now test it with four windows
197 $tmp = fresh_workspace;
198 cmd 'split v';
199
200 open_window for (1..4);
201
202 ($nodes, $focus) = get_ws_content($tmp);
203 my $height = $nodes->[0]->{rect}->{height};
204
205 cmd 'resize grow height 10 px';
206
207 ($nodes, $focus) = get_ws_content($tmp);
208 cmp_float($nodes->[3]->{rect}->{height}, $height + 10, 'last window is 10px larger');
209
210 ################################################################################
211 # Check that we can grow tiled windows by pixels
212 ################################################################################
213
214 $tmp = fresh_workspace;
215
216 $left = open_window;
217 $right = open_window;
218
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');
222
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');
227
228 ################################################################################
229 # Check that we can shrink tiled windows by pixels
230 ################################################################################
231
232 $tmp = fresh_workspace;
233
234 $left = open_window;
235 $right = open_window;
236
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');
240
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');
245
246
247 ################################################################################
248 # Check that we can shrink vertical tiled windows by pixels
249 ################################################################################
250
251 $tmp = fresh_workspace;
252
253 cmd 'split v';
254
255 $top = open_window;
256 $bottom = open_window;
257
258 ($nodes, $focus) = get_ws_content($tmp);
259 my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});
260
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');
265
266 ################################################################################
267 # Check that we can shrink vertical tiled windows by pixels
268 ################################################################################
269
270 $tmp = fresh_workspace;
271
272 cmd 'split v';
273
274 $top = open_window;
275 $bottom = open_window;
276
277 ($nodes, $focus) = get_ws_content($tmp);
278 my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});
279
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');
284
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 ################################################################################
289
290 $tmp = fresh_workspace;
291 $left = open_window;
292 $right = open_window;
293
294 cmd 'split h';
295 cmd 'resize grow width 10px or 25 ppt';
296
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%');
300
301 ############################################################
302 # checks that resizing floating windows works
303 ############################################################
304
305 $tmp = fresh_workspace;
306
307 $top = open_window;
308
309 cmd 'floating enable';
310
311 my @content = @{get_ws($tmp)->{floating_nodes}};
312 cmp_ok(@content, '==', 1, 'one floating node on this ws');
313
314 # up
315 my $oldrect = $content[0]->{rect};
316
317 cmd 'resize grow up 10 px or 25 ppt';
318
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');
326
327 # up, but with a different amount of px
328 $oldrect = $content[0]->{rect};
329
330 cmd 'resize grow up 12 px or 25 ppt';
331
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');
339
340 # left
341 $oldrect = $content[0]->{rect};
342
343 cmd 'resize grow left 10 px or 25 ppt';
344
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');
348
349 # right
350 $oldrect = $content[0]->{rect};
351
352 cmd 'resize grow right 10 px or 25 ppt';
353
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');
359
360 # down
361 $oldrect = $content[0]->{rect};
362
363 cmd 'resize grow down 10 px or 25 ppt';
364
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');
370
371 # grow width
372 $oldrect = $content[0]->{rect};
373
374 cmd 'resize grow width 10px or 10ppt';
375
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');
381
382 # shrink width
383 $oldrect = $content[0]->{rect};
384
385 cmd 'resize shrink width 10px or 10ppt';
386
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');
392
393 # grow height
394 $oldrect = $content[0]->{rect};
395
396 cmd 'resize grow height 10px or 10ppt';
397
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');
403
404 # shrink height
405 $oldrect = $content[0]->{rect};
406
407 cmd 'resize shrink height 10px or 10ppt';
408
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');
414
415 ################################################################################
416 # Check that resizing with criteria works
417 ################################################################################
418
419 $tmp = fresh_workspace;
420
421 $left = open_floating_window;
422 $right = open_floating_window;
423
424 sub get_floating_rect {
425     my ($window_id) = @_;
426
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};
433         }
434     }
435
436     return undef;
437 }
438
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';
443
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');
448
449 done_testing;