2 # vim:ts=4:sw=4:expandtab
4 # Checks if the 'move [window/container] to workspace' command works correctly
8 my $i3 = i3(get_socket_path());
10 # We move the pointer out of our way to avoid a bug where the focus will
11 # be set to the window under the cursor
12 $x->root->warp_pointer(0, 0);
14 sub move_workspace_test {
17 my $tmp = get_unused_workspace();
18 my $tmp2 = get_unused_workspace();
21 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
23 my $first = open_empty_con($i3);
24 my $second = open_empty_con($i3);
25 ok(@{get_ws_content($tmp)} == 2, 'two containers on first ws');
27 cmd "workspace $tmp2";
28 ok(@{get_ws_content($tmp2)} == 0, 'no containers on second ws yet');
33 ok(@{get_ws_content($tmp)} == 1, 'one container on first ws anymore');
34 ok(@{get_ws_content($tmp2)} == 1, 'one container on second ws');
35 my ($nodes, $focus) = get_ws_content($tmp2);
37 is($focus->[0], $second, 'same container on different ws');
39 ($nodes, $focus) = get_ws_content($tmp);
40 ok($nodes->[0]->{focused}, 'first container focused on first ws');
43 move_workspace_test('move workspace'); # supported for legacy reasons
44 move_workspace_test('move to workspace');
45 # Those are just synonyms and more verbose ways of saying the same thing:
46 move_workspace_test('move window to workspace');
47 move_workspace_test('move container to workspace');
49 ################################################################################
50 # Check that 'move to workspace number <number>' works to move a window to
51 # named workspaces which start with <number>.
52 ################################################################################
54 cmd 'workspace 13: meh';
56 ok(@{get_ws_content('13: meh')} == 1, 'one container on 13: meh');
58 ok(!workspace_exists('13'), 'workspace 13 does not exist yet');
63 cmd 'move to workspace number 13';
64 ok(@{get_ws_content('13: meh')} == 2, 'two containers on 13: meh');
65 ok(@{get_ws_content('12')} == 0, 'no container on 12 anymore');
67 ok(!workspace_exists('13'), 'workspace 13 does still not exist');
69 ###################################################################
70 # check if 'move workspace next' and 'move workspace prev' work
71 ###################################################################
73 # Open two containers on the first workspace, one container on the second
74 # workspace. Because the workspaces are named, they will be sorted by order of
76 my $tmp = get_unused_workspace();
77 my $tmp2 = get_unused_workspace();
79 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
80 my $first = open_empty_con($i3);
81 my $second = open_empty_con($i3);
82 ok(@{get_ws_content($tmp)} == 2, 'two containers on first ws');
84 cmd "workspace $tmp2";
85 ok(@{get_ws_content($tmp2)} == 0, 'no containers yet');
86 my $third = open_empty_con($i3);
87 ok(@{get_ws_content($tmp2)} == 1, 'one container on second ws');
89 # go back to the first workspace, move one of the containers to the next one
91 cmd 'move workspace next';
92 ok(@{get_ws_content($tmp)} == 1, 'one container on first ws');
93 ok(@{get_ws_content($tmp2)} == 2, 'two containers on second ws');
95 # go to the second workspace and move two containers to the first one
96 cmd "workspace $tmp2";
97 cmd 'move workspace prev';
98 cmd 'move workspace prev';
99 ok(@{get_ws_content($tmp)} == 3, 'three containers on first ws');
100 ok(@{get_ws_content($tmp2)} == 0, 'no containers on second ws');
102 ###################################################################
103 # check if 'move workspace current' works
104 ###################################################################
106 $tmp = get_unused_workspace();
107 $tmp2 = get_unused_workspace();
109 cmd "workspace $tmp";
110 $first = open_window(name => 'win-name');
111 ok(@{get_ws_content($tmp)} == 1, 'one container on first ws');
113 cmd "workspace $tmp2";
114 ok(@{get_ws_content($tmp2)} == 0, 'no containers yet');
116 cmd qq|[title="win-name"] move workspace $tmp2|;
117 ok(@{get_ws_content($tmp2)} == 1, 'one container on second ws');
119 cmd qq|[title="win-name"] move workspace $tmp|;
120 ok(@{get_ws_content($tmp2)} == 0, 'no containers on second ws');
122 ###################################################################
123 # check if floating cons are moved to new workspaces properly
124 # (that is, if they are floating on the target ws, too)
125 ###################################################################
127 $tmp = get_unused_workspace();
128 $tmp2 = get_unused_workspace();
129 cmd "workspace $tmp";
132 cmd "floating toggle";
134 my $ws = get_ws($tmp);
135 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
136 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
138 cmd "move workspace $tmp2";
141 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
142 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');