]> git.sur5r.net Git - i3/i3/blob - testcases/t/223-net-client-list.t
Merge branch 'next' into master
[i3/i3] / testcases / t / 223-net-client-list.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 _NET_CLIENT_LIST is properly updated on the root window as windows
18 # are mapped and unmapped.
19 #
20 # Information on this property can be found here:
21 # https://standards.freedesktop.org/wm-spec/latest/ar01s03.html
22 #
23 # > These arrays contain all X Windows managed by the Window Manager.
24 # > _NET_CLIENT_LIST has initial mapping order, starting with the oldest window.
25 #
26 # Ticket: #1099
27 # Bug still in: 4.7.2-8-ge6cce92
28 use i3test;
29
30 sub get_client_list {
31     my $cookie = $x->get_property(
32         0,
33         $x->get_root_window(),
34         $x->atom(name => '_NET_CLIENT_LIST')->id,
35         $x->atom(name => 'WINDOW')->id,
36         0,
37         4096,
38     );
39     my $reply = $x->get_property_reply($cookie->{sequence});
40     my $len = $reply->{length};
41
42     return () if $len == 0;
43     return unpack("L$len", $reply->{value});
44 }
45
46 # Mapping a window should give us one client in _NET_CLIENT_LIST
47 my $win1 = open_window;
48
49 my @clients = get_client_list;
50
51 is(@clients, 1, 'One client in _NET_CLIENT_LIST');
52 is($clients[0], $win1->{id}, 'Correct client in position one');
53
54 # Mapping another window should give us two clients in the list with the last
55 # client mapped in the last position
56 my $win2 = open_window;
57
58 @clients = get_client_list;
59 is(@clients, 2, 'Added mapped client to list (2)');
60 is($clients[0], $win1->{id}, 'Correct client in position one');
61 is($clients[1], $win2->{id}, 'Correct client in position two');
62
63 # Mapping another window should give us three clients in the list in the order
64 # they were mapped
65 my $win3 = open_window;
66
67 @clients = get_client_list;
68 is(@clients, 3, 'Added mapped client to list (3)');
69 is($clients[0], $win1->{id}, 'Correct client in position one');
70 is($clients[1], $win2->{id}, 'Correct client in position two');
71 is($clients[2], $win3->{id}, 'Correct client in position three');
72
73 # Unmapping the second window should give us the two remaining clients in the
74 # order they were mapped
75 $win2->unmap;
76 wait_for_unmap($win2);
77
78 @clients = get_client_list;
79 is(@clients, 2, 'Removed unmapped client from list (2)');
80 is($clients[0], $win1->{id}, 'Correct client in position one');
81 is($clients[1], $win3->{id}, 'Correct client in position two');
82
83 # Unmapping the first window should give us only the remaining mapped window in
84 # the list
85 $win1->unmap;
86 wait_for_unmap($win1);
87
88 @clients = get_client_list;
89 is(@clients, 1, 'Removed unmapped client from list (1)');
90 is($clients[0], $win3->{id}, 'Correct client in position one');
91
92 # Unmapping the last window should give us an empty list
93 $win3->unmap;
94 wait_for_unmap($win3);
95
96 @clients = get_client_list;
97 is(@clients, 0, 'Removed unmapped client from list (0)');
98
99 # Dock clients should not be included in this list
100
101 my $dock_win = open_window({
102         window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
103     });
104
105 @clients = get_client_list;
106 is(@clients, 0, 'Dock clients are not included in the list');
107
108 done_testing;