]> 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 # Tests resizing tiling containers
4 use i3test;
5
6 my $tmp = fresh_workspace;
7
8 cmd 'split v';
9
10 my $top = open_window;
11 my $bottom = open_window;
12
13 diag("top = " . $top->id . ", bottom = " . $bottom->id);
14
15 is($x->input_focus, $bottom->id, 'Bottom window focused');
16
17 ############################################################
18 # resize
19 ############################################################
20
21 cmd 'resize grow up 10 px or 25 ppt';
22
23 my ($nodes, $focus) = get_ws_content($tmp);
24
25 ok(cmp_float($nodes->[0]->{percent}, 0.25), 'top window got only 25%');
26 ok(cmp_float($nodes->[1]->{percent}, 0.75), 'bottom window got 75%');
27
28
29 ############################################################
30 # split and check if the 'percent' factor is still correct
31 ############################################################
32
33 cmd 'split h';
34
35 ($nodes, $focus) = get_ws_content($tmp);
36
37 ok(cmp_float($nodes->[0]->{percent}, 0.25), 'top window got only 25%');
38 ok(cmp_float($nodes->[1]->{percent}, 0.75), 'bottom window got 75%');
39
40 ############################################################
41 # checks that resizing within stacked/tabbed cons works
42 ############################################################
43
44 $tmp = fresh_workspace;
45
46 cmd 'split v';
47
48 $top = open_window;
49 $bottom = open_window;
50
51 cmd 'split h';
52 cmd 'layout stacked';
53
54 ($nodes, $focus) = get_ws_content($tmp);
55 ok(cmp_float($nodes->[0]->{percent}, 0.5), 'top window got 50%');
56 ok(cmp_float($nodes->[1]->{percent}, 0.5), 'bottom window got 50%');
57
58 cmd 'resize grow up 10 px or 25 ppt';
59
60 ($nodes, $focus) = get_ws_content($tmp);
61 ok(cmp_float($nodes->[0]->{percent}, 0.25), 'top window got 25%');
62 ok(cmp_float($nodes->[1]->{percent}, 0.75), 'bottom window got 75%');
63
64 ############################################################
65 # Checks that resizing in the parent's parent's orientation works.
66 # Take for example a horizontal workspace with one window on the left side and
67 # a v-split container with two windows on the right side. Focus is on the
68 # bottom right window, use 'resize left'.
69 ############################################################
70
71 $tmp = fresh_workspace;
72
73 my $left = open_window;
74 my $right = open_window;
75
76 cmd 'split v';
77
78 $top = open_window;
79 $bottom = open_window;
80
81 ($nodes, $focus) = get_ws_content($tmp);
82 ok(cmp_float($nodes->[0]->{percent}, 0.5), 'left window got 50%');
83 ok(cmp_float($nodes->[1]->{percent}, 0.5), 'right window got 50%');
84
85 cmd 'resize grow left 10 px or 25 ppt';
86
87 ($nodes, $focus) = get_ws_content($tmp);
88 ok(cmp_float($nodes->[0]->{percent}, 0.25), 'left window got 25%');
89 ok(cmp_float($nodes->[1]->{percent}, 0.75), 'right window got 75%');
90
91 ################################################################################
92 # Check that the resize grow/shrink width/height syntax works.
93 ################################################################################
94
95 # Use two windows
96 $tmp = fresh_workspace;
97
98 $left = open_window;
99 $right = open_window;
100
101 cmd 'resize grow width 10 px or 25 ppt';
102
103 ($nodes, $focus) = get_ws_content($tmp);
104 ok(cmp_float($nodes->[0]->{percent}, 0.25), 'left window got 25%');
105 ok(cmp_float($nodes->[1]->{percent}, 0.75), 'right window got 75%');
106
107 # Now test it with four windows
108 $tmp = fresh_workspace;
109
110 open_window for (1..4);
111
112 cmd 'resize grow width 10 px or 25 ppt';
113
114 ($nodes, $focus) = get_ws_content($tmp);
115 ok(cmp_float($nodes->[0]->{percent}, 0.166666666666667), 'first window got 16%');
116 ok(cmp_float($nodes->[1]->{percent}, 0.166666666666667), 'second window got 16%');
117 ok(cmp_float($nodes->[2]->{percent}, 0.166666666666667), 'third window got 16%');
118 ok(cmp_float($nodes->[3]->{percent}, 0.50), 'fourth window got 50%');
119
120 # height should be a no-op in this situation
121 cmd 'resize grow height 10 px or 25 ppt';
122
123 ($nodes, $focus) = get_ws_content($tmp);
124 ok(cmp_float($nodes->[0]->{percent}, 0.166666666666667), 'first window got 16%');
125 ok(cmp_float($nodes->[1]->{percent}, 0.166666666666667), 'second window got 16%');
126 ok(cmp_float($nodes->[2]->{percent}, 0.166666666666667), 'third window got 16%');
127 ok(cmp_float($nodes->[3]->{percent}, 0.50), 'fourth window got 50%');
128
129
130 ############################################################
131 # checks that resizing floating windows works
132 ############################################################
133
134 $tmp = fresh_workspace;
135
136 $top = open_window;
137
138 cmd 'floating enable';
139
140 my @content = @{get_ws($tmp)->{floating_nodes}};
141 cmp_ok(@content, '==', 1, 'one floating node on this ws');
142
143 # up
144 my $oldrect = $content[0]->{rect};
145
146 cmd 'resize grow up 10 px or 25 ppt';
147
148 @content = @{get_ws($tmp)->{floating_nodes}};
149 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
150 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 10, 'y exactly 10 px smaller');
151 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
152 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
153 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 10, 'height exactly 10 px higher');
154 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
155
156 # up, but with a different amount of px
157 $oldrect = $content[0]->{rect};
158
159 cmd 'resize grow up 12 px or 25 ppt';
160
161 @content = @{get_ws($tmp)->{floating_nodes}};
162 cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
163 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 12, 'y exactly 10 px smaller');
164 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
165 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
166 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 12, 'height exactly 10 px higher');
167 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');
168
169 # left
170 $oldrect = $content[0]->{rect};
171
172 cmd 'resize grow left 10 px or 25 ppt';
173
174 @content = @{get_ws($tmp)->{floating_nodes}};
175 cmp_ok($content[0]->{rect}->{x}, '<', $oldrect->{x}, 'x smaller than before');
176 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
177
178 # right
179 $oldrect = $content[0]->{rect};
180
181 cmd 'resize grow right 10 px or 25 ppt';
182
183 @content = @{get_ws($tmp)->{floating_nodes}};
184 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
185 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
186 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
187 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
188
189 # down
190 $oldrect = $content[0]->{rect};
191
192 cmd 'resize grow down 10 px or 25 ppt';
193
194 @content = @{get_ws($tmp)->{floating_nodes}};
195 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
196 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
197 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
198 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
199
200 # grow width
201 $oldrect = $content[0]->{rect};
202
203 cmd 'resize grow width 10px or 10ppt';
204
205 @content = @{get_ws($tmp)->{floating_nodes}};
206 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
207 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
208 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
209 cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
210
211 # shrink width
212 $oldrect = $content[0]->{rect};
213
214 cmd 'resize shrink width 10px or 10ppt';
215
216 @content = @{get_ws($tmp)->{floating_nodes}};
217 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
218 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
219 cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
220 cmp_ok($content[0]->{rect}->{width}, '<', $oldrect->{width}, 'width smaller than before');
221
222 # grow height
223 $oldrect = $content[0]->{rect};
224
225 cmd 'resize grow height 10px or 10ppt';
226
227 @content = @{get_ws($tmp)->{floating_nodes}};
228 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
229 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
230 cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
231 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
232
233 # shrink height
234 $oldrect = $content[0]->{rect};
235
236 cmd 'resize shrink height 10px or 10ppt';
237
238 @content = @{get_ws($tmp)->{floating_nodes}};
239 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
240 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
241 cmp_ok($content[0]->{rect}->{height}, '<', $oldrect->{height}, 'height smaller than before');
242 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
243
244 done_testing;