]> git.sur5r.net Git - i3/i3/blob - testcases/t/132-move-workspace.t
add banner.svg to contrib/
[i3/i3] / testcases / t / 132-move-workspace.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Checks if the 'move [window/container] to workspace' command works correctly
5 #
6 use i3test;
7
8 my $i3 = i3(get_socket_path());
9
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);
13
14 sub move_workspace_test {
15     my ($movecmd) = @_;
16
17     my $tmp = get_unused_workspace();
18     my $tmp2 = get_unused_workspace();
19     cmd "workspace $tmp";
20
21     ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
22
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');
26
27     cmd "workspace $tmp2";
28     ok(@{get_ws_content($tmp2)} == 0, 'no containers on second ws yet');
29
30     cmd "workspace $tmp";
31
32     cmd "$movecmd $tmp2";
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);
36
37     is($focus->[0], $second, 'same container on different ws');
38
39     ($nodes, $focus) = get_ws_content($tmp);
40     ok($nodes->[0]->{focused}, 'first container focused on first ws');
41 }
42
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');
48
49 ################################################################################
50 # Check that 'move to workspace number <number>' works to move a window to
51 # named workspaces which start with <number>.
52 ################################################################################
53
54 cmd 'workspace 13: meh';
55 cmd 'open';
56 ok(@{get_ws_content('13: meh')} == 1, 'one container on 13: meh');
57
58 ok(!workspace_exists('13'), 'workspace 13 does not exist yet');
59
60 cmd 'workspace 12';
61 cmd 'open';
62
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');
66
67 ok(!workspace_exists('13'), 'workspace 13 does still not exist');
68
69 ###################################################################
70 # check if 'move workspace next' and 'move workspace prev' work
71 ###################################################################
72
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
75 # creation.
76 my $tmp = get_unused_workspace();
77 my $tmp2 = get_unused_workspace();
78 cmd "workspace $tmp";
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');
83
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');
88
89 # go back to the first workspace, move one of the containers to the next one
90 cmd "workspace $tmp";
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');
94
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');
101
102 ###################################################################
103 # check if floating cons are moved to new workspaces properly
104 # (that is, if they are floating on the target ws, too)
105 ###################################################################
106
107 $tmp = get_unused_workspace();
108 $tmp2 = get_unused_workspace();
109 cmd "workspace $tmp";
110
111 cmd "open";
112 cmd "floating toggle";
113
114 my $ws = get_ws($tmp);
115 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
116 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
117
118 cmd "move workspace $tmp2";
119
120 $ws = get_ws($tmp2);
121 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
122 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
123
124 done_testing;