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
12 my $i3 = i3(get_socket_path());
14 my $tmp = fresh_workspace;
16 ######################################################################
17 # 1) move a container which cannot be moved
18 ######################################################################
22 my $old_content = get_ws_content($tmp);
23 is(@{$old_content}, 1, 'one container on this workspace');
25 my $first = $old_content->[0]->{id};
32 my $content = get_ws_content($tmp);
33 is_deeply($old_content, $content, 'workspace unmodified after useless moves');
35 ######################################################################
36 # 2) move a container before another single container
37 ######################################################################
40 $content = get_ws_content($tmp);
41 is(@{$content}, 2, 'two containers on this workspace');
42 my $second = $content->[1]->{id};
44 is($content->[0]->{id}, $first, 'first container unmodified');
46 # Move the second container before the first one (→ swap them)
48 $content = get_ws_content($tmp);
49 is($content->[0]->{id}, $second, 'first container modified');
51 # We should not be able to move any further
53 $content = get_ws_content($tmp);
54 is($content->[0]->{id}, $second, 'first container unmodified');
56 # Now move in the other direction
58 $content = get_ws_content($tmp);
59 is($content->[0]->{id}, $first, 'first container modified');
61 # We should not be able to move any further
63 $content = get_ws_content($tmp);
64 is($content->[0]->{id}, $first, 'first container unmodified');
66 ######################################################################
67 # 3) move a container inside another container
68 ######################################################################
70 # Split the current (second) container and create a new container on workspace
71 # level. Our layout looks like this now:
72 # --------------------------
74 # | first | ------ | third |
76 # --------------------------
81 $content = get_ws_content($tmp);
82 is(@{$content}, 3, 'three containers on this workspace');
83 my $third = $content->[2]->{id};
86 $content = get_ws_content($tmp);
87 is(@{$content}, 2, 'only two containers on this workspace');
88 my $nodes = $content->[1]->{nodes};
89 is($nodes->[0]->{id}, $second, 'second container on top');
90 is($nodes->[1]->{id}, $third, 'third container on bottom');
92 ######################################################################
93 # move it inside the split container
94 ######################################################################
97 $nodes = get_ws_content($tmp)->[1]->{nodes};
98 is($nodes->[0]->{id}, $third, 'third container on top');
99 is($nodes->[1]->{id}, $second, 'second container on bottom');
101 # move it outside again
103 $content = get_ws_content($tmp);
104 is(@{$content}, 3, 'three nodes on this workspace');
106 # due to automatic flattening/cleanup, the remaining split container
107 # will be replaced by the con itself, so we will still have 3 nodes
109 $content = get_ws_content($tmp);
110 is(@{$content}, 2, 'two nodes on this workspace');
112 ######################################################################
113 # 4) We create two v-split containers on the workspace, then we move
114 # all Cons from the left v-split to the right one. The old vsplit
115 # container needs to be closed. Verify that it will be closed.
116 ######################################################################
118 my $otmp = fresh_workspace;
131 $content = get_ws_content($otmp);
132 is(@{$content}, 1, 'only one nodes on this workspace');
134 ######################################################################
135 # 5) test moving floating containers.
136 ######################################################################
138 $tmp = fresh_workspace;
139 my $floatwin = open_floating_window;
140 my ($absolute_before, $top_before) = $floatwin->rect;
144 my ($absolute, $top) = $floatwin->rect;
146 is($absolute->x, ($absolute_before->x - 10), 'moved 10 px to the left');
147 is($absolute->y, $absolute_before->y, 'y not changed');
148 is($absolute->width, $absolute_before->width, 'width not changed');
149 is($absolute->height, $absolute_before->height, 'height not changed');
151 $absolute_before = $absolute;
156 ($absolute, $top) = $floatwin->rect;
158 is($absolute->x, ($absolute_before->x + 10), 'moved 10 px to the right');
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;
168 ($absolute, $top) = $floatwin->rect;
170 is($absolute->x, $absolute_before->x, 'x not changed');
171 is($absolute->y, ($absolute_before->y - 10), 'moved 10 px up');
172 is($absolute->width, $absolute_before->width, 'width not changed');
173 is($absolute->height, $absolute_before->height, 'height not changed');
175 $absolute_before = $absolute;
180 ($absolute, $top) = $floatwin->rect;
182 is($absolute->x, $absolute_before->x, 'x not changed');
183 is($absolute->y, ($absolute_before->y + 10), 'moved 10 px up');
184 is($absolute->width, $absolute_before->width, 'width not changed');
185 is($absolute->height, $absolute_before->height, 'height not changed');
187 $absolute_before = $absolute;
190 ######################################################################
191 # 6) test moving floating containers with a specific amount of px
192 ######################################################################
194 cmd 'move left 20 px';
196 ($absolute, $top) = $floatwin->rect;
198 is($absolute->x, ($absolute_before->x - 20), 'moved 20 px to the left');
199 is($absolute->y, $absolute_before->y, 'y not changed');
200 is($absolute->width, $absolute_before->width, 'width not changed');
201 is($absolute->height, $absolute_before->height, 'height not changed');