2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
5 # Tests the workspace_layout config option.
11 use File::Temp qw(tempfile tempdir);
12 use X11::XCB qw(:all);
13 use X11::XCB::Connection;
15 my $x = X11::XCB::Connection->new;
17 # assuming we are run by complete-run.pl
18 my $i3_path = abs_path("../i3");
20 #####################################################################
21 # 1: check that with an empty config, cons are place next to each
22 # other and no split containers are created
23 #####################################################################
25 my $socketpath = File::Temp::tempnam('/tmp', 'i3-test-socket-');
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";
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);
38 # force update of the cached socket path in lib/i3test
41 diag("pid = " . $process->pid);
43 my $tmp = fresh_workspace;
45 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
47 my $first = open_standard_window($x);
48 my $second = open_standard_window($x);
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');
55 exit_gracefully($process->pid);
57 #####################################################################
58 # 2: set workspace_layout stacked, check that when opening two cons,
59 # they end up in a stacked con
60 #####################################################################
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";
70 $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
71 $process = Proc::Background->new($i3cmd);
74 # force update of the cached socket path in lib/i3test
77 diag("pid = " . $process->pid);
79 $tmp = fresh_workspace;
81 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
83 $first = open_standard_window($x);
84 $second = open_standard_window($x);
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');
91 #####################################################################
92 # 3: focus parent, open two new cons, check that they end up in a stacked
94 #####################################################################
97 my $right_top = open_standard_window($x);
98 my $right_bot = open_standard_window($x);
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');
105 #####################################################################
106 # 4: move one of the cons to the right, check that it will end up in
108 #####################################################################
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');
118 #####################################################################
119 # 5: move it to the left again, check that the stacked con is deleted
120 #####################################################################
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');
129 #####################################################################
130 # 6: move it to a different workspace, check that it ends up in a
132 #####################################################################
134 my $otmp = get_unused_workspace;
136 cmd "move workspace $otmp";
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');
143 @content = @{get_ws_content($otmp)};
144 is(@content, 1, 'one con on target workspace');
145 is($content[0]->{layout}, 'stacked', 'layout stacked');
147 exit_gracefully($process->pid);