2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Verifies that most of i3's centering methods produce consistent results.
18 # Decorations are disabled to avoid floating_enable's logic which shifts
19 # windows upwards dependent on their decoration height.
21 use i3test i3_config => <<EOT;
23 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
29 #####################################################################
30 # Open a floating window, verifying that its initial position is
31 # centered, and also verify that both centering methods leave it in
33 #####################################################################
35 my $first = open_floating_window;
37 my $initial = $first->rect;
38 is(int($initial->{x} + $initial->{width} / 2), int($x->root->rect->width / 2),
39 'x coordinates match');
40 is(int($initial->{y} + $initial->{height} / 2), int($x->root->rect->height / 2),
41 'y coordinates match');
43 cmd 'move position center';
45 my $new = $first->rect;
46 is($initial->{x}, $new->{x}, 'x coordinates match');
47 is($initial->{y}, $new->{y}, 'y coordinates match');
49 cmd 'move absolute position center';
52 is($initial->{x}, $new->{x}, 'x coordinates match');
53 is($initial->{y}, $new->{y}, 'y coordinates match');
55 #####################################################################
56 # Create a second window and move it into and out of the scratchpad.
57 # Because it hasn't been moved or resized, it should be floated in
58 # the center of the screen when pulled out of the scratchpad.
59 #####################################################################
61 my $second = open_window;
63 cmd 'move scratchpad, scratchpad show';
66 my $mid_init = $initial->{x} + int($initial->{width} / 2);
67 my $mid_new = $new->{x} + int($new->{width} / 2);
68 is($mid_init, $mid_new, 'x midpoint is ws center');
70 $mid_init = $initial->{y} + int($initial->{height} / 2);
71 $mid_new = $new->{y} + int($new->{height} / 2);
72 is($mid_init, $mid_new, 'y midpoint is ws center');
74 #####################################################################
75 # Verify that manually floating a tiled window results in proper
77 #####################################################################
79 my $third = open_window;
81 cmd 'floating enable';
84 is($initial->{x}, $new->{x}, 'x coordinates match');
85 is($initial->{y}, $new->{y}, 'y coordinates match');
87 #####################################################################
88 # Create a child window of the previous window, which should result
89 # in the new window being centered over the last one.
90 #####################################################################
92 my $fourth = open_window( dont_map => 1, client_leader => $third );
96 my $child = $fourth->rect;
97 is($new->{x}, $child->{x}, 'x coordinates match');
98 is($new->{y}, $child->{y}, 'y coordinates match');