]> git.sur5r.net Git - i3/i3/blob - testcases/t/541-resize-set-tiling.t
956622a2343014ba7a05e20027648cfece1d0954
[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 ############################################################
128 # resize from inside a tabbed container
129 ############################################################
130
131 $tmp = fresh_workspace;
132
133 cmd 'split h';
134
135 $left = open_window;
136 my $right1 = open_window;
137
138 cmd 'split h';
139 cmd 'layout tabbed';
140
141 my $right2 = open_window;
142
143 diag("left = " . $left->id . ", right1 = " . $right1->id . ", right2 = " . $right2->id);
144
145 is($x->input_focus, $right2->id, '2nd right window focused');
146
147 cmd 'resize set 75 ppt 0 ppt';
148
149 ($nodes, $focus) = get_ws_content($tmp);
150
151 cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
152 cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
153
154 # Same but with px.
155 cmd 'resize set 155 px';
156
157 ($nodes, $focus) = get_ws_content($tmp);
158
159 cmp_float($nodes->[1]->{rect}->{width}, 155, 'right container got 155 px');
160
161 ############################################################
162 # resize from inside a stacked container
163 ############################################################
164
165 $tmp = fresh_workspace;
166
167 cmd 'split h';
168
169 $left = open_window;
170 $right1 = open_window;
171
172 cmd 'split h';
173 cmd 'layout stacked';
174
175 $right2 = open_window;
176
177 diag("left = " . $left->id . ", right1 = " . $right1->id . ", right2 = " . $right2->id);
178
179 is($x->input_focus, $right2->id, '2nd right window focused');
180
181 cmd 'resize set 75 ppt 0 ppt';
182
183 ($nodes, $focus) = get_ws_content($tmp);
184
185 cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
186 cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
187
188 # Same but with px.
189 cmd 'resize set 130 px';
190
191 ($nodes, $focus) = get_ws_content($tmp);
192
193 cmp_float($nodes->[1]->{rect}->{width}, 130, 'right container got 130 px');
194
195 done_testing;