aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/266-net-moveresize-window.t
blob: b31aeed65eaf0eccb771527512f552aee7dff84d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Tests for _NET_MOVERESIZE_WINDOW.
# Ticket: #2603
use i3test i3_autostart => 0;

sub moveresize_window {
    my ($win, $pos_x, $pos_y, $width, $height) = @_;

    my $flags = 0;
    $flags |= (1 << 8) if $pos_x >= 0;
    $flags |= (1 << 9) if $pos_y >= 0;
    $flags |= (1 << 10) if $width >= 0;
    $flags |= (1 << 11) if $height >= 0;

    my $msg = pack "CCSLLLLLLL",
        X11::XCB::CLIENT_MESSAGE, # response_type
        32, # format
        0, # sequence
        $win->id, # window
        $x->atom(name => '_NET_MOVERESIZE_WINDOW')->id, # message type
        $flags, # data32[0] (flags)
        $pos_x, # data32[1] (x)
        $pos_y, # data32[2] (y)
        $width, # data32[3] (width)
        $height; # data32[4] (height)

    $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
    sync_with_i3;
}

my $config = <<EOT;
# i3 config file (v4)
font font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

new_window none
new_float none
EOT

my ($pid, $ws, $window, $content);

###############################################################################

###############################################################################
# A _NET_MOVERESIZE_WINDOW client message can change the position and size
# of a floating window.
###############################################################################

$pid = launch_with_config($config);
$ws = fresh_workspace;

$window = open_floating_window(rect => [50, 50, 100, 100]);
moveresize_window($window, 0, 0, 555, 666);

$content = get_ws($ws);
is($content->{floating_nodes}->[0]->{rect}->{x}, 0, 'the x coordinate is correct');
is($content->{floating_nodes}->[0]->{rect}->{y}, 0, 'the y coordinate is correct');
is($content->{floating_nodes}->[0]->{rect}->{width}, 555, 'the width is correct');
is($content->{floating_nodes}->[0]->{rect}->{height}, 666, 'the height is correct');

exit_gracefully($pid);

###############################################################################
# A _NET_MOVERESIZE_WINDOW client message can change only the position of a
# window.
###############################################################################

$pid = launch_with_config($config);
$ws = fresh_workspace;

$window = open_floating_window(rect => [50, 50, 100, 100]);
moveresize_window($window, 100, 100, -1, -1);

$content = get_ws($ws);
is($content->{floating_nodes}->[0]->{rect}->{x}, 100, 'the x coordinate is correct');
is($content->{floating_nodes}->[0]->{rect}->{y}, 100, 'the y coordinate is correct');
is($content->{floating_nodes}->[0]->{rect}->{width}, 100, 'the width is unchanged');
is($content->{floating_nodes}->[0]->{rect}->{height}, 100, 'the height is unchanged');

exit_gracefully($pid);

###############################################################################
# A _NET_MOVERESIZE_WINDOW client message can change only the size of a
# window.
###############################################################################

$pid = launch_with_config($config);
$ws = fresh_workspace;

$window = open_floating_window(rect => [50, 50, 100, 100]);
moveresize_window($window, -1, -1, 200, 200);

$content = get_ws($ws);
is($content->{floating_nodes}->[0]->{rect}->{x}, 50, 'the x coordinate is unchanged');
is($content->{floating_nodes}->[0]->{rect}->{y}, 50, 'the y coordinate is unchanged');
is($content->{floating_nodes}->[0]->{rect}->{width}, 200, 'the width is correct');
is($content->{floating_nodes}->[0]->{rect}->{height}, 200, 'the height is correct');

exit_gracefully($pid);

###############################################################################

done_testing;