2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Checks if the 'move [window/container] to workspace' command works correctly
21 my $i3 = i3(get_socket_path());
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);
27 sub move_workspace_test {
30 my $tmp = get_unused_workspace();
31 my $tmp2 = get_unused_workspace();
34 is_num_children($tmp, 0, 'no containers yet');
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');
40 cmd "workspace $tmp2";
41 is_num_children($tmp2, 0, 'no containers on second ws yet');
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);
50 is($focus->[0], $second, 'same container on different ws');
52 ($nodes, $focus) = get_ws_content($tmp);
53 ok($nodes->[0]->{focused}, 'first container focused on first ws');
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');
62 ################################################################################
63 # Check that 'move to workspace number <number>' works to move a window to
64 # named workspaces which start with <number>.
65 ################################################################################
67 cmd 'workspace 13: meh';
69 is_num_children('13: meh', 1, 'one container on 13: meh');
71 ok(!workspace_exists('13'), 'workspace 13 does not exist yet');
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');
80 ok(!workspace_exists('13'), 'workspace 13 does still not exist');
82 ###################################################################
83 # check if 'move workspace next' and 'move workspace prev' work
84 ###################################################################
86 # Open two containers on the first workspace, one container on the second
87 # workspace. Because the workspaces are named, they will be sorted by order of
89 my $tmp = get_unused_workspace();
90 my $tmp2 = get_unused_workspace();
92 is_num_children($tmp, 0, 'no containers yet');
93 my $first = open_empty_con($i3);
94 my $second = open_empty_con($i3);
95 is_num_children($tmp, 2, 'two containers');
97 cmd "workspace $tmp2";
98 is_num_children($tmp2, 0, 'no containers yet');
99 my $third = open_empty_con($i3);
100 is_num_children($tmp2, 1, 'one container on second ws');
102 # go back to the first workspace, move one of the containers to the next one
103 cmd "workspace $tmp";
104 cmd 'move workspace next';
105 is_num_children($tmp, 1, 'one container on first ws');
106 is_num_children($tmp2, 2, 'two containers on second ws');
108 # go to the second workspace and move two containers to the first one
109 cmd "workspace $tmp2";
110 cmd 'move workspace prev';
111 cmd 'move workspace prev';
112 is_num_children($tmp, 3, 'three containers on first ws');
113 is_num_children($tmp2, 0, 'no containers on second ws');
115 ###################################################################
116 # check if 'move workspace current' works
117 ###################################################################
119 $tmp = get_unused_workspace();
120 $tmp2 = get_unused_workspace();
122 cmd "workspace $tmp";
123 $first = open_window(name => 'win-name');
124 is_num_children($tmp, 1, 'one container on first ws');
126 cmd "workspace $tmp2";
127 is_num_children($tmp2, 0, 'no containers yet');
129 cmd qq|[title="win-name"] move workspace $tmp2|;
130 is_num_children($tmp2, 1, 'one container on second ws');
132 cmd qq|[title="win-name"] move workspace $tmp|;
133 is_num_children($tmp2, 0, 'no containers on second ws');
135 ###################################################################
136 # check if floating cons are moved to new workspaces properly
137 # (that is, if they are floating on the target ws, too)
138 ###################################################################
140 $tmp = get_unused_workspace();
141 $tmp2 = get_unused_workspace();
142 cmd "workspace $tmp";
145 cmd "floating toggle";
147 my $ws = get_ws($tmp);
148 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
149 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
151 cmd "move workspace $tmp2";
154 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
155 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
157 ################################################################################
158 # Check that 'move workspace number' works correctly.
159 ################################################################################
161 $tmp = get_unused_workspace();
166 is_num_children('16', 1, 'one node on ws 16');
168 cmd "workspace $tmp";
170 cmd 'move workspace number 16';
171 is_num_children('16', 2, 'two nodes on ws 16');
173 ok(!workspace_exists('17'), 'workspace 17 does not exist yet');
175 cmd 'move workspace number 17';
176 ok(workspace_exists('17'), 'workspace 17 created by moving');
177 is(@{get_ws('17')->{nodes}}, 1, 'one node on ws 16');