]> git.sur5r.net Git - i3/i3/blob - testcases/t/124-move.t
cmdparse.l: [^t] is enough (Thanks f8l)
[i3/i3] / testcases / t / 124-move.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
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
9 #
10 use i3test;
11
12 my $i3 = i3(get_socket_path());
13
14 my $tmp = fresh_workspace;
15
16 ######################################################################
17 # 1) move a container which cannot be moved
18 ######################################################################
19
20 cmd 'open';
21
22 my $old_content = get_ws_content($tmp);
23 is(@{$old_content}, 1, 'one container on this workspace');
24
25 my $first = $old_content->[0]->{id};
26
27 cmd 'move left';
28 cmd 'move right';
29 cmd 'move up';
30 cmd 'move down';
31
32 my $content = get_ws_content($tmp);
33 is_deeply($old_content, $content, 'workspace unmodified after useless moves');
34
35 ######################################################################
36 # 2) move a container before another single container
37 ######################################################################
38
39 cmd 'open';
40 $content = get_ws_content($tmp);
41 is(@{$content}, 2, 'two containers on this workspace');
42 my $second = $content->[1]->{id};
43
44 is($content->[0]->{id}, $first, 'first container unmodified');
45
46 # Move the second container before the first one (→ swap them)
47 cmd 'move left';
48 $content = get_ws_content($tmp);
49 is($content->[0]->{id}, $second, 'first container modified');
50
51 # We should not be able to move any further
52 cmd 'move left';
53 $content = get_ws_content($tmp);
54 is($content->[0]->{id}, $second, 'first container unmodified');
55
56 # Now move in the other direction
57 cmd 'move right';
58 $content = get_ws_content($tmp);
59 is($content->[0]->{id}, $first, 'first container modified');
60
61 # We should not be able to move any further
62 cmd 'move right';
63 $content = get_ws_content($tmp);
64 is($content->[0]->{id}, $first, 'first container unmodified');
65
66 ######################################################################
67 # 3) move a container inside another container
68 ######################################################################
69
70 # Split the current (second) container and create a new container on workspace
71 # level. Our layout looks like this now:
72 # --------------------------
73 # |       | second |       |
74 # | first | ------ | third |
75 # |       |        |       |
76 # --------------------------
77 cmd 'split v';
78 cmd 'focus parent';
79 cmd 'open';
80
81 $content = get_ws_content($tmp);
82 is(@{$content}, 3, 'three containers on this workspace');
83 my $third = $content->[2]->{id};
84
85 cmd 'move left';
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');
91
92 ######################################################################
93 # move it inside the split container
94 ######################################################################
95
96 cmd 'move up';
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');
100
101 # move it outside again
102 cmd 'move left';
103 $content = get_ws_content($tmp);
104 is(@{$content}, 3, 'three nodes on this workspace');
105
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
108 cmd 'move right';
109 $content = get_ws_content($tmp);
110 is(@{$content}, 2, 'two nodes on this workspace');
111
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 ######################################################################
117
118 my $otmp = fresh_workspace;
119
120 cmd "open";
121 cmd "open";
122 cmd "split v";
123 cmd "open";
124 cmd 'focus left';
125 cmd "split v";
126 cmd "open";
127 cmd "move right";
128 cmd 'focus left';
129 cmd "move right";
130
131 $content = get_ws_content($otmp);
132 is(@{$content}, 1, 'only one nodes on this workspace');
133
134 ######################################################################
135 # 5) test moving floating containers.
136 ######################################################################
137
138 $tmp = fresh_workspace;
139 my $floatwin = open_floating_window;
140 my ($absolute_before, $top_before) = $floatwin->rect;
141
142 cmd 'move left';
143
144 my ($absolute, $top) = $floatwin->rect;
145
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');
150
151 $absolute_before = $absolute;
152 $top_before = $top;
153
154 cmd 'move right';
155
156 ($absolute, $top) = $floatwin->rect;
157
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');
162
163 $absolute_before = $absolute;
164 $top_before = $top;
165
166 cmd 'move up';
167
168 ($absolute, $top) = $floatwin->rect;
169
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');
174
175 $absolute_before = $absolute;
176 $top_before = $top;
177
178 cmd 'move down';
179
180 ($absolute, $top) = $floatwin->rect;
181
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');
186
187 $absolute_before = $absolute;
188 $top_before = $top;
189
190 ######################################################################
191 # 6) test moving floating containers with a specific amount of px
192 ######################################################################
193
194 cmd 'move left 20 px';
195
196 ($absolute, $top) = $floatwin->rect;
197
198 is($absolute->x, ($absolute_before->x - 20), 'moved 10 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');
202
203
204
205 done_testing;