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