This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
/
294-update-ewmh-atoms.t
119 lines (94 loc) · 3.16 KB
/
294-update-ewmh-atoms.t
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
#!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)
#
# Verifies _NET_DESKTOP_NAMES, _NET_CURRENT_DESKTOP and _NET_CURRENT_DESKTOP
# are updated properly when closing an inactive workspace container.
# See github issue #3126
use i3test;
sub get_desktop_names {
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};
}
sub get_num_of_desktops {
sync_with_i3;
my $cookie = $x->get_property(
0,
$x->get_root_window(),
$x->atom(name => '_NET_NUMBER_OF_DESKTOPS')->id,
$x->atom(name => 'CARDINAL')->id,
0,
4,
);
my $reply = $x->get_property_reply($cookie->{sequence});
return undef if $reply->{value_len} != 1;
return undef if $reply->{format} != 32;
return undef if $reply->{type} != $x->atom(name => 'CARDINAL')->id,;
return unpack 'L', $reply->{value};
}
sub get_current_desktop {
sync_with_i3;
my $cookie = $x->get_property(
0,
$x->get_root_window(),
$x->atom(name => '_NET_CURRENT_DESKTOP')->id,
$x->atom(name => 'CARDINAL')->id,
0,
4,
);
my $reply = $x->get_property_reply($cookie->{sequence});
return undef if $reply->{value_len} != 1;
return undef if $reply->{format} != 32;
return undef if $reply->{type} != $x->atom(name => 'CARDINAL')->id,;
return unpack 'L', $reply->{value};
}
cmd 'workspace 0';
my $first = open_window;
cmd 'workspace 1';
my $second = open_window;
cmd 'workspace 2';
my $third = open_window;
# Sanity check
is(get_current_desktop, 2);
is(get_num_of_desktops, 3);
my @actual_names = get_desktop_names;
my @expected_names = ('0', '1', '2');
is_deeply(\@actual_names, \@expected_names);
# Kill first window to close a workspace.
cmd '[id="' . $second->id . '"] kill';
is(get_current_desktop, 1, '_NET_CURRENT_DESKTOP should be updated');
is(get_num_of_desktops, 2, '_NET_NUMBER_OF_DESKTOPS should be updated');
my @actual_names = get_desktop_names;
my @expected_names = ('0', '2');
is_deeply(\@actual_names, \@expected_names, '_NET_DESKTOP_NAMES should be updated');
# Rename workspace to reorder them.
cmd 'rename workspace 0 to 5';
is(get_current_desktop, 0, '_NET_CURRENT_DESKTOP should be updated');
is(get_num_of_desktops, 2, '_NET_NUMBER_OF_DESKTOPS should remain the same');
my @actual_names = get_desktop_names;
my @expected_names = ('2', '5');
is_deeply(\@actual_names, \@expected_names, '_NET_DESKTOP_NAMES should be updated');
done_testing;