]> git.sur5r.net Git - i3/i3/blob - testcases/t/541-resize-set-tiling.t
0298fecd31692b783f23f431145c57479d451455
[i3/i3] / testcases / t / 541-resize-set-tiling.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 ############################################################
21 # resize horizontally
22 ############################################################
23
24 my $tmp = fresh_workspace;
25
26 cmd 'split h';
27
28 my $left = open_window;
29 my $right = open_window;
30
31 diag("left = " . $left->id . ", right = " . $right->id);
32
33 is($x->input_focus, $right->id, 'Right window focused');
34
35 cmd 'resize set 75 ppt 0 ppt';
36
37 my ($nodes, $focus) = get_ws_content($tmp);
38
39 cmp_float($nodes->[0]->{percent}, 0.25, 'left window got only 25%');
40 cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');
41
42 # Same but use the 'width' keyword.
43 cmd 'resize set width 80 ppt';
44
45 ($nodes, $focus) = get_ws_content($tmp);
46
47 cmp_float($nodes->[0]->{percent}, 0.20, 'left window got 20%');
48 cmp_float($nodes->[1]->{percent}, 0.80, 'right window got 80%');
49
50 # Same but with px.
51 cmd 'resize set width 200 px';
52
53 ($nodes, $focus) = get_ws_content($tmp);
54
55 cmp_float($nodes->[1]->{rect}->{width}, 200, 'right window got 200 px');
56
57 ############################################################
58 # resize vertically
59 ############################################################
60
61 $tmp = fresh_workspace;
62
63 cmd 'split v';
64
65 my $top = open_window;
66 my $bottom = open_window;
67
68 diag("top = " . $top->id . ", bottom = " . $bottom->id);
69
70 is($x->input_focus, $bottom->id, 'Bottom window focused');
71
72 cmd 'resize set 0 ppt 75 ppt';
73
74 ($nodes, $focus) = get_ws_content($tmp);
75
76 cmp_float($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
77 cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
78
79 # Same but use the 'height' keyword.
80 cmd 'resize set height 80 ppt';
81
82 ($nodes, $focus) = get_ws_content($tmp);
83
84 cmp_float($nodes->[0]->{percent}, 0.20, 'top window got 20%');
85 cmp_float($nodes->[1]->{percent}, 0.80, 'bottom window got 80%');
86
87 # Same but with px.
88 cmd 'resize set height 200 px';
89
90 ($nodes, $focus) = get_ws_content($tmp);
91
92 cmp_float($nodes->[1]->{rect}->{height}, 200, 'bottom window got 200 px');
93
94 ############################################################
95 # resize horizontally and vertically
96 ############################################################
97
98 $tmp = fresh_workspace;
99
100 cmd 'split h';
101 $left = open_window;
102 my $top_right = open_window;
103 cmd 'split v';
104 my $bottom_right = open_window;
105
106 diag("left = " . $left->id . ", top-right = " . $top_right->id . ", bottom-right = " . $bottom_right->id);
107
108 is($x->input_focus, $bottom_right->id, 'Bottom-right window focused');
109
110 cmd 'resize set 75 ppt 75 ppt';
111
112 ($nodes, $focus) = get_ws_content($tmp);
113
114 cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
115 cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
116 cmp_float($nodes->[1]->{nodes}->[0]->{percent}, 0.25, 'top-right window got 25%');
117 cmp_float($nodes->[1]->{nodes}->[1]->{percent}, 0.75, 'bottom-right window got 75%');
118
119 # Same but with px.
120 cmd 'resize set 155 px 135 px';
121
122 ($nodes, $focus) = get_ws_content($tmp);
123
124 cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{width}, 155, 'bottom-right window got 155 px width');
125 cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{height}, 135, 'bottom-right window got 135 px height');
126
127 # Without specifying mode
128 cmd 'resize set 201 131';
129
130 ($nodes, $focus) = get_ws_content($tmp);
131
132 cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{width}, 201, 'bottom-right window got 201 px width');
133 cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{height}, 131, 'bottom-right window got 131 px height');
134
135 # Mix ppt and px
136 cmd 'resize set 75 ppt 200 px';
137
138 ($nodes, $focus) = get_ws_content($tmp);
139
140 cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
141 cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
142 cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{height}, 200, 'bottom-right window got 200 px height');
143
144 ############################################################
145 # resize from inside a tabbed container
146 ############################################################
147
148 $tmp = fresh_workspace;
149
150 cmd 'split h';
151
152 $left = open_window;
153 my $right1 = open_window;
154
155 cmd 'split h';
156 cmd 'layout tabbed';
157
158 my $right2 = open_window;
159
160 diag("left = " . $left->id . ", right1 = " . $right1->id . ", right2 = " . $right2->id);
161
162 is($x->input_focus, $right2->id, '2nd right window focused');
163
164 cmd 'resize set 75 ppt 0 ppt';
165
166 ($nodes, $focus) = get_ws_content($tmp);
167
168 cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
169 cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
170
171 # Same but with px.
172 cmd 'resize set 155 px';
173
174 ($nodes, $focus) = get_ws_content($tmp);
175
176 cmp_float($nodes->[1]->{rect}->{width}, 155, 'right container got 155 px');
177
178 ############################################################
179 # resize from inside a stacked container
180 ############################################################
181
182 $tmp = fresh_workspace;
183
184 cmd 'split h';
185
186 $left = open_window;
187 $right1 = open_window;
188
189 cmd 'split h';
190 cmd 'layout stacked';
191
192 $right2 = open_window;
193
194 diag("left = " . $left->id . ", right1 = " . $right1->id . ", right2 = " . $right2->id);
195
196 is($x->input_focus, $right2->id, '2nd right window focused');
197
198 cmd 'resize set 75 ppt 0 ppt';
199
200 ($nodes, $focus) = get_ws_content($tmp);
201
202 cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
203 cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
204
205 # Same but with px.
206 cmd 'resize set 130 px';
207
208 ($nodes, $focus) = get_ws_content($tmp);
209
210 cmp_float($nodes->[1]->{rect}->{width}, 130, 'right container got 130 px');
211
212 done_testing;