]> git.sur5r.net Git - i3/i3/blob - testcases/t/266-net-moveresize-window.t
Merge pull request #3400 from Synray/next
[i3/i3] / testcases / t / 266-net-moveresize-window.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 for _NET_MOVERESIZE_WINDOW.
18 # Ticket: #2603
19 use i3test i3_autostart => 0;
20
21 sub moveresize_window {
22     my ($win, $pos_x, $pos_y, $width, $height) = @_;
23
24     my $flags = 0;
25     $flags |= (1 << 8) if $pos_x >= 0;
26     $flags |= (1 << 9) if $pos_y >= 0;
27     $flags |= (1 << 10) if $width >= 0;
28     $flags |= (1 << 11) if $height >= 0;
29
30     my $msg = pack "CCSLLLLLLL",
31         X11::XCB::CLIENT_MESSAGE, # response_type
32         32, # format
33         0, # sequence
34         $win->id, # window
35         $x->atom(name => '_NET_MOVERESIZE_WINDOW')->id, # message type
36         $flags, # data32[0] (flags)
37         $pos_x, # data32[1] (x)
38         $pos_y, # data32[2] (y)
39         $width, # data32[3] (width)
40         $height; # data32[4] (height)
41
42     $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
43     sync_with_i3;
44 }
45
46 my $config = <<EOT;
47 # i3 config file (v4)
48 font font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
49
50 new_window none
51 new_float none
52 EOT
53
54 my ($pid, $ws, $window, $content);
55
56 ###############################################################################
57
58 ###############################################################################
59 # A _NET_MOVERESIZE_WINDOW client message can change the position and size
60 # of a floating window.
61 ###############################################################################
62
63 $pid = launch_with_config($config);
64 $ws = fresh_workspace;
65
66 $window = open_floating_window(rect => [50, 50, 100, 100]);
67 moveresize_window($window, 0, 0, 555, 666);
68
69 $content = get_ws($ws);
70 is($content->{floating_nodes}->[0]->{rect}->{x}, 0, 'the x coordinate is correct');
71 is($content->{floating_nodes}->[0]->{rect}->{y}, 0, 'the y coordinate is correct');
72 is($content->{floating_nodes}->[0]->{rect}->{width}, 555, 'the width is correct');
73 is($content->{floating_nodes}->[0]->{rect}->{height}, 666, 'the height is correct');
74
75 exit_gracefully($pid);
76
77 ###############################################################################
78 # A _NET_MOVERESIZE_WINDOW client message can change only the position of a
79 # window.
80 ###############################################################################
81
82 $pid = launch_with_config($config);
83 $ws = fresh_workspace;
84
85 $window = open_floating_window(rect => [50, 50, 100, 100]);
86 moveresize_window($window, 100, 100, -1, -1);
87
88 $content = get_ws($ws);
89 is($content->{floating_nodes}->[0]->{rect}->{x}, 100, 'the x coordinate is correct');
90 is($content->{floating_nodes}->[0]->{rect}->{y}, 100, 'the y coordinate is correct');
91 is($content->{floating_nodes}->[0]->{rect}->{width}, 100, 'the width is unchanged');
92 is($content->{floating_nodes}->[0]->{rect}->{height}, 100, 'the height is unchanged');
93
94 exit_gracefully($pid);
95
96 ###############################################################################
97 # A _NET_MOVERESIZE_WINDOW client message can change only the size of a
98 # window.
99 ###############################################################################
100
101 $pid = launch_with_config($config);
102 $ws = fresh_workspace;
103
104 $window = open_floating_window(rect => [50, 50, 100, 100]);
105 moveresize_window($window, -1, -1, 200, 200);
106
107 $content = get_ws($ws);
108 is($content->{floating_nodes}->[0]->{rect}->{x}, 50, 'the x coordinate is unchanged');
109 is($content->{floating_nodes}->[0]->{rect}->{y}, 50, 'the y coordinate is unchanged');
110 is($content->{floating_nodes}->[0]->{rect}->{width}, 200, 'the width is correct');
111 is($content->{floating_nodes}->[0]->{rect}->{height}, 200, 'the height is correct');
112
113 exit_gracefully($pid);
114
115 ###############################################################################
116
117 done_testing;