]> git.sur5r.net Git - i3/i3/blob - testcases/t/67-workspace_layout.t
Merge branch 'tree' into next
[i3/i3] / testcases / t / 67-workspace_layout.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
4 #
5 # Tests the workspace_layout config option.
6 #
7
8 use i3test;
9 use Cwd qw(abs_path);
10 use Proc::Background;
11 use File::Temp qw(tempfile tempdir);
12 use X11::XCB qw(:all);
13 use X11::XCB::Connection;
14
15 my $x = X11::XCB::Connection->new;
16
17 # assuming we are run by complete-run.pl
18 my $i3_path = abs_path("../i3");
19
20 #####################################################################
21 # 1: check that with an empty config, cons are place next to each
22 # other and no split containers are created
23 #####################################################################
24
25 my $socketpath = File::Temp::tempnam('/tmp', 'i3-test-socket-');
26
27 my ($fh, $tmpfile) = tempfile();
28 say $fh "# i3 config file (v4)";
29 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
30 say $fh "ipc-socket $socketpath";
31 close($fh);
32
33 diag("Starting i3");
34 my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
35 my $process = Proc::Background->new($i3cmd);
36 sleep 1;
37
38 # force update of the cached socket path in lib/i3test
39 get_socket_path(0);
40
41 diag("pid = " . $process->pid);
42
43 my $tmp = fresh_workspace;
44
45 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
46
47 my $first = open_standard_window($x);
48 my $second = open_standard_window($x);
49
50 is($x->input_focus, $second->id, 'second window focused');
51 ok(@{get_ws_content($tmp)} == 2, 'two containers opened');
52 isnt($content[0]->{layout}, 'stacked', 'layout not stacked');
53 isnt($content[1]->{layout}, 'stacked', 'layout not stacked');
54
55 exit_gracefully($process->pid);
56
57 #####################################################################
58 # 2: set workspace_layout stacked, check that when opening two cons,
59 # they end up in a stacked con
60 #####################################################################
61
62 ($fh, $tmpfile) = tempfile();
63 say $fh "# i3 config file (v4)";
64 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
65 say $fh "ipc-socket $socketpath";
66 say $fh "workspace_layout stacked";
67 close($fh);
68
69 diag("Starting i3");
70 $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
71 $process = Proc::Background->new($i3cmd);
72 sleep 1;
73
74 # force update of the cached socket path in lib/i3test
75 get_socket_path(0);
76
77 diag("pid = " . $process->pid);
78
79 $tmp = fresh_workspace;
80
81 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
82
83 $first = open_standard_window($x);
84 $second = open_standard_window($x);
85
86 is($x->input_focus, $second->id, 'second window focused');
87 my @content = @{get_ws_content($tmp)};
88 ok(@content == 1, 'one con at workspace level');
89 is($content[0]->{layout}, 'stacked', 'layout stacked');
90
91 #####################################################################
92 # 3: focus parent, open two new cons, check that they end up in a stacked
93 # con
94 #####################################################################
95
96 cmd 'focus parent';
97 my $right_top = open_standard_window($x);
98 my $right_bot = open_standard_window($x);
99
100 @content = @{get_ws_content($tmp)};
101 is(@content, 2, 'two cons at workspace level after focus parent');
102 is($content[0]->{layout}, 'stacked', 'layout stacked');
103 is($content[1]->{layout}, 'stacked', 'layout stacked');
104
105 #####################################################################
106 # 4: move one of the cons to the right, check that it will end up in
107 # a stacked con
108 #####################################################################
109
110 cmd 'move right';
111
112 @content = @{get_ws_content($tmp)};
113 is(@content, 3, 'three cons at workspace level after move');
114 is($content[0]->{layout}, 'stacked', 'layout stacked');
115 is($content[1]->{layout}, 'stacked', 'layout stacked');
116 is($content[2]->{layout}, 'stacked', 'layout stacked');
117
118 #####################################################################
119 # 5: move it to the left again, check that the stacked con is deleted
120 #####################################################################
121
122 cmd 'move left';
123
124 @content = @{get_ws_content($tmp)};
125 is(@content, 2, 'two cons at workspace level after moving back');
126 is($content[0]->{layout}, 'stacked', 'layout stacked');
127 is($content[1]->{layout}, 'stacked', 'layout stacked');
128
129 #####################################################################
130 # 6: move it to a different workspace, check that it ends up in a
131 # stacked con
132 #####################################################################
133
134 my $otmp = get_unused_workspace;
135
136 cmd "move workspace $otmp";
137
138 @content = @{get_ws_content($tmp)};
139 is(@content, 2, 'still two cons on this workspace');
140 is($content[0]->{layout}, 'stacked', 'layout stacked');
141 is($content[1]->{layout}, 'stacked', 'layout stacked');
142
143 @content = @{get_ws_content($otmp)};
144 is(@content, 1, 'one con on target workspace');
145 is($content[0]->{layout}, 'stacked', 'layout stacked');
146
147 exit_gracefully($process->pid);
148
149 done_testing;