]> git.sur5r.net Git - i3/i3/blob - testcases/t/132-move-workspace.t
Merge branch 'fix-float-close'
[i3/i3] / testcases / t / 132-move-workspace.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Checks if the 'move 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 my $x = X11::XCB::Connection->new;
13 $x->root->warp_pointer(0, 0);
14
15 my $tmp = get_unused_workspace();
16 my $tmp2 = get_unused_workspace();
17 cmd "workspace $tmp";
18
19 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
20
21 my $first = open_empty_con($i3);
22 my $second = open_empty_con($i3);
23 ok(@{get_ws_content($tmp)} == 2, 'two containers on first ws');
24
25 cmd "workspace $tmp2";
26 ok(@{get_ws_content($tmp2)} == 0, 'no containers on second ws yet');
27
28 cmd "workspace $tmp";
29
30 cmd "move workspace $tmp2";
31 ok(@{get_ws_content($tmp)} == 1, 'one container on first ws anymore');
32 ok(@{get_ws_content($tmp2)} == 1, 'one container on second ws');
33 my ($nodes, $focus) = get_ws_content($tmp2);
34
35 is($focus->[0], $second, 'same container on different ws');
36
37 ($nodes, $focus) = get_ws_content($tmp);
38 ok($nodes->[0]->{focused}, 'first container focused on first ws');
39
40 ###################################################################
41 # check if 'move workspace next' and 'move workspace prev' work
42 ###################################################################
43
44 # Open two containers on the first workspace, one container on the second
45 # workspace. Because the workspaces are named, they will be sorted by order of
46 # creation.
47 $tmp = get_unused_workspace();
48 $tmp2 = get_unused_workspace();
49 cmd "workspace $tmp";
50 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
51 $first = open_empty_con($i3);
52 $second = open_empty_con($i3);
53 ok(@{get_ws_content($tmp)} == 2, 'two containers on first ws');
54
55 cmd "workspace $tmp2";
56 ok(@{get_ws_content($tmp2)} == 0, 'no containers yet');
57 my $third = open_empty_con($i3);
58 ok(@{get_ws_content($tmp2)} == 1, 'one container on second ws');
59
60 # go back to the first workspace, move one of the containers to the next one
61 cmd "workspace $tmp";
62 cmd 'move workspace next';
63 ok(@{get_ws_content($tmp)} == 1, 'one container on first ws');
64 ok(@{get_ws_content($tmp2)} == 2, 'two containers on second ws');
65
66 # go to the second workspace and move two containers to the first one
67 cmd "workspace $tmp2";
68 cmd 'move workspace prev';
69 cmd 'move workspace prev';
70 ok(@{get_ws_content($tmp)} == 3, 'three containers on first ws');
71 ok(@{get_ws_content($tmp2)} == 0, 'no containers on second ws');
72
73 ###################################################################
74 # check if floating cons are moved to new workspaces properly
75 # (that is, if they are floating on the target ws, too)
76 ###################################################################
77
78 $tmp = get_unused_workspace();
79 $tmp2 = get_unused_workspace();
80 cmd "workspace $tmp";
81
82 cmd "open";
83 cmd "floating toggle";
84
85 my $ws = get_ws($tmp);
86 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
87 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
88
89 cmd "move workspace $tmp2";
90
91 $ws = get_ws($tmp2);
92 is(@{$ws->{nodes}}, 0, 'no nodes on workspace');
93 is(@{$ws->{floating_nodes}}, 1, 'one floating node on workspace');
94
95 done_testing;