2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
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
25 my $i3 = i3(get_socket_path());
27 my $tmp = fresh_workspace;
29 ######################################################################
30 # 1) move a container which cannot be moved
31 ######################################################################
35 my $old_content = get_ws_content($tmp);
36 is(@{$old_content}, 1, 'one container on this workspace');
38 my $first = $old_content->[0]->{id};
45 my $content = get_ws_content($tmp);
46 is_deeply($old_content, $content, 'workspace unmodified after useless moves');
48 ######################################################################
49 # 2) move a container before another single container
50 ######################################################################
53 $content = get_ws_content($tmp);
54 is(@{$content}, 2, 'two containers on this workspace');
55 my $second = $content->[1]->{id};
57 is($content->[0]->{id}, $first, 'first container unmodified');
59 # Move the second container before the first one (→ swap them)
61 $content = get_ws_content($tmp);
62 is($content->[0]->{id}, $second, 'first container modified');
64 # We should not be able to move any further
66 $content = get_ws_content($tmp);
67 is($content->[0]->{id}, $second, 'first container unmodified');
69 # Now move in the other direction
71 $content = get_ws_content($tmp);
72 is($content->[0]->{id}, $first, 'first container modified');
74 # We should not be able to move any further
76 $content = get_ws_content($tmp);
77 is($content->[0]->{id}, $first, 'first container unmodified');
79 ######################################################################
80 # 3) move a container inside another container
81 ######################################################################
83 # Split the current (second) container and create a new container on workspace
84 # level. Our layout looks like this now:
85 # --------------------------
87 # | first | ------ | third |
89 # --------------------------
94 $content = get_ws_content($tmp);
95 is(@{$content}, 3, 'three containers on this workspace');
96 my $third = $content->[2]->{id};
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');
105 ######################################################################
106 # move it inside the split container
107 ######################################################################
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');
114 # move it outside again
116 is_num_children($tmp, 3, 'three containers after moving left');
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
121 is_num_children($tmp, 2, 'two containers after moving right (flattening)');
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 ######################################################################
129 my $otmp = fresh_workspace;
142 is_num_children($otmp, 1, 'only one node on this workspace');
144 ######################################################################
145 # 5) test moving floating containers.
146 ######################################################################
148 $tmp = fresh_workspace;
149 my $floatwin = open_floating_window;
150 my ($absolute_before, $top_before) = $floatwin->rect;
156 my ($absolute, $top) = $floatwin->rect;
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');
163 $absolute_before = $absolute;
170 ($absolute, $top) = $floatwin->rect;
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');
177 $absolute_before = $absolute;
184 ($absolute, $top) = $floatwin->rect;
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');
191 $absolute_before = $absolute;
198 ($absolute, $top) = $floatwin->rect;
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');
205 $absolute_before = $absolute;
208 ######################################################################
209 # 6) test moving floating containers with a specific amount of px
210 ######################################################################
212 cmd 'move left 20 px';
216 ($absolute, $top) = $floatwin->rect;
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');
223 ######################################################################
224 # 6) test moving floating window to a specified position
225 # and to absolute center
226 ######################################################################
228 $tmp = fresh_workspace;
229 open_floating_window; my @floatcon;
231 cmd 'move position 5 px 15 px';
233 @floatcon = @{get_ws($tmp)->{floating_nodes}};
235 is($floatcon[0]->{rect}->{x}, 5, 'moved to position 5 x');
236 is($floatcon[0]->{rect}->{y}, 15, 'moved to position 15 y');
238 cmd 'move absolute position center';
240 @floatcon = @{get_ws($tmp)->{floating_nodes}};
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);
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");