Codebase list i3-gaps / upstream/4.18.1 testcases / t / 141-resize.t
upstream/4.18.1

Tree @upstream/4.18.1 (Download .tar.gz)

141-resize.t @upstream/4.18.1raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Tests resizing tiling containers
use i3test;

my ($left, $right);
my $tmp = fresh_workspace;

cmd 'split v';

my $top = open_window;
my $bottom = open_window;

diag("top = " . $top->id . ", bottom = " . $bottom->id);

is($x->input_focus, $bottom->id, 'Bottom window focused');

############################################################
# resize
############################################################

cmd 'resize grow up 10 px or 25 ppt';

my ($nodes, $focus) = get_ws_content($tmp);

cmp_float($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');


############################################################
# split and check if the 'percent' factor is still correct
############################################################

cmd 'split h';

($nodes, $focus) = get_ws_content($tmp);

cmp_float($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');

############################################################
# checks that resizing within stacked/tabbed cons works
############################################################

$tmp = fresh_workspace;

cmd 'split v';

$top = open_window;
$bottom = open_window;

cmd 'split h';
cmd 'layout stacked';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{percent}, 0.5, 'top window got 50%');
cmp_float($nodes->[1]->{percent}, 0.5, 'bottom window got 50%');

cmd 'resize grow up 10 px or 25 ppt';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{percent}, 0.25, 'top window got 25%');
cmp_float($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');

############################################################
# Checks that resizing in the parent's parent's orientation works.
# Take for example a horizontal workspace with one window on the left side and
# a v-split container with two windows on the right side. Focus is on the
# bottom right window, use 'resize left'.
############################################################

$tmp = fresh_workspace;

$left = open_window;
$right = open_window;

cmd 'split v';

$top = open_window;
$bottom = open_window;

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{percent}, 0.5, 'left window got 50%');
cmp_float($nodes->[1]->{percent}, 0.5, 'right window got 50%');

cmd 'resize grow left 10 px or 25 ppt';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');

################################################################################
# Check that the resize grow/shrink width/height syntax works.
################################################################################

# Use two windows
$tmp = fresh_workspace;

$left = open_window;
$right = open_window;

cmd 'resize grow width 10 px or 25 ppt';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');

# Now test it with four windows
$tmp = fresh_workspace;

open_window for (1..4);

cmd 'resize grow width 10 px or 25 ppt';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{percent}, 0.166666666666667, 'first window got 16%');
cmp_float($nodes->[1]->{percent}, 0.166666666666667, 'second window got 16%');
cmp_float($nodes->[2]->{percent}, 0.166666666666667, 'third window got 16%');
cmp_float($nodes->[3]->{percent}, 0.50, 'fourth window got 50%');

# height should be a no-op in this situation
cmd 'resize grow height 10 px or 25 ppt';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{percent}, 0.166666666666667, 'first window got 16%');
cmp_float($nodes->[1]->{percent}, 0.166666666666667, 'second window got 16%');
cmp_float($nodes->[2]->{percent}, 0.166666666666667, 'third window got 16%');
cmp_float($nodes->[3]->{percent}, 0.50, 'fourth window got 50%');

################################################################################
# Same but using pixels instead of ppt.
################################################################################

# Use two windows
$tmp = fresh_workspace;

$left = open_window;
$right = open_window;

($nodes, $focus) = get_ws_content($tmp);
my @widths = ($nodes->[0]->{rect}->{width}, $nodes->[1]->{rect}->{width});

cmd 'resize grow width 10 px';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{rect}->{width}, $widths[0] - 10, 'left window is 10px smaller');
cmp_float($nodes->[1]->{rect}->{width}, $widths[1] + 10, 'right window is 10px larger');

# Now test it with four windows
$tmp = fresh_workspace;

open_window for (1..4);

($nodes, $focus) = get_ws_content($tmp);
my $width = $nodes->[0]->{rect}->{width};

cmd 'resize grow width 10 px';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[3]->{rect}->{width}, $width + 10, 'last window is 10px larger');

################################################################################
# Same but for height
################################################################################

# Use two windows
$tmp = fresh_workspace;
cmd 'split v';

$left = open_window;
$right = open_window;

($nodes, $focus) = get_ws_content($tmp);
my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});

cmd 'resize grow height 10 px';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{rect}->{height}, $heights[0] - 10, 'left window is 10px smaller');
cmp_float($nodes->[1]->{rect}->{height}, $heights[1] + 10, 'right window is 10px larger');

# Now test it with four windows
$tmp = fresh_workspace;
cmd 'split v';

open_window for (1..4);

($nodes, $focus) = get_ws_content($tmp);
my $height = $nodes->[0]->{rect}->{height};

cmd 'resize grow height 10 px';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[3]->{rect}->{height}, $height + 10, 'last window is 10px larger');

################################################################################
# Check that we can grow tiled windows by pixels
################################################################################

$tmp = fresh_workspace;

$left = open_window;
$right = open_window;

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{rect}->{width}, 640, 'left window is 640px');
cmp_float($nodes->[1]->{rect}->{width}, 640, 'right window is 640px');

cmd 'resize grow left 10px';
($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{rect}->{width}, 630, 'left window is 630px');
cmp_float($nodes->[1]->{rect}->{width}, 650, 'right window is 650px');

################################################################################
# Check that we can shrink tiled windows by pixels
################################################################################

$tmp = fresh_workspace;

$left = open_window;
$right = open_window;

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{rect}->{width}, 640, 'left window is 640px');
cmp_float($nodes->[1]->{rect}->{width}, 640, 'right window is 640px');

