]> git.sur5r.net Git - i3/i3/blob - testcases/t/245-move-position-mouse.t
Remove trailing whitespace from Perl scripts
[i3/i3] / testcases / t / 245-move-position-mouse.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 # Tests the 'move [window|container] [to] position mouse|cursor|pointer command.
18 # Ticket: #1696
19 use i3test i3_autostart => 0;
20 use POSIX qw(floor);
21
22 sub warp_pointer {
23     my ($pos_x, $pos_y) = @_;
24     $x->root->warp_pointer($pos_x, $pos_y);
25     sync_with_i3;
26 }
27
28 my ($pid, $config, $ws, $rect, @cons);
29 my $root_rect = $x->root->rect;
30
31 ##########################################################################
32
33 ##########################################################################
34 # Given a floating container and the cursor far from any edges, when
35 # moving the container to the mouse, then the container is moved such
36 # that the cursor is centered inside it.
37 ##########################################################################
38
39 $config = <<EOT;
40 # i3 config file (v4)
41 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
42 EOT
43 $pid = launch_with_config($config);
44
45 $ws = fresh_workspace;
46 open_floating_window;
47 warp_pointer(100, 100);
48
49 cmd 'move position mouse';
50
51 @cons = @{get_ws($ws)->{floating_nodes}};
52 $rect = $cons[0]->{rect};
53
54 is(floor($rect->{x} + $rect->{width} / 2), 100, "con is centered around cursor horizontally");
55 is(floor($rect->{y} + $rect->{height} / 2), 100, "con is centered around cursor vertically");
56
57 exit_gracefully($pid);
58
59 ##########################################################################
60 # Given a floating container and the cursor is in the left upper edge
61 # of the output, when moving the container to the mouse, then the
62 # container is moved but adjusted to stay in-bounds.
63 ##########################################################################
64
65 $config = <<EOT;
66 # i3 config file (v4)
67 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
68 EOT
69 $pid = launch_with_config($config);
70
71 $ws = fresh_workspace;
72 open_floating_window;
73 warp_pointer(5, 5);
74
75 cmd 'move position mouse';
76
77 @cons = @{get_ws($ws)->{floating_nodes}};
78 $rect = $cons[0]->{rect};
79
80 is($rect->{x}, 0, "con is on the left edge");
81 is($rect->{y}, 0, "con is on the upper edge");
82
83 exit_gracefully($pid);
84
85 ##########################################################################
86 # Given a floating container and the cursor is in the left right lower
87 # edge of the output, when moving the container to the mouse, then the
88 # container is moved but adjusted to stay in-bounds.
89 ##########################################################################
90
91 $config = <<EOT;
92 # i3 config file (v4)
93 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
94 EOT
95 $pid = launch_with_config($config);
96
97 $ws = fresh_workspace;
98 open_floating_window;
99 warp_pointer($root_rect->width - 5, $root_rect->height - 5);
100
101 cmd 'move position mouse';
102
103 @cons = @{get_ws($ws)->{floating_nodes}};
104 $rect = $cons[0]->{rect};
105
106 is($rect->{x} + $rect->{width}, $root_rect->width, "con is on the right edge");
107 is($rect->{y} + $rect->{height}, $root_rect->height, "con is on the lower edge");
108
109 exit_gracefully($pid);
110
111 ##########################################################################
112 # Given a floating container and the cursor being close to the corner of
113 # an output, when the container is moved to the mouse, then the container
114 # is moved but adjusted to the output boundaries.
115 # This test verifies that boundaries of individual outputs are respected
116 # and not just boundaries of the entire X root screen.
117 ##########################################################################
118
119 $config = <<EOT;
120 # i3 config file (v4)
121 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
122 fake-outputs 500x500+0+0,500x500+500+0,500x500+0+500,500x500+500+500
123 EOT
124 $pid = launch_with_config($config);
125
126 $ws = fresh_workspace;
127 open_floating_window;
128 warp_pointer(495, 495);
129
130 cmd 'move position mouse';
131
132 @cons = @{get_ws($ws)->{floating_nodes}};
133 $rect = $cons[0]->{rect};
134
135 is($rect->{x} + $rect->{width}, 500, "con is on the right edge");
136 is($rect->{y} + $rect->{height}, 500, "con is on the lower edge");
137
138 exit_gracefully($pid);
139
140 ##########################################################################
141
142 done_testing;