2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://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_autostart => 0;
25 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
31 my $pid = launch_with_config($config);
33 #####################################################################
34 # Open a floating window, verifying that its initial position is
35 # centered, and also verify that both centering methods leave it in
37 #####################################################################
39 my $first = open_floating_window;
41 my $initial = $first->rect;
42 is(int($initial->{x} + $initial->{width} / 2), int($x->root->rect->width / 2),
43 'x coordinates match');
44 is(int($initial->{y} + $initial->{height} / 2), int($x->root->rect->height / 2),
45 'y coordinates match');
47 cmd 'move position center';
49 my $new = $first->rect;
50 is($initial->{x}, $new->{x}, 'x coordinates match');
51 is($initial->{y}, $new->{y}, 'y coordinates match');
53 cmd 'move absolute position center';
56 is($initial->{x}, $new->{x}, 'x coordinates match');
57 is($initial->{y}, $new->{y}, 'y coordinates match');
59 #####################################################################
60 # Create a second window and move it into and out of the scratchpad.
61 # Because it hasn't been moved or resized, it should be floated in
62 # the center of the screen when pulled out of the scratchpad.
63 #####################################################################
65 my $second = open_window;
67 cmd 'move scratchpad, scratchpad show';
70 my $mid_init = $initial->{x} + int($initial->{width} / 2);
71 my $mid_new = $new->{x} + int($new->{width} / 2);
72 is($mid_init, $mid_new, 'x midpoint is ws center');
74 $mid_init = $initial->{y} + int($initial->{height} / 2);
75 $mid_new = $new->{y} + int($new->{height} / 2);
76 is($mid_init, $mid_new, 'y midpoint is ws center');
78 #####################################################################
79 # Verify that manually floating a tiled window results in proper
81 #####################################################################
83 my $third = open_window;
85 cmd 'floating enable';
88 is($initial->{x}, $new->{x}, 'x coordinates match');
89 is($initial->{y}, $new->{y}, 'y coordinates match');
91 #####################################################################
92 # Create a child window of the previous window, which should result
93 # in the new window being centered over the last one.
94 #####################################################################
96 my $fourth = open_window( dont_map => 1, client_leader => $third );
100 my $child = $fourth->rect;
101 is($new->{x}, $child->{x}, 'x coordinates match');
102 is($new->{y}, $child->{y}, 'y coordinates match');
104 exit_gracefully($pid);