cmd 'resize shrink left 10px';
($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{rect}->{width}, 650, 'left window is 650px');
cmp_float($nodes->[1]->{rect}->{width}, 630, 'right window is 630px');


################################################################################
# Check that we can shrink vertical tiled windows by pixels
################################################################################

$tmp = fresh_workspace;

cmd 'split v';

$top = open_window;
$bottom = open_window;

($nodes, $focus) = get_ws_content($tmp);
my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});

cmd 'resize grow up 10px';
($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{rect}->{height}, $heights[0] - 10, 'top window is 10px larger');
cmp_float($nodes->[1]->{rect}->{height}, $heights[1] + 10, 'bottom window is 10px smaller');

################################################################################
# Check that we can shrink vertical tiled windows by pixels
################################################################################

$tmp = fresh_workspace;

cmd 'split v';

$top = open_window;
$bottom = open_window;

($nodes, $focus) = get_ws_content($tmp);
my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height});

cmd 'resize shrink up 10px';
($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{rect}->{height}, $heights[0] + 10, 'top window is 10px smaller');
cmp_float($nodes->[1]->{rect}->{height}, $heights[1] - 10, 'bottom window is 10px larger');

################################################################################
# Check that the resize grow/shrink width/height syntax works if a nested split
# was set on the container, but no sibling has been opened yet. See #2015.
################################################################################

$tmp = fresh_workspace;
$left = open_window;
$right = open_window;

cmd 'split h';
cmd 'resize grow width 10px or 25 ppt';

($nodes, $focus) = get_ws_content($tmp);
cmp_float($nodes->[0]->{percent}, 0.25, 'left window got 25%');
cmp_float($nodes->[1]->{percent}, 0.75, 'right window got 75%');

############################################################
# checks that resizing floating windows works
############################################################

$tmp = fresh_workspace;

$top = open_window;

cmd 'floating enable';

my @content = @{get_ws($tmp)->{floating_nodes}};
cmp_ok(@content, '==', 1, 'one floating node on this ws');

# up
my $oldrect = $content[0]->{rect};

cmd 'resize grow up 10 px or 25 ppt';

@content = @{get_ws($tmp)->{floating_nodes}};
cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 10, 'y exactly 10 px smaller');
cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 10, 'height exactly 10 px higher');
cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');

# up, but with a different amount of px
$oldrect = $content[0]->{rect};

cmd 'resize grow up 12 px or 25 ppt';

@content = @{get_ws($tmp)->{floating_nodes}};
cmp_ok($content[0]->{rect}->{y}, '<', $oldrect->{y}, 'y smaller than before');
cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y} - 12, 'y exactly 10 px smaller');
cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height} + 12, 'height exactly 10 px higher');
cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'x untouched');

# left
$oldrect = $content[0]->{rect};

cmd 'resize grow left 10 px or 25 ppt';

@content = @{get_ws($tmp)->{floating_nodes}};
cmp_ok($content[0]->{rect}->{x}, '<', $oldrect->{x}, 'x smaller than before');
cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');

# right
$oldrect = $content[0]->{rect};

cmd 'resize grow right 10 px or 25 ppt';

@content = @{get_ws($tmp)->{floating_nodes}};
cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');
cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');

# down
$oldrect = $content[0]->{rect};

cmd 'resize grow down 10 px or 25 ppt';

@content = @{get_ws($tmp)->{floating_nodes}};
cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');

# grow width
$oldrect = $content[0]->{rect};

cmd 'resize grow width 10px or 10ppt';

@content = @{get_ws($tmp)->{floating_nodes}};
cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
cmp_ok($content[0]->{rect}->{width}, '>', $oldrect->{width}, 'width bigger than before');

# shrink width
$oldrect = $content[0]->{rect};

cmd 'resize shrink width 10px or 10ppt';

@content = @{get_ws($tmp)->{floating_nodes}};
cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height the same as before');
cmp_ok($content[0]->{rect}->{width}, '<', $oldrect->{width}, 'width smaller than before');

# grow height
$oldrect = $content[0]->{rect};

cmd 'resize grow height 10px or 10ppt';

@content = @{get_ws($tmp)->{floating_nodes}};
cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
cmp_ok($content[0]->{rect}->{height}, '>', $oldrect->{height}, 'height bigger than before');
cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');

# shrink height
$oldrect = $content[0]->{rect};

cmd 'resize shrink height 10px or 10ppt';

@content = @{get_ws($tmp)->{floating_nodes}};
cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x the same as before');
cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
cmp_ok($content[0]->{rect}->{height}, '<', $oldrect->{height}, 'height smaller than before');
cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');

################################################################################
# Check that resizing with criteria works
################################################################################

$tmp = fresh_workspace;

$left = open_floating_window;
$right = open_floating_window;

sub get_floating_rect {
    my ($window_id) = @_;

    my $floating_nodes = get_ws($tmp)->{floating_nodes};
    for my $floating_node (@$floating_nodes) {
        # Get all the windows within that floating container
        my @window_ids = map { $_->{window} } @{$floating_node->{nodes}};
        if ($window_id ~~ @window_ids) {
            return $floating_node->{rect};
        }
    }

    return undef;
}

# focus is on the right window, so we resize the left one using criteria
my $leftold = get_floating_rect($left->id);
my $rightold = get_floating_rect($right->id);
cmd '[id="' . $left->id . '"] resize grow height 10px or 10ppt';

my $leftnew = get_floating_rect($left->id);
my $rightnew = get_floating_rect($right->id);
is($rightnew->{height}, $rightold->{height}, 'height of right container unchanged');
is($leftnew->{height}, $leftold->{height} + 10, 'height of left container changed');

done_testing;