]> git.sur5r.net Git - i3/i3/blob - testcases/t/241-consistent-center.t
Merge branch 'master' into next
[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 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://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_autostart => 0;
22
23 my $config = <<EOT;
24 # i3 config file (v4)
25 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
26
27 new_window none
28 new_float none
29 EOT
30
31 my $pid = launch_with_config($config);
32
33 #####################################################################
34 # Open a floating window, verifying that its initial position is
35 # centered, and also verify that both centering methods leave it in
36 # its original spot.
37 #####################################################################
38
39 my $first = open_floating_window;
40
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');
46
47 cmd 'move position center';
48
49 my $new = $first->rect;
50 is($initial->{x}, $new->{x}, 'x coordinates match');
51 is($initial->{y}, $new->{y}, 'y coordinates match');
52
53 cmd 'move absolute position center';
54
55 $new = $first->rect;
56 is($initial->{x}, $new->{x}, 'x coordinates match');
57 is($initial->{y}, $new->{y}, 'y coordinates match');
58
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 #####################################################################
64
65 my $second = open_window;
66
67 cmd 'move scratchpad, scratchpad show';
68
69 $new = $second->rect;
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');
73
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');
77
78 #####################################################################
79 # Verify that manually floating a tiled window results in proper
80 # centering.
81 #####################################################################
82
83 my $third = open_window;
84
85 cmd 'floating enable';
86
87 $new = $third->rect;
88 is($initial->{x}, $new->{x}, 'x coordinates match');
89 is($initial->{y}, $new->{y}, 'y coordinates match');
90
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 #####################################################################
95
96 my $fourth = open_window( dont_map => 1, client_leader => $third );
97 $fourth->map;
98 sync_with_i3;
99
100 my $child = $fourth->rect;
101 is($new->{x}, $child->{x}, 'x coordinates match');
102 is($new->{y}, $child->{y}, 'y coordinates match');
103
104 exit_gracefully($pid);
105
106 done_testing;