]> git.sur5r.net Git - i3/i3/blob - testcases/t/24-move.t
Go down the tree when moving windows, add testcase for moving
[i3/i3] / testcases / t / 24-move.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests moving. Basically, there are four different code-paths:
5 # 1) move a container which cannot be moved (single container on a workspace)
6 # 2) move a container before another single container
7 # 3) move a container inside another container
8 # 4) move a container in a different direction so that we need to go up in tree
9 #
10 use i3test tests => 16;
11 use X11::XCB qw(:all);
12 use v5.10;
13
14 my $i3 = i3("/tmp/nestedcons");
15
16 my $tmp = get_unused_workspace();
17 $i3->command("workspace $tmp")->recv;
18
19 ######################################################################
20 # 1) move a container which cannot be moved
21 ######################################################################
22
23 $i3->command('open')->recv;
24
25 my $old_content = get_ws_content($tmp);
26 is(@{$old_content}, 1, 'one container on this workspace');
27
28 my $first = $old_content->[0]->{id};
29
30 $i3->command('move before h')->recv;
31 $i3->command('move before v')->recv;
32 $i3->command('move after v')->recv;
33 $i3->command('move after h')->recv;
34
35 my $content = get_ws_content($tmp);
36 is_deeply($old_content, $content, 'workspace unmodified after useless moves');
37
38 ######################################################################
39 # 2) move a container before another single container
40 ######################################################################
41
42 $i3->command('open')->recv;
43 $content = get_ws_content($tmp);
44 is(@{$content}, 2, 'two containers on this workspace');
45 my $second = $content->[1]->{id};
46
47 is($content->[0]->{id}, $first, 'first container unmodified');
48
49 # Move the second container before the first one (→ swap them)
50 $i3->command('move before h')->recv;
51 $content = get_ws_content($tmp);
52 is($content->[0]->{id}, $second, 'first container modified');
53
54 # We should not be able to move any further
55 $i3->command('move before h')->recv;
56 $content = get_ws_content($tmp);
57 is($content->[0]->{id}, $second, 'first container unmodified');
58
59 # Now move in the other direction
60 $i3->command('move after h')->recv;
61 $content = get_ws_content($tmp);
62 is($content->[0]->{id}, $first, 'first container modified');
63
64 # We should not be able to move any further
65 $i3->command('move after h')->recv;
66 $content = get_ws_content($tmp);
67 is($content->[0]->{id}, $first, 'first container unmodified');
68
69 ######################################################################
70 # 3) move a container inside another container
71 ######################################################################
72
73 # Split the current (second) container and create a new container on workspace
74 # level. Our layout looks like this now:
75 # --------------------------
76 # |       | second |       |
77 # | first | ------ | third |
78 # |       |        |       |
79 # --------------------------
80 $i3->command('split v')->recv;
81 $i3->command('level up')->recv;
82 $i3->command('open')->recv;
83
84 $content = get_ws_content($tmp);
85 is(@{$content}, 3, 'three containers on this workspace');
86 my $third = $content->[2]->{id};
87
88 $i3->command('move before h')->recv;
89 $content = get_ws_content($tmp);
90 is(@{$content}, 2, 'only two containers on this workspace');
91 my $nodes = $content->[1]->{nodes};
92 is($nodes->[0]->{id}, $second, 'second container on top');
93 is($nodes->[1]->{id}, $third, 'third container on bottom');
94
95 ######################################################################
96 # move it inside the split container
97 ######################################################################
98
99 $i3->command('move before v')->recv;
100 $nodes = get_ws_content($tmp)->[1]->{nodes};
101 is($nodes->[0]->{id}, $third, 'third container on top');
102 is($nodes->[1]->{id}, $second, 'second container on bottom');
103
104 # move it outside again
105 $i3->command('move before h')->recv;
106 $content = get_ws_content($tmp);
107 is(@{$content}, 3, 'three nodes on this workspace');
108
109 $i3->command('move after h')->recv;
110 $content = get_ws_content($tmp);
111 is(@{$content}, 2, 'two nodes on this workspace');
112
113 diag( "Testing i3, Perl $], $^X" );