]> git.sur5r.net Git - i3/i3/blob - testcases/t/189-floating-constraints.t
Fix flakyness in t/189-floating-constraints.t
[i3/i3] / testcases / t / 189-floating-constraints.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 the floating_{minimum,maximum}_size config options.
18 #
19 # Note that the minimum floating window size is already verified in
20 # t/005-floating.t.
21 #
22
23 use i3test i3_autostart => 0;
24 use X11::XCB qw/PROP_MODE_REPLACE/;
25
26 ################################################################################
27 # 1: check floating_minimum_size (with non-default limits)
28 ################################################################################
29
30 my $config = <<EOT;
31 # i3 config file (v4)
32 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
33
34 # Test with different dimensions than the i3 default.
35 floating_minimum_size 60 x 40
36 EOT
37
38 my $pid = launch_with_config($config);
39
40 my $window = open_floating_window(rect => [ 0, 0, 20, 20 ]);
41 my $rect = $window->rect;
42
43 is($rect->{width}, 60, 'width = 60');
44 is($rect->{height}, 40, 'height = 40');
45
46 exit_gracefully($pid);
47
48 ################################################################################
49 # 2: check floating_minimum_size with -1 (unlimited)
50 ################################################################################
51
52 $config = <<EOT;
53 # i3 config file (v4)
54 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
55
56 floating_minimum_size -1 x -1
57 EOT
58
59 $pid = launch_with_config($config);
60
61 cmd 'nop MEH';
62 $window = open_floating_window(rect => [ 0, 0, 50, 40 ]);
63 $rect = $window->rect;
64
65 is($rect->{width}, 50, 'width = 50');
66 is($rect->{height}, 40, 'height = 40');
67
68 exit_gracefully($pid);
69
70 ################################################################################
71 # 3: check floating_maximum_size
72 ################################################################################
73
74 $config = <<EOT;
75 # i3 config file (v4)
76 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
77
78 # Test with different dimensions than the i3 default.
79 floating_maximum_size 100 x 100
80 EOT
81
82 $pid = launch_with_config($config);
83
84 $window = open_floating_window(rect => [ 0, 0, 150, 150 ]);
85 $rect = $window->rect;
86
87 is($rect->{width}, 100, 'width = 100');
88 is($rect->{height}, 100, 'height = 100');
89
90 exit_gracefully($pid);
91
92 # Test that the feature works at all (without explicit configuration) by
93 # opening a window which is bigger than the testsuite screen (1280x1024).
94
95 $config = <<EOT;
96 # i3 config file (v4)
97 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
98 EOT
99
100 $pid = launch_with_config($config);
101
102 $window = open_floating_window(rect => [ 0, 0, 2048, 2048 ]);
103 $rect = $window->rect;
104
105 cmp_ok($rect->{width}, '<', 2048, 'width < 2048');
106 cmp_ok($rect->{height}, '<', 2048, 'height < 2048');
107
108 exit_gracefully($pid);
109
110 ################################################################################
111 # 4: check floating_maximum_size
112 ################################################################################
113
114 $config = <<EOT;
115 # i3 config file (v4)
116 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
117
118 # Test with different dimensions than the i3 default.
119 floating_maximum_size -1 x -1
120 EOT
121
122 $pid = launch_with_config($config);
123
124 $window = open_floating_window(rect => [ 0, 0, 2048, 2048 ]);
125 $rect = $window->rect;
126
127 is($rect->{width}, 2048, 'width = 2048');
128 is($rect->{height}, 2048, 'height = 2048');
129
130 exit_gracefully($pid);
131
132 ################################################################################
133 # 5: check floating_minimum_size with cmd_resize
134 ################################################################################
135
136 $config = <<EOT;
137 # i3 config file (v4)
138 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
139
140 # Test with different dimensions than the i3 default.
141 floating_minimum_size 60 x 50
142 EOT
143
144 $pid = launch_with_config($config);
145
146 $window = open_floating_window(rect => [ 0, 0, 100, 100 ]);
147 cmd 'border none';
148 cmd 'resize shrink height 80px or 80ppt';
149 cmd 'resize shrink width 80px or 80ppt';
150 sync_with_i3;
151 $rect = $window->rect;
152 is($rect->{width}, 60, 'width = 60');
153 is($rect->{height}, 50, 'height = 50');
154
155 exit_gracefully($pid);
156
157 ################################################################################
158 # 6: check floating_maximum_size with cmd_resize
159 ################################################################################
160
161 $config = <<EOT;
162 # i3 config file (v4)
163 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
164
165 # Test with different dimensions than the i3 default.
166 floating_maximum_size 100 x 100
167 EOT
168
169 $pid = launch_with_config($config);
170
171 $window = open_floating_window(rect => [ 200, 200, 50, 50 ]);
172 cmd 'border none';
173 cmd 'resize grow height 100px or 100ppt';
174 cmd 'resize grow width 100px or 100ppt';
175 sync_with_i3;
176 $rect = $window->rect;
177 is($rect->{width}, 100, 'width = 100');
178 is($rect->{height}, 100, 'height = 100');
179
180 my $old_x = $rect->{x};
181 my $old_y = $rect->{y};
182 cmd 'resize grow up 10px or 10ppt';
183 sync_with_i3;
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');
187
188 exit_gracefully($pid);
189
190 ################################################################################
191 # 7: check floating_maximum_size with cmd_size
192 ################################################################################
193
194 $config = <<EOT;
195 # i3 config file (v4)
196 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
197
198 # Test with different dimensions than the i3 default.
199 floating_minimum_size 80 x 70
200 floating_maximum_size 100 x 90
201 EOT
202
203 $pid = launch_with_config($config);
204
205 $window = open_floating_window(rect => [ 0, 0, 90, 80 ]);
206 cmd 'border none';
207
208 cmd 'resize set 101 91';
209 sync_with_i3;
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');
213
214 cmd 'resize set 79 69';
215 sync_with_i3;
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');
219
220 exit_gracefully($pid);
221
222 ################################################################################
223 # 8: check minimum_size and maximum_size set by WM_NORMAL_HINTS
224 ################################################################################
225
226 $config = <<EOT;
227 # i3 config file (v4)
228 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
229 EOT
230
231 my $min_width = 150;
232 my $min_height = 100;
233 my $max_width = 250;
234 my $max_height = 200;
235
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;
241
242     my $flags = $XCB_ICCCM_SIZE_HINT_P_MIN_SIZE | $XCB_ICCCM_SIZE_HINT_P_MAX_SIZE;
243
244     my $pad = 0x00;
245
246     my $window = open_window(
247         before_map => sub {
248             my ($window) = @_;
249
250             my $atomname = $x->atom(name => 'WM_NORMAL_HINTS');
251             my $atomtype = $x->atom(name => 'WM_SIZE_HINTS');
252             $x->change_property(
253                 PROP_MODE_REPLACE,
254                 $window->id,
255                 $atomname->id,
256                 $atomtype->id,
257                 32,
258                 13,
259                 pack('C5N8', $flags, $pad, $pad, $pad, $pad, 0, 0, 0, $min_width, $min_height, $max_width, $max_height),
260             );
261         },
262     );
263
264     return $window;
265 }
266
267 my sub check_minsize {
268     sync_with_i3;
269     is($window->rect->{width}, $min_width, 'width = min_width');
270     is($window->rect->{height}, $min_height, 'height = min_height');
271 }
272
273 my sub check_maxsize {
274     sync_with_i3;
275     is($window->rect->{width}, $max_width, 'width = max_width');
276     is($window->rect->{height}, $max_height, 'height = max_height');
277 }
278
279 $pid = launch_with_config($config);
280
281 $window = open_with_max_size;
282 cmd 'floating enable';
283 cmd 'border none';
284
285 cmd "resize set $min_width px $min_height px";
286 check_minsize;
287
288 # Try to resize below minimum width
289 cmd 'resize set ' . ($min_width - 10) . ' px ' . ($min_height - 50) . ' px';
290 check_minsize;
291
292 cmd "resize set $max_width px $max_height px";
293 check_maxsize;
294
295 # Try to resize above maximum width
296 cmd 'resize set ' . ($max_width + 150) . ' px ' . ($max_height + 500) . ' px';
297 check_maxsize;
298
299 exit_gracefully($pid);
300
301 done_testing;