]> git.sur5r.net Git - i3/i3/blob - testcases/t/132-move-workspace.t
a4f6b6082ad7da6f4a4ebef73241aad0ba402899
[i3/i3] / testcases / t / 132-move-workspace.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Checks if the 'move [window/container] to workspace' command works correctly
18 #
19 use i3test;
20
21 my $i3 = i3(get_socket_path());
22
23 # We move the pointer out of our way to avoid a bug where the focus will
24 # be set to the window under the cursor
25 $x->root->warp_pointer(0, 0);
26
27 sub move_workspace_test {
28     my ($movecmd) = @_;
29
30     my $tmp = get_unused_workspace();
31     my $tmp2 = get_unused_workspace();
32     cmd "workspace $tmp";
33
34     is_num_children($tmp, 0, 'no containers yet');
35
36     my $first = open_empty_con($i3);
37     my $second = open_empty_con($i3);
38     is_num_children($tmp, 2, 'two containers on first ws');
39
40     cmd "workspace $tmp2";
41     is_num_children($tmp2, 0, 'no containers on second ws yet');
42
43     cmd "workspace $tmp";
44
45     cmd "$movecmd $tmp2";
46     is_num_children($tmp, 1, 'one container on first ws anymore');
47     is_num_children($tmp2, 1, 'one container on second ws');
48     my ($nodes, $focus) = get_ws_content($tmp2);
49
50     is($focus->[0], $second, 'same container on different ws');
51
52     ($nodes, $focus) = get_ws_content($tmp);
53     ok($nodes->[0]->{focused}, 'first container focused on first ws');
54 }
55
56 move_workspace_test('move workspace');  # supported for legacy reasons
57 move_workspace_test('move to workspace');
58 # Those are just synonyms and more verbose ways of saying the same thing:
59 move_workspace_test('move window to workspace');
60 move_workspace_test('move container to workspace');
61
62 ################################################################################
63 # Check that 'move to workspace number <number>' works to move a window to
64 # named workspaces which start with <number>.
65 ################################################################################
66
67 cmd 'workspace 13: meh';
68 cmd 'open';
69 is_num_children('13: meh', 1, 'one container on 13: meh');
70
71 ok(!workspace_exists('13'), 'workspace 13 does not exist yet');
72
73 cmd 'workspace 12';
74 cmd 'open';
75
76 cmd 'move to workspace number 13';
77 is_num_children('13: meh', 2, 'one container on 13: meh');
78 is_num_children('12', 0, 'no container on 12 anymore');
79
80 ok(!workspace_exists('13'), 'workspace 13 does still not exist');
81
82 ################################################################################
83 # Check that 'move to workspace number <number><name>' works to move a window to
84 # named workspaces which start with <number>.
85 ################################################################################
86
87 cmd 'workspace 15: meh';
88 cmd 'open';
89 is_num_children('15: meh', 1, 'one container on 15: meh');
90
91 ok(!workspace_exists('15'), 'workspace 15 does not exist yet');
92 ok(!workspace_exists('15: duh'), 'workspace 15: duh does not exist yet');
93
94 cmd 'workspace 14';
95 cmd 'open';
96
97 cmd 'move to workspace number 15: duh';
98 is_num_children('15: meh', 2, 'two containers on 15: meh');
99 is_num_children('14', 0, 'no container on 14 anymore');
100
101 ok(!workspace_exists('15'), 'workspace 15 does still not exist');
102 ok(!workspace_exists('15: duh'), 'workspace 15 does still not exist');
103
104 ###################################################################
105 # check if 'move workspace next' and 'move workspace prev' work
106 ###################################################################
107
108 # Open two containers on the first workspace, one container on the second
109 # workspace. Because the workspaces are named, they will be sorted by order of
110 # creation.
111 my $tmp = get_unused_workspace();
112 my $tmp2 = get_unused_workspace();
113 cmd "workspace $tmp";
114 is_num_children($tmp, 0, 'no containers yet');
115 my $first = open_empty_con($i3);
116 my $second = open_empty_con($i3);
117 is_num_children($tmp, 2, 'two containers');
118
119 cmd "workspace $tmp2";
120 is_num_children($tmp2, 0, 'no containers yet');
121 my $third = open_empty_con($i3);
122 is_num_children($tmp2, 1, 'one container on second ws');
123
124 # go back to the first workspace, move one of the containers to the next one
125 cmd "workspace $tmp";
126 cmd 'move workspace next';
127 is_num_children($tmp, 1, 'one container on first ws');
128 is_num_children($tmp2, 2, 'two containers on second ws');
129
130 # go to the second workspace and move two containers to the first one
131 cmd "workspace $tmp2";
132 cmd 'move workspace prev';
133 cmd 'move workspace prev';
134 is_num_children($tmp, 3, 'three containers on first ws');
135 is_num_children($tmp2, 0, 'no containers on second ws');
136
137 ###################################################################
138 # check if 'move workspace current' works
139 ###################################################################
140
141 $tmp = get_unused_workspace();
142 $tmp2 = get_unused_workspace();
143
144 cmd "workspace $tmp";
145 $first = open_window(name => 'win-name');
146 is_num_children($tmp, 1, 'one container on first ws');
147
148 cmd "workspace $tmp2";
149 is_num_children($tmp2, 0, 'no containers yet');
150
151 cmd qq|[title="win-name"] move workspace $tmp2|;
152 is_num_children($tmp2, 1, 'one container on second ws');
153
154 cmd qq|[title="win-name"] move workspace $tmp|;
155 is_num_children($tmp2, 0, 'no containers on second ws');
156
157 ###################################################################
158 # check if floating cons are moved to new workspaces properly
159 # (that is, if they are floating on the target ws, too)
160 ###################################################################
161
162 $tmp = get_unused_workspace();
163 $tmp2 = get_unused_workspace();
164 cmd "workspace $tmp";
165
166 cmd "open";
167 cmd "floating toggle";
168
169 my $ws = get_ws($tmp);
170 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
171 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
172
173 cmd "move workspace $tmp2";
174
175 $ws = get_ws($tmp2);
176 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
177 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
178
179 ################################################################################
180 # Check that 'move workspace number' works correctly.
181 ################################################################################
182
183 $tmp = get_unused_workspace();
184 cmd 'open';
185
186 cmd 'workspace 16';
187 cmd 'open';
188 is_num_children('16', 1, 'one node on ws 16');
189
190 cmd "workspace $tmp";
191 cmd 'open';
192 cmd 'move workspace number 16';
193 is_num_children('16', 2, 'two nodes on ws 16');
194
195 ok(!workspace_exists('17'), 'workspace 17 does not exist yet');
196 cmd 'open';
197 cmd 'move workspace number 17';
198 ok(workspace_exists('17'), 'workspace 17 created by moving');
199 is(@{get_ws('17')->{nodes}}, 1, 'one node on ws 16');
200
201 done_testing;