i3 - improved tiling WM


Add test for _NET_CLIENT_LIST

Patch status: needinfo

Patch by Tony Crisci

Long description:

Test that _NET_CLIENT_LIST is properly updated on the root window as windows
are mapped and unmapped.

Information on this property can be found here:
http://standards.freedesktop.org/wm-spec/latest/ar01s03.html

> These arrays contain all X Windows managed by the Window Manager.
> _NET_CLIENT_LIST has initial mapping order, starting with the oldest window.

To apply this patch, use:
curl http://cr.i3wm.org/patch/476/raw.patch | git am

b/testcases/t/223-net-client-list.t

23
@@ -0,0 +1,102 @@
24
+#!perl
25
+# vim:ts=4:sw=4:expandtab
26
+#
27
+# Please read the following documents before working on tests:
28
+# • http://build.i3wm.org/docs/testsuite.html
29
+#   (or docs/testsuite)
30
+#
31
+# • http://build.i3wm.org/docs/lib-i3test.html
32
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
33
+#
34
+# • http://build.i3wm.org/docs/ipc.html
35
+#   (or docs/ipc)
36
+#
37
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
38
+#   (unless you are already familiar with Perl)
39
+#
40
+# Test that _NET_CLIENT_LIST is properly updated on the root window as windows
41
+# are mapped and unmapped.
42
+#
43
+# Information on this property can be found here:
44
+# http://standards.freedesktop.org/wm-spec/latest/ar01s03.html
45
+#
46
+# > These arrays contain all X Windows managed by the Window Manager.
47
+# > _NET_CLIENT_LIST has initial mapping order, starting with the oldest window.
48
+#
49
+# Ticket: #1099
50
+# Bug still in: 4.7.2-8-ge6cce92
51
+use i3test;
52
+
53
+sub get_client_list {
54
+    my $cookie = $x->get_property(
55
+        0,
56
+        $x->get_root_window(),
57
+        $x->atom(name => '_NET_CLIENT_LIST')->id,
58
+        $x->atom(name => 'WINDOW')->id,
59
+        0,
60
+        4096,
61
+    );
62
+    my $reply = $x->get_property_reply($cookie->{sequence});
63
+    my $len = $reply->{length};
64
+
65
+    my @retval = ();
66
+
67
+    @retval = unpack("L$len", $reply->{value}) if $len;
68
+
69
+    return @retval;
70
+}
71
+
72
+# Mapping a window should give us one client in _NET_CLIENT_LIST
73
+my $win1 = open_window;
74
+
75
+my @clients = get_client_list;
76
+
77
+is(@clients, 1, 'One client in _NET_CLIENT_LIST');
78
+is($clients[0], $win1->{id}, 'Correct client in position one');
79
+
80
+# Mapping another window should give us two clients in the list with the last
81
+# client mapped in the last position
82
+my $win2 = open_window;
83
+
84
+@clients = get_client_list;
85
+is(@clients, 2, 'Added mapped client to list (2)');
86
+is($clients[0], $win1->{id}, 'Correct client in position one');
87
+is($clients[1], $win2->{id}, 'Correct client in position two');
88
+
89
+# Mapping another window should give us three clients in the list in the order
90
+# they were mapped
91
+my $win3 = open_window;
92
+
93
+@clients = get_client_list;
94
+is(@clients, 3, 'Added mapped client to list (3)');
95
+is($clients[0], $win1->{id}, 'Correct client in position one');
96
+is($clients[1], $win2->{id}, 'Correct client in position two');
97
+is($clients[2], $win3->{id}, 'Correct client in position three');
98
+
99
+# Unmapping the second window should give us the two remaining clients in the
100
+# order they were mapped
101
+$win2->unmap;
102
+wait_for_unmap($win2);
103
+
104
+@clients = get_client_list;
105
+is(@clients, 2, 'Removed unmapped client from list (2)');
106
+is($clients[0], $win1->{id}, 'Correct client in position one');
107
+is($clients[1], $win3->{id}, 'Correct client in position two');
108
+
109
+# Unmapping the first window should give us only the remaining mapped window in
110
+# the list
111
+$win1->unmap;
112
+wait_for_unmap($win1);
113
+
114
+@clients = get_client_list;
115
+is(@clients, 1, 'Removed unmapped client from list (1)');
116
+is($clients[0], $win3->{id}, 'Correct client in position one');
117
+
118
+# Unmapping the last window should give us an empty list
119
+$win3->unmap;
120
+wait_for_unmap($win3);
121
+
122
+@clients = get_client_list;
123
+is(@clients, 0, 'Removed unmapped client from list (0)');
124
+
125
+done_testing;