]> git.sur5r.net Git - i3/i3/blob - testcases/t/252-floating-size.t
Add support to resize floating container in percentage
[i3/i3] / testcases / t / 252-floating-size.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 # Test behavior of "resize <width> <height>" command.
18 # Ticket: #1727
19 # Bug still in: 4.10.2-1-gc0dbc5d
20 use i3test i3_config => <<EOT;
21 # i3 config file (v4)
22 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
23
24 fake-outputs 1333x999+0+0
25 workspace ws output fake-0
26 EOT
27
28 ################################################################################
29 # Check that setting floating windows size works
30 ################################################################################
31
32 my $tmp = fresh_workspace;
33
34 open_floating_window;
35
36 my @content = @{get_ws($tmp)->{floating_nodes}};
37 is(@content, 1, 'one floating node on this ws');
38
39 my $oldrect = $content[0]->{rect};
40
41 cmd 'resize set 100 px 250 px';
42
43 @content = @{get_ws($tmp)->{floating_nodes}};
44 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
45 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y untouched');
46 cmp_ok($content[0]->{rect}->{width}, '!=', $oldrect->{width}, 'width changed');
47 cmp_ok($content[0]->{rect}->{height}, '!=', $oldrect->{width}, 'height changed');
48 cmp_ok($content[0]->{rect}->{width}, '==', 100, 'width changed to 100 px');
49 cmp_ok($content[0]->{rect}->{height}, '==', 250, 'height changed to 250 px');
50
51 ################################################################################
52 # Same but with ppt instead of px
53 ################################################################################
54
55 kill_all_windows;
56 $tmp = 'ws';
57 cmd "workspace $tmp";
58 open_floating_window;
59
60 @content = @{get_ws($tmp)->{floating_nodes}};
61 is(@content, 1, 'one floating node on this ws');
62
63 $oldrect = $content[0]->{rect};
64
65 cmd 'resize set 33 ppt 20 ppt';
66 my $expected_width = int(0.33 * 1333);
67 my $expected_height = int(0.2 * 999);
68
69 @content = @{get_ws($tmp)->{floating_nodes}};
70 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
71 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y untouched');
72 cmp_ok($content[0]->{rect}->{width}, '!=', $oldrect->{width}, 'width changed');
73 cmp_ok($content[0]->{rect}->{height}, '!=', $oldrect->{width}, 'height changed');
74 cmp_ok($content[0]->{rect}->{width}, '==', $expected_width, "width changed to $expected_width px");
75 cmp_ok($content[0]->{rect}->{height}, '==', $expected_height, "height changed to $expected_height px");
76
77 ################################################################################
78 # Mix ppt and px in a single resize set command
79 ################################################################################
80
81 cmd 'resize set 44 ppt 111 px';
82 my $expected_width = int(0.44 * 1333);
83 my $expected_height = 111;
84
85 @content = @{get_ws($tmp)->{floating_nodes}};
86 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
87 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y untouched');
88 cmp_ok($content[0]->{rect}->{width}, '==', $expected_width, "width changed to $expected_width px");
89 cmp_ok($content[0]->{rect}->{height}, '==', $expected_height, "height changed to $expected_height px");
90
91 cmd 'resize set 222 px 100 ppt';
92 my $expected_width = 222;
93 my $expected_height = 999;
94
95 @content = @{get_ws($tmp)->{floating_nodes}};
96 cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
97 cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y untouched');
98 cmp_ok($content[0]->{rect}->{width}, '==', $expected_width, "width changed to $expected_width px");
99 cmp_ok($content[0]->{rect}->{height}, '==', $expected_height, "height changed to $expected_height px");
100
101 done_testing;