]> git.sur5r.net Git - i3/i3/blob - testcases/t/234-ewmh-desktop-names.t
tests: replace http:// with https:// where appropriate
[i3/i3] / testcases / t / 234-ewmh-desktop-names.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 # Test that the EWMH specified property _NET_DESKTOP_NAMES is updated properly
18 # on the root window. We interpret this as a list of the open workspace names.
19 # Ticket: #1241
20 use i3test;
21
22 sub get_desktop_names {
23     # Make sure that i3 pushed its changes to X11 before querying.
24     sync_with_i3;
25
26     my $cookie = $x->get_property(
27         0,
28         $x->get_root_window(),
29         $x->atom(name => '_NET_DESKTOP_NAMES')->id,
30         $x->atom(name => 'UTF8_STRING')->id,
31         0,
32         4096,
33     );
34
35     my $reply = $x->get_property_reply($cookie->{sequence});
36
37     return 0 if $reply->{value_len} == 0;
38
39     # the property is a null-delimited list of utf8 strings ;;
40     return split /\0/, $reply->{value};
41 }
42
43 cmd 'workspace foo';
44
45 my @expected_names = ('foo');
46 my @desktop_names = get_desktop_names;
47
48 is_deeply(\@desktop_names, \@expected_names, '_NET_DESKTOP_NAMES should be an array of the workspace names');
49
50 # open a new workspace and see that the property is updated correctly
51 open_window;
52 cmd 'workspace bar';
53
54 @desktop_names = get_desktop_names;
55 @expected_names = ('foo', 'bar');
56
57 is_deeply(\@desktop_names, \@expected_names, 'it should be updated when a new workspace appears');
58
59 # rename the workspace and see that the property is updated correctly
60 cmd 'rename workspace bar to baz';
61
62 @desktop_names = get_desktop_names;
63 @expected_names = ('foo', 'baz');
64
65 is_deeply(\@desktop_names, \@expected_names, 'it should be updated when a workspace is renamed');
66
67 # empty a workspace and see that the property is updated correctly
68 cmd 'workspace foo';
69
70 @desktop_names = get_desktop_names;
71 @expected_names = ('foo');
72
73 is_deeply(\@desktop_names, \@expected_names, 'it should be updated when a workspace is emptied');
74
75 done_testing;