]> git.sur5r.net Git - i3/i3/blob - testcases/t/241-consistent-center.t
Merge branch 'release-4.16.1'
[i3/i3] / testcases / t / 241-consistent-center.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
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.
20 #
21 use i3test i3_config => <<EOT;
22 # i3 config file (v4)
23 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
24
25 new_window none
26 new_float none
27 EOT
28
29 #####################################################################
30 # Open a floating window, verifying that its initial position is
31 # centered, and also verify that both centering methods leave it in
32 # its original spot.
33 #####################################################################
34
35 my $first = open_floating_window;
36
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');
42
43 cmd 'move position center';
44
45 my $new = $first->rect;
46 is($initial->{x}, $new->{x}, 'x coordinates match');
47 is($initial->{y}, $new->{y}, 'y coordinates match');
48
49 cmd 'move absolute position center';
50
51 $new = $first->rect;
52 is($initial->{x}, $new->{x}, 'x coordinates match');
53 is($initial->{y}, $new->{y}, 'y coordinates match');
54
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 #####################################################################
60
61 my $second = open_window;
62
63 cmd 'move scratchpad, scratchpad show';
64
65 $new = $second->rect;
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');
69
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');
73
74 #####################################################################
75 # Verify that manually floating a tiled window results in proper
76 # centering.
77 #####################################################################
78
79 my $third = open_window;
80
81 cmd 'floating enable';
82
83 $new = $third->rect;
84 is($initial->{x}, $new->{x}, 'x coordinates match');
85 is($initial->{y}, $new->{y}, 'y coordinates match');
86
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 #####################################################################
91
92 my $fourth = open_window( dont_map => 1, client_leader => $third );
93 $fourth->map;
94 sync_with_i3;
95
96 my $child = $fourth->rect;
97 is($new->{x}, $child->{x}, 'x coordinates match');
98 is($new->{y}, $child->{y}, 'y coordinates match');
99
100 done_testing;