]> git.sur5r.net Git - i3/i3/blob - testcases/t/124-move.t
Merge branch 'next' into master
[i3/i3] / testcases / t / 124-move.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 # Tests moving. Basically, there are four different code-paths:
18 # 1) move a container which cannot be moved (single container on a workspace)
19 # 2) move a container before another single container
20 # 3) move a container inside another container
21 # 4) move a container in a different direction so that we need to go up in tree
22 #
23 use i3test;
24
25 my $i3 = i3(get_socket_path());
26
27 my $tmp = fresh_workspace;
28
29 ######################################################################
30 # 1) move a container which cannot be moved
31 ######################################################################
32
33 cmd 'open';
34
35 my $old_content = get_ws_content($tmp);
36 is(@{$old_content}, 1, 'one container on this workspace');
37
38 my $first = $old_content->[0]->{id};
39
40 cmd 'move left';
41 cmd 'move right';
42 cmd 'move up';
43 cmd 'move down';
44
45 my $content = get_ws_content($tmp);
46 is_deeply($old_content, $content, 'workspace unmodified after useless moves');
47
48 ######################################################################
49 # 2) move a container before another single container
50 ######################################################################
51
52 cmd 'open';
53 $content = get_ws_content($tmp);
54 is(@{$content}, 2, 'two containers on this workspace');
55 my $second = $content->[1]->{id};
56
57 is($content->[0]->{id}, $first, 'first container unmodified');
58
59 # Move the second container before the first one (→ swap them)
60 cmd 'move left';
61 $content = get_ws_content($tmp);
62 is($content->[0]->{id}, $second, 'first container modified');
63
64 # We should not be able to move any further
65 cmd 'move left';
66 $content = get_ws_content($tmp);
67 is($content->[0]->{id}, $second, 'first container unmodified');
68
69 # Now move in the other direction
70 cmd 'move right';
71 $content = get_ws_content($tmp);
72 is($content->[0]->{id}, $first, 'first container modified');
73
74 # We should not be able to move any further
75 cmd 'move right';
76 $content = get_ws_content($tmp);
77 is($content->[0]->{id}, $first, 'first container unmodified');
78
79 ######################################################################
80 # 3) move a container inside another container
81 ######################################################################
82
83 # Split the current (second) container and create a new container on workspace
84 # level. Our layout looks like this now:
85 # --------------------------
86 # |       | second |       |
87 # | first | ------ | third |
88 # |       |        |       |
89 # --------------------------
90 cmd 'split v';
91 cmd 'focus parent';
92 cmd 'open';
93
94 $content = get_ws_content($tmp);
95 is(@{$content}, 3, 'three containers on this workspace');
96 my $third = $content->[2]->{id};
97
98 cmd 'move left';
99 $content = get_ws_content($tmp);
100 is(@{$content}, 2, 'only two containers on this workspace');
101 my $nodes = $content->[1]->{nodes};
102 is($nodes->[0]->{id}, $second, 'second container on top');
103 is($nodes->[1]->{id}, $third, 'third container on bottom');
104
105 ######################################################################
106 # move it inside the split container
107 ######################################################################
108
109 cmd 'move up';
110 $nodes = get_ws_content($tmp)->[1]->{nodes};
111 is($nodes->[0]->{id}, $third, 'third container on top');
112 is($nodes->[1]->{id}, $second, 'second container on bottom');
113
114 # move it outside again
115 cmd 'move left';
116 is_num_children($tmp, 3, 'three containers after moving left');
117
118 # due to automatic flattening/cleanup, the remaining split container
119 # will be replaced by the con itself, so we will still have 3 nodes
120 cmd 'move right';
121 is_num_children($tmp, 2, 'two containers after moving right (flattening)');
122
123 ######################################################################
124 # 4) We create two v-split containers on the workspace, then we move
125 #    all Cons from the left v-split to the right one. The old vsplit
126 #    container needs to be closed. Verify that it will be closed.
127 ######################################################################
128
129 my $otmp = fresh_workspace;
130
131 cmd "open";
132 cmd "open";
133 cmd "split v";
134 cmd "open";
135 cmd 'focus left';
136 cmd "split v";
137 cmd "open";
138 cmd "move right";
139 cmd 'focus left';
140 cmd "move right";
141
142 is_num_children($otmp, 1, 'only one node on this workspace');
143
144 ######################################################################
145 # 5) test moving floating containers.
146 ######################################################################
147
148 $tmp = fresh_workspace;
149 my $floatwin = open_floating_window;
150 my ($absolute_before, $top_before) = $floatwin->rect;
151
152 cmd 'move left';
153
154 sync_with_i3;
155
156 my ($absolute, $top) = $floatwin->rect;
157
158 is($absolute->x, ($absolute_before->x - 10), 'moved 10 px to the left');
159 is($absolute->y, $absolute_before->y, 'y not changed');
160 is($absolute->width, $absolute_before->width, 'width not changed');
161 is($absolute->height, $absolute_before->height, 'height not changed');
162
163 $absolute_before = $absolute;
164 $top_before = $top;
165
166 cmd 'move right';
167
168 sync_with_i3;
169
170 ($absolute, $top) = $floatwin->rect;
171
172 is($absolute->x, ($absolute_before->x + 10), 'moved 10 px to the right');
173 is($absolute->y, $absolute_before->y, 'y not changed');
174 is($absolute->width, $absolute_before->width, 'width not changed');
175 is($absolute->height, $absolute_before->height, 'height not changed');
176
177 $absolute_before = $absolute;
178 $top_before = $top;
179
180 cmd 'move up';
181
182 sync_with_i3;
183
184 ($absolute, $top) = $floatwin->rect;
185
186 is($absolute->x, $absolute_before->x, 'x not changed');
187 is($absolute->y, ($absolute_before->y - 10), 'moved 10 px up');
188 is($absolute->width, $absolute_before->width, 'width not changed');
189 is($absolute->height, $absolute_before->height, 'height not changed');
190
191 $absolute_before = $absolute;
192 $top_before = $top;
193
194 cmd 'move down';
195
196 sync_with_i3;
197
198 ($absolute, $top) = $floatwin->rect;
199
200 is($absolute->x, $absolute_before->x, 'x not changed');
201 is($absolute->y, ($absolute_before->y + 10), 'moved 10 px up');
202 is($absolute->width, $absolute_before->width, 'width not changed');
203 is($absolute->height, $absolute_before->height, 'height not changed');
204
205 $absolute_before = $absolute;
206 $top_before = $top;
207
208 ######################################################################
209 # 6) test moving floating containers with a specific amount of px
210 ######################################################################
211
212 cmd 'move left 20 px';
213
214 sync_with_i3;
215
216 ($absolute, $top) = $floatwin->rect;
217
218 is($absolute->x, ($absolute_before->x - 20), 'moved 20 px to the left');
219 is($absolute->y, $absolute_before->y, 'y not changed');
220 is($absolute->width, $absolute_before->width, 'width not changed');
221 is($absolute->height, $absolute_before->height, 'height not changed');
222
223 ######################################################################
224 # 6) test moving floating window to a specified position
225 #    and to absolute center
226 ######################################################################
227
228 $tmp = fresh_workspace;
229 open_floating_window; my @floatcon;
230
231 cmd 'move position 5 px 15 px';
232
233 @floatcon = @{get_ws($tmp)->{floating_nodes}};
234
235 is($floatcon[0]->{rect}->{x}, 5, 'moved to position 5 x');
236 is($floatcon[0]->{rect}->{y}, 15, 'moved to position 15 y');
237
238 cmd 'move absolute position center';
239
240 @floatcon = @{get_ws($tmp)->{floating_nodes}};
241
242 my $center_x = int($x->root->rect->width/2) - int($floatcon[0]->{rect}->{width}/2);
243 my $center_y = int($x->root->rect->height/2) - int($floatcon[0]->{rect}->{height}/2);
244
245 is($floatcon[0]->{rect}->{x}, $center_x, "moved to center at position $center_x x");
246 is($floatcon[0]->{rect}->{y}, $center_y, "moved to center at position $center_y y");
247
248 # Make sure the command works with criteria
249 open_floating_window;
250
251 @floatcon = @{get_ws($tmp)->{floating_nodes}};
252
253 cmd '[con_id="' . $floatcon[0]->{nodes}[0]->{id} . '"] move position 25 px 30 px';
254 cmd '[con_id="' . $floatcon[1]->{nodes}[0]->{id} . '"] move position 35 px 40 px';
255
256 @floatcon = @{get_ws($tmp)->{floating_nodes}};
257
258 is($floatcon[0]->{rect}->{x}, 25, 'moved to position 25 x with criteria');
259 is($floatcon[0]->{rect}->{y}, 30, 'moved to position 30 y with criteria');
260
261 is($floatcon[1]->{rect}->{x}, 35, 'moved to position 35 x with criteria');
262 is($floatcon[1]->{rect}->{y}, 40, 'moved to position 40 y with criteria');
263
264 done_testing;