]> git.sur5r.net Git - i3/i3/blob - testcases/t/141-resize.t
0e7fd526b75e9d450a532c92cfad26268d621d3d
[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 # Check that the resize grow/shrink width/height syntax works if a nested split
146 # was set on the container, but no sibling has been opened yet. See #2015.
147 ################################################################################
148
149 $tmp = fresh_workspace;
150 $left = open_window;
151 $right = open_window;
152
153 cmd 'split h';
154 cmd 'resize grow width 10px or 25 ppt';
155
156 ($nodes, $focus) = get_ws_content($tmp);
157 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
158 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
159
160 ############################################################
161 # checks that resizing floating windows works
162 ############################################################
163
164 $tmp = fresh_workspace;
165
166 $top = open_window;
167
168 cmd 'floating enable';
169
170 my @content = @{get_ws($tmp)->{floating_nodes}};
171 cmp_ok(@content, '==', 1, 'one floating node on this ws');
172
173 # up
174 my $oldrect = $content[0]->{rect};
175
176 cmd 'resize grow up 10 px or 25 ppt';
177
178 @content = @{get_ws($tmp)->{floating_nodes}};
179 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
180 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 10, 'y exactly 10 px smaller');
181 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
182 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
183 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 10, 'height exactly 10 px higher');
184 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
185
186 # up, but with a different amount of px
187 $oldrect = $content[0]->{rect};
188
189 cmd 'resize grow up 12 px or 25 ppt';
190
191 @content = @{get_ws($tmp)->{floating_nodes}};
192 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
193 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 12, 'y exactly 10 px smaller');
194 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
195 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
196 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 12, 'height exactly 10 px higher');
197 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
198
199 # left
200 $oldrect = $content[0]->{rect};
201
202 cmd 'resize grow left 10 px or 25 ppt';
203
204 @content = @{get_ws($tmp)->{floating_nodes}};
205 cmp_ok($content[0]->{rect}->{x}, '<', $oldrect->{x}, 'x smaller than before');
206 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
207
208 # right
209 $oldrect = $content[0]->{rect};
210
211 cmd 'resize grow right 10 px or 25 ppt';
212
213 @content = @{get_ws($tmp)->{floating_nodes}};
214 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
215 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
216 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
217 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
218
219 # down
220 $oldrect = $content[0]->{rect};
221
222 cmd 'resize grow down 10 px or 25 ppt';
223
224 @content = @{get_ws($tmp)->{floating_nodes}};
225 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
226 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
227 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
228 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
229
230 # grow width
231 $oldrect = $content[0]->{rect};
232
233 cmd 'resize grow width 10px or 10ppt';
234
235 @content = @{get_ws($tmp)->{floating_nodes}};
236 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
237 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
238 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
239 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
240
241 # shrink width
242 $oldrect = $content[0]->{rect};
243
244 cmd 'resize shrink width 10px or 10ppt';
245
246 @content = @{get_ws($tmp)->{floating_nodes}};
247 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
248 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
249 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
250 cmp_ok($content[0]->{rect}->{width}, '<', $oldrect->{width}, 'width smaller than before');
251
252 # grow height
253 $oldrect = $content[0]->{rect};
254
255 cmd 'resize grow height 10px or 10ppt';
256
257 @content = @{get_ws($tmp)->{floating_nodes}};
258 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
259 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
260 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
261 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
262
263 # shrink height
264 $oldrect = $content[0]->{rect};
265
266 cmd 'resize shrink height 10px or 10ppt';
267
268 @content = @{get_ws($tmp)->{floating_nodes}};
269 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
270 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
271 cmp_ok($content[0]->{rect}->{height}, '<', $oldrect->{height}, 'height smaller than before');
272 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
273
274 ################################################################################
275 # Check that resizing with criteria works
276 ################################################################################
277
278 $tmp = fresh_workspace;
279
280 $left = open_floating_window;
281 $right = open_floating_window;
282
283 sub get_floating_rect {
284     my ($window_id) = @_;
285
286     my $floating_nodes = get_ws($tmp)->{floating_nodes};
287     for my $floating_node (@$floating_nodes) {
288         # Get all the windows within that floating container
289         my @window_ids = map { $_->{window} } @{$floating_node->{nodes}};
290         if ($window_id ~~ @window_ids) {
291             return $floating_node->{rect};
292         }
293     }
294
295     return undef;
296 }
297
298 # focus is on the right window, so we resize the left one using criteria
299 my $leftold = get_floating_rect($left->id);
300 my $rightold = get_floating_rect($right->id);
301 cmd '[id="' . $left->id . '"] resize grow height 10px or 10ppt';
302
303 my $leftnew = get_floating_rect($left->id);
304 my $rightnew = get_floating_rect($right->id);
305 is($rightnew->{height}, $rightold->{height}, 'height of right container unchanged');
306 is($leftnew->{height}, $leftold->{height} + 10, 'height of left container changed');
307
308 done_testing;