]> git.sur5r.net Git - i3/i3/blob - testcases/t/252-floating-size.t
resize set: accept 'width' and 'height' keywords
[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 # Init variables used for all tests.
30 ################################################################################
31
32 my $tmp = fresh_workspace;
33 open_floating_window;
34 my @content = @{get_ws($tmp)->{floating_nodes}};
35 is(@content, 1, 'one floating node on this ws');
36 my $oldrect = $content[0]->{rect};
37
38 sub do_test {
39     my ($width, $height) = @_;
40
41     cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x unchanged');
42     cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y unchanged');
43
44     @content = @{get_ws($tmp)->{floating_nodes}};
45     if ($width) {
46         cmp_ok($content[0]->{rect}->{width}, '==', $width, "width changed to $width px");
47     } else {
48         cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width unchanged');
49     }
50     if ($height) {
51         cmp_ok($content[0]->{rect}->{height}, '==', $height, "height changed to $height px");
52     } else {
53         cmp_ok($content[0]->{rect}->{height}, '==', $oldrect->{height}, 'height unchanged');
54     }
55     $oldrect = $content[0]->{rect};
56 }
57
58 ################################################################################
59 # Check that setting floating windows size works
60 ################################################################################
61
62 cmd 'resize set 100 px 250 px';
63 do_test(100, 250);
64
65 ################################################################################
66 # Same but with ppt instead of px
67 ################################################################################
68
69 cmd 'resize set 33 ppt 20 ppt';
70 do_test(int(0.33 * 1333), int(0.2 * 999));
71
72 ################################################################################
73 # Mix ppt and px in a single resize set command
74 ################################################################################
75
76 cmd 'resize set 44 ppt 111 px';
77 do_test(int(0.44 * 1333), 111);
78
79 cmd 'resize set 222 px 100 ppt';
80 do_test(222, 999);
81
82 ################################################################################
83 # Zero is interpreted as no change.
84 # See issue: #3276.
85 ################################################################################
86
87 cmd 'resize set 0 px 333 px';
88 do_test(0, 333);
89
90 cmd 'resize set 333 px 0 ppt';
91 do_test(333, 0);
92
93 cmd 'resize set 0 px 0 ppt';
94 do_test(0, 0);
95
96 cmd 'resize set 100 ppt 0 px';
97 do_test(1333, 0);
98
99 ################################################################################
100 # Use 'width' and 'height' keywords.
101 # See issue: #3275.
102 ################################################################################
103
104 cmd 'resize set width 200 px';
105 do_test(200, 0);
106
107 cmd 'resize set height 200 px';
108 do_test(0, 200);
109
110 cmd 'resize set width 300 px height 300 px';
111 do_test(300, 300);
112
113 # ppt + keyword used only for height
114 cmd 'resize set 100 ppt height 100 px';
115 do_test(1333, 100);
116
117 done_testing;