aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/521-ewmh-desktop-viewport.t
blob: a411936749918fb925dd7d8384ca8d46603e4601 (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
118
119
120
#!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)
#
# Test that the EWMH specified property _NET_DESKTOP_VIEWPORT is updated
# properly on the root window. We interpret this as a list of x/y coordinate
# pairs for the upper left corner of the respective outputs of the workspaces
# Ticket: #1241
use i3test i3_config => <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

workspace 0 output fake-0
workspace 1 output fake-1

fake-outputs 1024x768+0+0,1024x768+1024+0
EOT

sub get_desktop_viewport {
    # Make sure that i3 pushed its changes to X11 before querying.
    sync_with_i3;

    my $cookie = $x->get_property(
        0,
        $x->get_root_window(),
        $x->atom(name => '_NET_DESKTOP_VIEWPORT')->id,
        $x->atom(name => 'CARDINAL')->id,
        0,
        4096
    );

    my $reply = $x->get_property_reply($cookie->{sequence});

    return 0 if $reply->{value_len} == 0;

    my $len = $reply->{length};

    return unpack ("L$len", $reply->{value});
}

################################################################################
# Initialize the workspaces
################################################################################

cmd 'workspace 1';
cmd 'workspace 0';

my @expected_viewport = (0, 0, 1024, 0);
my @desktop_viewport = get_desktop_viewport;

is_deeply(\@desktop_viewport, \@expected_viewport,
    '_NET_DESKTOP_VIEWPORT should be an array of x/y coordinate pairs for the upper left corner of the respective outputs of the workspaces');

################################################################################
# Create workspace
################################################################################

cmd 'workspace 0';
open_window;
cmd 'workspace 3';

@expected_viewport = (0, 0, 0, 0, 1024, 0);
@desktop_viewport = get_desktop_viewport;

is_deeply(\@desktop_viewport, \@expected_viewport,
    'it should be updated when a new workspace appears');

################################################################################
# Rename workspace
################################################################################

cmd 'rename workspace 3 to 2';

@expected_viewport = (0, 0, 0, 0, 1024, 0);
@desktop_viewport = get_desktop_viewport;

is_deeply(\@desktop_viewport, \@expected_viewport,
    'it should stay up to date when a workspace is renamed');

################################################################################
# Empty workspace
################################################################################

cmd 'workspace 0';

@expected_viewport = (0, 0, 1024, 0);
@desktop_viewport = get_desktop_viewport;

is_deeply(\@desktop_viewport, \@expected_viewport,
    'it should be updated when a workspace is emptied');

################################################################################
# Move workspace
# See #4001
################################################################################

# Keep workspace 1 open to have 3 workspaces in total
cmd 'workspace 1';
open_window;
cmd 'workspace 0, move workspace to output right';
@expected_viewport = (0, 0, 1024, 0, 1024, 0);
@desktop_viewport = get_desktop_viewport;
is_deeply(\@desktop_viewport, \@expected_viewport,
    'it should be updated when a workspace is moved');

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

done_testing;