aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/541-resize-set-tiling.t
blob: 0298fecd31692b783f23f431145c57479d451455 (plain)
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
#!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;

############################################################
# resize horizontally
############################################################

my $tmp = fresh_workspace;

cmd 'split h';

my $left = open_window;
my $right = open_window;

diag("left = " . $left->id . ", right = " . $right->id);

is($x->input_focus, $right->id, 'Right window focused');

cmd 'resize set 75 ppt 0 ppt';

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

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

# Same but use the 'width' keyword.
cmd 'resize set width 80 ppt';

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

cmp_float($nodes->[0]->{percent}, 0.20, 'left window got 20%');
cmp_float($nodes->[1]->{percent}, 0.80, 'right window got 80%');

# Same but with px.
cmd 'resize set width 200 px';

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

cmp_float($nodes->[1]->{rect}->{width}, 200, 'right window got 200 px');

############################################################
# resize vertically
############################################################

$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');

cmd 'resize set 0 ppt 75 ppt';

($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%');

# Same but use the 'height' keyword.
cmd 'resize set height 80 ppt';

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

cmp_float($nodes->[0]->{percent}, 0.20, 'top window got 20%');
cmp_float($nodes->[1]->{percent}, 0.80, 'bottom window got 80%');

# Same but with px.
cmd 'resize set height 200 px';

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

cmp_float($nodes->[1]->{rect}->{height}, 200, 'bottom window got 200 px');

############################################################
# resize horizontally and vertically
############################################################

$tmp = fresh_workspace;

cmd 'split h';
$left = open_window;
my $top_right = open_window;
cmd 'split v';
my $bottom_right = open_window;

diag("left = " . $left->id . ", top-right = " . $top_right->id . ", bottom-right = " . $bottom_right->id);

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

cmd 'resize set 75 ppt 75 ppt';

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

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

# Same but with px.
cmd 'resize set 155 px 135 px';

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

cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{width}, 155, 'bottom-right window got 155 px width');
cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{height}, 135, 'bottom-right window got 135 px height');

# Without specifying mode
cmd 'resize set 201 131';

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

cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{width}, 201, 'bottom-right window got 201 px width');
cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{height}, 131, 'bottom-right window got 131 px height');

# Mix ppt and px
cmd 'resize set 75 ppt 200 px';

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

cmp_float($nodes->[0]->{percent}, 0.25, 'left container got 25%');
cmp_float($nodes->[1]->{percent}, 0.75, 'right container got 75%');
cmp_float($nodes->[1]->{nodes}->[1]->{rect}->{height}, 200, 'bottom-right window got 200 px height');

############################################################
# resize from inside a tabbed container
############################################################

$tmp = fresh_workspace;

cmd 'split h';

$left = open_window;
my $right1 = open_window;

cmd 'split h';
cmd 'layout tabbed';

my $right2 = open_window;

diag("left = " . $left->id . ", right1 = " . $right1->id . ", right2 = " . $right2->id);

is($x->input_focus, $right2->id, '2nd right window focused');

cmd 'resize set 75 ppt 0 ppt';

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

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

# Same but with px.
cmd 'resize set 155 px';

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

cmp_float($nodes->[1]->{rect}->{width}, 155, 'right container got 155 px');

############################################################
# resize from inside a stacked container
############################################################

$tmp = fresh_workspace;

cmd 'split h';

$left = open_window;
$right1 = open_window;

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

$right2 = open_window;

diag("left = " . $left->id . ", right1 = " . $right1->id . ", right2 = " . $right2->id);

is($x->input_focus, $right2->id, '2nd right window focused');

cmd 'resize set 75 ppt 0 ppt';

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

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

# Same but with px.
cmd 'resize set 130 px';

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

cmp_float($nodes->[1]->{rect}->{width}, 130, 'right container got 130 px');

done_testing;