aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/234-ewmh-desktop-names.t
blob: 246a0a46ff0b06ca2c71744a122032ad4a87debb (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
#!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_NAMES is updated properly
# on the root window. We interpret this as a list of the open workspace names.
# Ticket: #1241
use i3test;

sub get_desktop_names {
    # 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_NAMES')->id,
        $x->atom(name => 'UTF8_STRING')->id,
        0,
        4096,
    );

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

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

    # the property is a null-delimited list of utf8 strings ;;
    return split /\0/, $reply->{value};
}

cmd 'workspace foo';

my @expected_names = ('foo');
my @desktop_names = get_desktop_names;

is_deeply(\@desktop_names, \@expected_names, '_NET_DESKTOP_NAMES should be an array of the workspace names');

# open a new workspace and see that the property is updated correctly
open_window;
cmd 'workspace bar';

@desktop_names = get_desktop_names;
@expected_names = ('foo', 'bar');

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

# rename the workspace and see that the property is updated correctly
cmd 'rename workspace bar to baz';

@desktop_names = get_desktop_names;
@expected_names = ('foo', 'baz');

is_deeply(\@desktop_names, \@expected_names, 'it should be updated when a workspace is renamed');

# empty a workspace and see that the property is updated correctly
cmd 'workspace foo';

@desktop_names = get_desktop_names;
@expected_names = ('foo');

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

done_testing;