2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
7 use X11::XCB::Connection;
11 use File::Temp qw(tempfile tempdir);
13 my $x = X11::XCB::Connection->new;
15 # assuming we are run by complete-run.pl
16 my $i3_path = abs_path("../i3");
18 ##############################################################
19 # 1: test the following directive:
20 # for_window [class="borderless"] border none
21 # by first creating a window with a different class (should get
22 # the normal border), then creating a window with the class
23 # "borderless" (should get no border)
24 ##############################################################
26 my $socketpath = File::Temp::tempnam('/tmp', 'i3-test-socket-');
28 my ($fh, $tmpfile) = tempfile();
29 say $fh "# i3 config file (v4)";
30 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
31 say $fh "ipc-socket $socketpath";
32 say $fh q|for_window [class="borderless"] border none|;
36 my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
37 my $process = Proc::Background->new($i3cmd);
40 # force update of the cached socket path in lib/i3test
43 my $tmp = fresh_workspace;
45 my $window = $x->root->create_child(
46 class => WINDOW_CLASS_INPUT_OUTPUT,
47 rect => [ 0, 0, 30, 30 ],
48 background_color => '#00ff00',
51 $window->name('Border window');
55 my @content = @{get_ws_content($tmp)};
56 cmp_ok(@content, '==', 1, 'one node on this workspace now');
57 is($content[0]->{border}, 'normal', 'normal border');
62 my @content = @{get_ws_content($tmp)};
63 cmp_ok(@content, '==', 0, 'no more nodes');
64 diag('content = '. Dumper(\@content));
66 $window = $x->root->create_child(
67 class => WINDOW_CLASS_INPUT_OUTPUT,
68 rect => [ 0, 0, 30, 30 ],
69 background_color => '#00ff00',
74 # TODO: move this to X11::XCB::Window
76 my ($id, $class, $instance) = @_;
78 # Add a _NET_WM_STRUT_PARTIAL hint
79 my $atomname = $x->atom(name => 'WM_CLASS');
80 my $atomtype = $x->atom(name => 'STRING');
88 length($class) + length($instance) + 2,
89 "$instance\x00$class\x00"
93 set_wm_class($window->id, 'borderless', 'borderless');
94 $window->name('Borderless window');
98 @content = @{get_ws_content($tmp)};
99 cmp_ok(@content, '==', 1, 'one node on this workspace now');
100 is($content[0]->{border}, 'none', 'no border');
105 @content = @{get_ws_content($tmp)};
106 cmp_ok(@content, '==', 0, 'no more nodes');
108 exit_gracefully($process->pid);
110 ##############################################################
111 # 2: match on the title, check if for_window is really executed
113 ##############################################################
115 ($fh, $tmpfile) = tempfile();
116 say $fh "# i3 config file (v4)";
117 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
118 say $fh "ipc-socket $socketpath";
119 say $fh q|for_window [class="borderless"] border none|;
120 say $fh q|for_window [title="special borderless title"] border none|;
124 my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
125 my $process = Proc::Background->new($i3cmd);
128 # force update of the cached socket path in lib/i3test
131 $tmp = fresh_workspace;
133 $window = $x->root->create_child(
134 class => WINDOW_CLASS_INPUT_OUTPUT,
135 rect => [ 0, 0, 30, 30 ],
136 background_color => '#00ff00',
139 $window->name('special title');
143 @content = @{get_ws_content($tmp)};
144 cmp_ok(@content, '==', 1, 'one node on this workspace now');
145 is($content[0]->{border}, 'normal', 'normal border');
147 $window->name('special borderless title');
150 @content = @{get_ws_content($tmp)};
151 is($content[0]->{border}, 'none', 'no border');
153 $window->name('special title');
158 @content = @{get_ws_content($tmp)};
159 is($content[0]->{border}, 'normal', 'border reset to normal');
161 $window->name('special borderless title');
164 @content = @{get_ws_content($tmp)};
165 is($content[0]->{border}, 'normal', 'still normal border');
170 @content = @{get_ws_content($tmp)};
171 cmp_ok(@content, '==', 0, 'no more nodes');
173 exit_gracefully($process->pid);
175 ##############################################################
176 # 3: match on the title, set border style *and* a mark
177 ##############################################################
179 ($fh, $tmpfile) = tempfile();
180 say $fh "# i3 config file (v4)";
181 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
182 say $fh "ipc-socket $socketpath";
183 say $fh q|for_window [class="borderless"] border none|;
184 say $fh q|for_window [title="special borderless title"] border none|;
185 say $fh q|for_window [title="special mark title"] border none, mark bleh|;
189 my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
190 my $process = Proc::Background->new($i3cmd);
193 # force update of the cached socket path in lib/i3test
196 $tmp = fresh_workspace;
198 $window = $x->root->create_child(
199 class => WINDOW_CLASS_INPUT_OUTPUT,
200 rect => [ 0, 0, 30, 30 ],
201 background_color => '#00ff00',
204 $window->name('special mark title');
208 @content = @{get_ws_content($tmp)};
209 cmp_ok(@content, '==', 1, 'one node on this workspace now');
210 is($content[0]->{border}, 'none', 'no border');
212 my $other = open_standard_window($x);
214 @content = @{get_ws_content($tmp)};
215 cmp_ok(@content, '==', 2, 'two nodes');
216 is($content[0]->{border}, 'none', 'no border');
217 is($content[1]->{border}, 'normal', 'normal border');
218 ok(!$content[0]->{focused}, 'first one not focused');
220 cmd qq|[con_mark="bleh"] focus|;
222 @content = @{get_ws_content($tmp)};
223 ok($content[0]->{focused}, 'first node focused');
225 exit_gracefully($process->pid);
227 ##############################################################
228 # 4: multiple criteria for the for_window command
229 ##############################################################
231 ($fh, $tmpfile) = tempfile();
232 say $fh "# i3 config file (v4)";
233 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
234 say $fh "ipc-socket $socketpath";
235 say $fh q|for_window [class="borderless" title="usethis"] border none|;
239 my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/tmp/a 2>/dev/null";
240 my $process = Proc::Background->new($i3cmd);
243 # force update of the cached socket path in lib/i3test
246 $tmp = fresh_workspace;
248 $window = $x->root->create_child(
249 class => WINDOW_CLASS_INPUT_OUTPUT,
250 rect => [ 0, 0, 30, 30 ],
251 background_color => '#00ff00',
256 set_wm_class($window->id, 'borderless', 'borderless');
257 $window->name('usethis');
261 @content = @{get_ws_content($tmp)};
262 cmp_ok(@content, '==', 1, 'one node on this workspace now');
263 is($content[0]->{border}, 'none', 'no border');
268 @content = @{get_ws_content($tmp)};
269 cmp_ok(@content, '==', 0, 'no nodes on this workspace now');
271 set_wm_class($window->id, 'borderless', 'borderless');
272 $window->name('notthis');
276 @content = @{get_ws_content($tmp)};
277 cmp_ok(@content, '==', 1, 'one node on this workspace now');
278 is($content[0]->{border}, 'normal', 'no border');
281 exit_gracefully($process->pid);