aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/124-move.t
blob: b4a8ca3e282f7303f561359be225ea26d6f95e36 (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
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
#!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 moving. Basically, there are four different code-paths:
# 1) move a container which cannot be moved (single container on a workspace)
# 2) move a container before another single container
# 3) move a container inside another container
# 4) move a container in a different direction so that we need to go up in tree
#
use i3test;

my $i3 = i3(get_socket_path());

my $tmp = fresh_workspace;

######################################################################
# 1) move a container which cannot be moved
######################################################################

cmd 'open';

my $old_content = get_ws_content($tmp);
is(@{$old_content}, 1, 'one container on this workspace');

my $first = $old_content->[0]->{id};

cmd 'move left';
cmd 'move right';
cmd 'move up';
cmd 'move down';

my $content = get_ws_content($tmp);
is_deeply($old_content, $content, 'workspace unmodified after useless moves');

######################################################################
# 2) move a container before another single container
######################################################################

cmd 'open';
$content = get_ws_content($tmp);
is(@{$content}, 2, 'two containers on this workspace');
my $second = $content->[1]->{id};

is($content->[0]->{id}, $first, 'first container unmodified');

# Move the second container before the first one (→ swap them)
cmd 'move left';
$content = get_ws_content($tmp);
is($content->[0]->{id}, $second, 'first container modified');

# We should not be able to move any further
cmd 'move left';
$content = get_ws_content($tmp);
is($content->[0]->{id}, $second, 'first container unmodified');

# Now move in the other direction
cmd 'move right';
$content = get_ws_content($tmp);
is($content->[0]->{id}, $first, 'first container modified');

# We should not be able to move any further
cmd 'move right';
$content = get_ws_content($tmp);
is($content->[0]->{id}, $first, 'first container unmodified');

######################################################################
# 3) move a container inside another container
######################################################################

# Split the current (second) container and create a new container on workspace
# level. Our layout looks like this now:
# --------------------------
# |       | second |       |
# | first | ------ | third |
# |       |        |       |
# --------------------------
cmd 'split v';
cmd 'focus parent';
cmd 'open';

$content = get_ws_content($tmp);
is(@{$content}, 3, 'three containers on this workspace');
my $third = $content->[2]->{id};

cmd 'move left';
$content = get_ws_content($tmp);
is(@{$content}, 2, 'only two containers on this workspace');
my $nodes = $content->[1]->{nodes};
is($nodes->[0]->{id}, $second, 'second container on top');
is($nodes->[1]->{id}, $third, 'third container on bottom');

######################################################################
# move it inside the split container
######################################################################

cmd 'move up';
$nodes = get_ws_content($tmp)->[1]->{nodes};
is($nodes->[0]->{id}, $third, 'third container on top');
is($nodes->[1]->{id}, $second, 'second container on bottom');

# move it outside again
cmd 'move left';
is_num_children($tmp, 3, 'three containers after moving left');

# due to automatic flattening/cleanup, the remaining split container
# will be replaced by the con itself, so we will still have 3 nodes
cmd 'move right';
is_num_children($tmp, 2, 'two containers after moving right (flattening)');

######################################################################
# 4) We create two v-split containers on the workspace, then we move
#    all Cons from the left v-split to the right one. The old vsplit
#    container needs to be closed. Verify that it will be closed.
######################################################################

my $otmp = fresh_workspace;

cmd "open";
cmd "open";
cmd "split v";
cmd "open";
cmd 'focus left';
cmd "split v";
cmd "open";
cmd "move right";
cmd 'focus left';
cmd "move right";

is_num_children($otmp, 1, 'only one node on this workspace');

######################################################################
# 5) test moving floating containers.
######################################################################

$tmp = fresh_workspace;
my $floatwin = open_floating_window;
my ($absolute_before, $top_before) = $floatwin->rect;

cmd 'move left';

sync_with_i3;

my ($absolute, $top) = $floatwin->rect;

is($absolute->x, ($absolute_before->x - 10), 'moved 10 px to the left');
is($absolute->y, $absolute_before->y, 'y not changed');
is($absolute->width, $absolute_before->width, 'width not changed');
is($absolute->height, $absolute_before->height, 'height not changed');

$absolute_before = $absolute;
$top_before = $top;

cmd 'move right';

sync_with_i3;

($absolute, $top) = $floatwin->rect;

is($absolute->x, ($absolute_before->x + 10), 'moved 10 px to the right');
is($absolute->y, $absolute_before->y, 'y not changed');
is($absolute->width, $absolute_before->width, 'width not changed');
is($absolute->height, $absolute_before->height, 'height not changed');

$absolute_before = $absolute;
$top_before = $top;

cmd 'move up';

sync_with_i3;

($absolute, $top) = $floatwin->rect;

is($absolute->x, $absolute_before->x, 'x not changed');
is($absolute->y, ($absolute_before->y - 10), 'moved 10 px up');
is($absolute->width, $absolute_before->width, 'width not changed');
is($absolute->height, $absolute_before->height, 'height not changed');

$absolute_before = $absolute;
$top_before = $top;

cmd 'move down';

sync_with_i3;

($absolute, $top) = $floatwin->rect;

is($absolute->x, $absolute_before->x, 'x not changed');
is($absolute->y, ($absolute_before->y + 10), 'moved 10 px up');
is($absolute->width, $absolute_before->width, 'width not changed');
is($absolute->height, $absolute_before->height, 'height not changed');

$absolute_before = $absolute;
$top_before = $top;

######################################################################
# 6) test moving floating containers with a specific amount of px
######################################################################

cmd 'move left 20 px';

sync_with_i3;

($absolute, $top) = $floatwin->rect;

is($absolute->x, ($absolute_before->x - 20), 'moved 20 px to the left');
is($absolute->y, $absolute_before->y, 'y not changed');
is($absolute->width, $absolute_before->width, 'width not changed');
is($absolute->height, $absolute_before->height, 'height not changed');

$absolute_before = $absolute;
$top_before = $top;

######################################################################
# 7) test moving floating containers with a specific amount of ppt
######################################################################

cmd 'move right 25 ppt';

sync_with_i3;

($absolute, $top) = $floatwin->rect;

is($absolute->x, int($x->root->rect->width * 0.25) + $absolute_before->x, 'moved 25 ppt to the right');
is($absolute->y, $absolute_before->y, 'y not changed');
is($absolute->width, $absolute_before->width, 'width not changed');
is($absolute->height, $absolute_before->height, 'height not changed');

######################################################################
# 8) test moving floating window to a specified position
#    and to absolute center
######################################################################

$tmp = fresh_workspace;
open_floating_window; my @floatcon;

# Move to specified position with px
cmd 'move position 5 px 15 px';

@floatcon = @{get_ws($tmp)->{floating_nodes}};

is($floatcon[0]->{rect}->{x}, 5, 'moved to position 5 (px) x');
is($floatcon[0]->{rect}->{y}, 15, 'moved to position 15 (px) y');

# Move to specified position with ppt
cmd 'move position 20 ppt 20 ppt';

@floatcon = @{get_ws($tmp)->{floating_nodes}};

is($floatcon[0]->{rect}->{x}, int($x->root->rect->width * 0.20), "moved to position 20 (ppt) x");
is($floatcon[0]->{rect}->{y}, int($x->root->rect->height * 0.20), "moved to position 20 (ppt) y");

# Move to absolute center
cmd 'move absolute position center';

@floatcon = @{get_ws($tmp)->{floating_nodes}};

my $center_x = int($x->root->rect->width/2) - int($floatcon[0]->{rect}->{width}/2);
my $center_y = int($x->root->rect->height/2) - int($floatcon[0]->{rect}->{height}/2);

is($floatcon[0]->{rect}->{x}, $center_x, "moved to center at position $center_x x");
is($floatcon[0]->{rect}->{y}, $center_y, "moved to center at position $center_y y");

# Make sure the command works with criteria
open_floating_window;

@floatcon = @{get_ws($tmp)->{floating_nodes}};

cmd '[con_id="' . $floatcon[0]->{nodes}[0]->{id} . '"] move position 25 px 30 px';
cmd '[con_id="' . $floatcon[1]->{nodes}[0]->{id} . '"] move position 35 px 40 px';

@floatcon = @{get_ws($tmp)->{floating_nodes}};

is($floatcon[0]->{rect}->{x}, 25, 'moved to position 25 x with criteria');
is($floatcon[0]->{rect}->{y}, 30, 'moved to position 30 y with criteria');

is($floatcon[1]->{rect}->{x}, 35, 'moved to position 35 x with criteria');
is($floatcon[1]->{rect}->{y}, 40, 'moved to position 40 y with criteria');

done_testing;