2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Tests the floating_{minimum,maximum}_size config options.
19 # Note that the minimum floating window size is already verified in
23 use i3test i3_autostart => 0;
24 use X11::XCB qw/PROP_MODE_REPLACE/;
26 ################################################################################
27 # 1: check floating_minimum_size (with non-default limits)
28 ################################################################################
32 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
34 # Test with different dimensions than the i3 default.
35 floating_minimum_size 60 x 40
38 my $pid = launch_with_config($config);
40 my $window = open_floating_window(rect => [ 0, 0, 20, 20 ]);
41 my $rect = $window->rect;
43 is($rect->{width}, 60, 'width = 60');
44 is($rect->{height}, 40, 'height = 40');
46 exit_gracefully($pid);
48 ################################################################################
49 # 2: check floating_minimum_size with -1 (unlimited)
50 ################################################################################
54 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
56 floating_minimum_size -1 x -1
59 $pid = launch_with_config($config);
62 $window = open_floating_window(rect => [ 0, 0, 50, 40 ]);
63 $rect = $window->rect;
65 is($rect->{width}, 50, 'width = 50');
66 is($rect->{height}, 40, 'height = 40');
68 exit_gracefully($pid);
70 ################################################################################
71 # 3: check floating_maximum_size
72 ################################################################################
76 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
78 # Test with different dimensions than the i3 default.
79 floating_maximum_size 100 x 100
82 $pid = launch_with_config($config);
84 $window = open_floating_window(rect => [ 0, 0, 150, 150 ]);
85 $rect = $window->rect;
87 is($rect->{width}, 100, 'width = 100');
88 is($rect->{height}, 100, 'height = 100');
90 exit_gracefully($pid);
92 # Test that the feature works at all (without explicit configuration) by
93 # opening a window which is bigger than the testsuite screen (1280x1024).
97 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
100 $pid = launch_with_config($config);
102 $window = open_floating_window(rect => [ 0, 0, 2048, 2048 ]);
103 $rect = $window->rect;
105 cmp_ok($rect->{width}, '<', 2048, 'width < 2048');
106 cmp_ok($rect->{height}, '<', 2048, 'height < 2048');
108 exit_gracefully($pid);
110 ################################################################################
111 # 4: check floating_maximum_size
112 ################################################################################
115 # i3 config file (v4)
116 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
118 # Test with different dimensions than the i3 default.
119 floating_maximum_size -1 x -1
122 $pid = launch_with_config($config);
124 $window = open_floating_window(rect => [ 0, 0, 2048, 2048 ]);
125 $rect = $window->rect;
127 is($rect->{width}, 2048, 'width = 2048');
128 is($rect->{height}, 2048, 'height = 2048');
130 exit_gracefully($pid);
132 ################################################################################
133 # 5: check floating_minimum_size with cmd_resize
134 ################################################################################
137 # i3 config file (v4)
138 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
140 # Test with different dimensions than the i3 default.
141 floating_minimum_size 60 x 50
144 $pid = launch_with_config($config);
146 $window = open_floating_window(rect => [ 0, 0, 100, 100 ]);
148 cmd 'resize shrink height 80px or 80ppt';
149 cmd 'resize shrink width 80px or 80ppt';
151 $rect = $window->rect;
152 is($rect->{width}, 60, 'width = 60');
153 is($rect->{height}, 50, 'height = 50');
155 exit_gracefully($pid);
157 ################################################################################
158 # 6: check floating_maximum_size with cmd_resize
159 ################################################################################
162 # i3 config file (v4)
163 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
165 # Test with different dimensions than the i3 default.
166 floating_maximum_size 100 x 100
169 $pid = launch_with_config($config);
171 $window = open_floating_window(rect => [ 200, 200, 50, 50 ]);
173 cmd 'resize grow height 100px or 100ppt';
174 cmd 'resize grow width 100px or 100ppt';
176 $rect = $window->rect;
177 is($rect->{width}, 100, 'width = 100');
178 is($rect->{height}, 100, 'height = 100');
180 my $old_x = $rect->{x};
181 my $old_y = $rect->{y};
182 cmd 'resize grow up 10px or 10ppt';
184 $rect = $window->rect;
185 is($rect->{x}, $old_x, 'window did not move when trying to resize');
186 is($rect->{y}, $old_y, 'window did not move when trying to resize');
188 exit_gracefully($pid);
190 ################################################################################
191 # 7: check floating_maximum_size with cmd_size
192 ################################################################################
195 # i3 config file (v4)
196 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
198 # Test with different dimensions than the i3 default.
199 floating_minimum_size 80 x 70
200 floating_maximum_size 100 x 90
203 $pid = launch_with_config($config);
205 $window = open_floating_window(rect => [ 0, 0, 90, 80 ]);
208 cmd 'resize set 101 91';
210 $rect = $window->rect;
211 is($rect->{width}, 100, 'width did not exceed maximum width');
212 is($rect->{height}, 90, 'height did not exceed maximum height');
214 cmd 'resize set 79 69';
216 $rect = $window->rect;
217 is($rect->{width}, 80, 'width did not exceed minimum width');
218 is($rect->{height}, 70, 'height did not exceed minimum height');
220 exit_gracefully($pid);
222 ################################################################################
223 # 8: check minimum_size and maximum_size set by WM_NORMAL_HINTS
224 ################################################################################
227 # i3 config file (v4)
228 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
232 my $min_height = 100;
234 my $max_height = 200;
236 my sub open_with_max_size {
237 # The type of the WM_NORMAL_HINTS property is WM_SIZE_HINTS
238 # https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.2.3
239 my $XCB_ICCCM_SIZE_HINT_P_MIN_SIZE = 0x32;
240 my $XCB_ICCCM_SIZE_HINT_P_MAX_SIZE = 0x16;
242 my $flags = $XCB_ICCCM_SIZE_HINT_P_MIN_SIZE | $XCB_ICCCM_SIZE_HINT_P_MAX_SIZE;
246 my $window = open_window(
250 my $atomname = $x->atom(name => 'WM_NORMAL_HINTS');
251 my $atomtype = $x->atom(name => 'WM_SIZE_HINTS');
259 pack('C5N8', $flags, $pad, $pad, $pad, $pad, 0, 0, 0, $min_width, $min_height, $max_width, $max_height),
267 my sub check_minsize {
269 is($window->rect->{width}, $min_width, 'width = min_width');
270 is($window->rect->{height}, $min_height, 'height = min_height');
273 my sub check_maxsize {
275 is($window->rect->{width}, $max_width, 'width = max_width');
276 is($window->rect->{height}, $max_height, 'height = max_height');
279 $pid = launch_with_config($config);
281 $window = open_with_max_size;
282 cmd 'floating enable';
285 cmd "resize set $min_width px $min_height px";
288 # Try to resize below minimum width
289 cmd 'resize set ' . ($min_width - 10) . ' px ' . ($min_height - 50) . ' px';
292 cmd "resize set $max_width px $max_height px";
295 # Try to resize above maximum width
296 cmd 'resize set ' . ($max_width + 150) . ' px ' . ($max_height + 500) . ' px';
299 exit_gracefully($pid);