# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
-# • http://build.i3wm.org/docs/testsuite.html
+# • https://build.i3wm.org/docs/testsuite.html
# (or docs/testsuite)
#
-# • http://build.i3wm.org/docs/lib-i3test.html
+# • https://build.i3wm.org/docs/lib-i3test.html
# (alternatively: perldoc ./testcases/lib/i3test.pm)
#
-# • http://build.i3wm.org/docs/ipc.html
+# • https://build.i3wm.org/docs/ipc.html
# (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
# Verifies that using criteria to address scratchpad windows works.
use i3test;
+my $i3 = i3(get_socket_path());
+
#####################################################################
# Verify that using scratchpad show with criteria works as expected:
# - When matching a scratchpad window which is visible,
my $scratch_focus = get_focused($tmp);
isnt($scratch_focus, $old_focus, 'matching criteria works');
+# Check that the window was centered and resized too.
+my $tree = $i3->get_tree->recv;
+my $ws = get_ws($tmp);
+my $scratchrect = $ws->{floating_nodes}->[0]->{rect};
+my $output = $tree->{nodes}->[1];
+my $outputrect = $output->{rect};
+
+is($scratchrect->{width}, $outputrect->{width} * 0.5, 'scratch width is 50%');
+is($scratchrect->{height}, $outputrect->{height} * 0.75, 'scratch height is 75%');
+is($scratchrect->{x},
+ ($outputrect->{width} / 2) - ($scratchrect->{width} / 2),
+ 'scratch window centered horizontally');
+is($scratchrect->{y},
+ ($outputrect->{height} / 2 ) - ($scratchrect->{height} / 2),
+ 'scratch window centered vertically');
+
cmd '[title="scratch-match"] scratchpad show';
isnt(get_focused($tmp), $scratch_focus, 'matching criteria works');