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