2 # vim:ts=4:sw=4:expandtab
4 # Tests moving. Basically, there are four different code-paths:
5 # 1) move a container which cannot be moved (single container on a workspace)
6 # 2) move a container before another single container
7 # 3) move a container inside another container
8 # 4) move a container in a different direction so that we need to go up in tree
11 use X11::XCB::Connection;
13 my $x = X11::XCB::Connection->new;
14 my $i3 = i3(get_socket_path());
16 my $tmp = fresh_workspace;
18 ######################################################################
19 # 1) move a container which cannot be moved
20 ######################################################################
24 my $old_content = get_ws_content($tmp);
25 is(@{$old_content}, 1, 'one container on this workspace');
27 my $first = $old_content->[0]->{id};
34 my $content = get_ws_content($tmp);
35 is_deeply($old_content, $content, 'workspace unmodified after useless moves');
37 ######################################################################
38 # 2) move a container before another single container
39 ######################################################################
42 $content = get_ws_content($tmp);
43 is(@{$content}, 2, 'two containers on this workspace');
44 my $second = $content->[1]->{id};
46 is($content->[0]->{id}, $first, 'first container unmodified');
48 # Move the second container before the first one (→ swap them)
50 $content = get_ws_content($tmp);
51 is($content->[0]->{id}, $second, 'first container modified');
53 # We should not be able to move any further
55 $content = get_ws_content($tmp);
56 is($content->[0]->{id}, $second, 'first container unmodified');
58 # Now move in the other direction
60 $content = get_ws_content($tmp);
61 is($content->[0]->{id}, $first, 'first container modified');
63 # We should not be able to move any further
65 $content = get_ws_content($tmp);
66 is($content->[0]->{id}, $first, 'first container unmodified');
68 ######################################################################
69 # 3) move a container inside another container
70 ######################################################################
72 # Split the current (second) container and create a new container on workspace
73 # level. Our layout looks like this now:
74 # --------------------------
76 # | first | ------ | third |
78 # --------------------------
83 $content = get_ws_content($tmp);
84 is(@{$content}, 3, 'three containers on this workspace');
85 my $third = $content->[2]->{id};
88 $content = get_ws_content($tmp);
89 is(@{$content}, 2, 'only two containers on this workspace');
90 my $nodes = $content->[1]->{nodes};
91 is($nodes->[0]->{id}, $second, 'second container on top');
92 is($nodes->[1]->{id}, $third, 'third container on bottom');
94 ######################################################################
95 # move it inside the split container
96 ######################################################################
99 $nodes = get_ws_content($tmp)->[1]->{nodes};
100 is($nodes->[0]->{id}, $third, 'third container on top');
101 is($nodes->[1]->{id}, $second, 'second container on bottom');
103 # move it outside again
105 $content = get_ws_content($tmp);
106 is(@{$content}, 3, 'three nodes on this workspace');
108 # due to automatic flattening/cleanup, the remaining split container
109 # will be replaced by the con itself, so we will still have 3 nodes
111 $content = get_ws_content($tmp);
112 is(@{$content}, 2, 'two nodes on this workspace');
114 ######################################################################
115 # 4) We create two v-split containers on the workspace, then we move
116 # all Cons from the left v-split to the right one. The old vsplit
117 # container needs to be closed. Verify that it will be closed.
118 ######################################################################
120 my $otmp = fresh_workspace;
133 $content = get_ws_content($otmp);
134 is(@{$content}, 1, 'only one nodes on this workspace');
136 ######################################################################
137 # 5) test moving floating containers.
138 ######################################################################
140 $tmp = fresh_workspace;
141 my $floatwin = open_floating_window($x);
142 my ($absolute_before, $top_before) = $floatwin->rect;
146 my ($absolute, $top) = $floatwin->rect;
148 is($absolute->x, ($absolute_before->x - 10), 'moved 10 px to the left');
149 is($absolute->y, $absolute_before->y, 'y not changed');
150 is($absolute->width, $absolute_before->width, 'width not changed');
151 is($absolute->height, $absolute_before->height, 'height not changed');
153 $absolute_before = $absolute;
158 ($absolute, $top) = $floatwin->rect;
160 is($absolute->x, ($absolute_before->x + 10), 'moved 10 px to the right');
161 is($absolute->y, $absolute_before->y, 'y not changed');
162 is($absolute->width, $absolute_before->width, 'width not changed');
163 is($absolute->height, $absolute_before->height, 'height not changed');
165 $absolute_before = $absolute;
170 ($absolute, $top) = $floatwin->rect;
172 is($absolute->x, $absolute_before->x, 'x not changed');
173 is($absolute->y, ($absolute_before->y - 10), 'moved 10 px up');
174 is($absolute->width, $absolute_before->width, 'width not changed');
175 is($absolute->height, $absolute_before->height, 'height not changed');
177 $absolute_before = $absolute;
182 ($absolute, $top) = $floatwin->rect;
184 is($absolute->x, $absolute_before->x, 'x not changed');
185 is($absolute->y, ($absolute_before->y + 10), 'moved 10 px up');
186 is($absolute->width, $absolute_before->width, 'width not changed');
187 is($absolute->height, $absolute_before->height, 'height not changed');
189 $absolute_before = $absolute;
192 ######################################################################
193 # 6) test moving floating containers with a specific amount of px
194 ######################################################################
196 cmd 'move left 20 px';
198 ($absolute, $top) = $floatwin->rect;
200 is($absolute->x, ($absolute_before->x - 20), 'moved 10 px to the left');
201 is($absolute->y, $absolute_before->y, 'y not changed');
202 is($absolute->width, $absolute_before->width, 'width not changed');
203 is($absolute->height, $absolute_before->height, 'height not changed');