i3 - improved tiling WM


Set EWMH desktop properties on startup.

Patch status: merged

Patch by Steve Jones

Long description:

Calls ewmh_update_current_desktop on startup to set the
_NET_CURRENT_DESKTOP property. Without this change the property only
gets set after the workspaces have been manipulated. Also exclude
hidden workspaces (i.e. those starting with "__" from the workspace
index.

Adds tests for startup and workspace switching.

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

b/src/ewmh.c

23
@@ -27,6 +27,9 @@ void ewmh_update_current_desktop(void) {
24
     TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
25
         Con *ws;
26
         TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
27
+            if (STARTS_WITH(ws->name, "__"))
28
+                continue;
29
+
30
             if (ws == focused_ws) {
31
                 xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
32
                         A__NET_CURRENT_DESKTOP, XCB_ATOM_CARDINAL, 32, 1, &idx);

b/src/main.c

37
@@ -761,6 +761,9 @@ int main(int argc, char *argv[]) {
38
     x_set_i3_atoms();
39
     ewmh_update_workarea();
40
 
41
+    /* Set the _NET_CURRENT_DESKTOP property. */
42
+    ewmh_update_current_desktop();
43
+
44
     struct ev_io *xcb_watcher = scalloc(sizeof(struct ev_io));
45
     struct ev_io *xkb = scalloc(sizeof(struct ev_io));
46
     xcb_check = scalloc(sizeof(struct ev_check));

b/testcases/t/217-NET_CURRENT_DESKTOP.t

52
@@ -0,0 +1,75 @@
53
+#!perl
54
+# vim:ts=4:sw=4:expandtab
55
+#
56
+# Please read the following documents before working on tests:
57
+# • http://build.i3wm.org/docs/testsuite.html
58
+#   (or docs/testsuite)
59
+#
60
+# • http://build.i3wm.org/docs/lib-i3test.html
61
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
62
+#
63
+# • http://build.i3wm.org/docs/ipc.html
64
+#   (or docs/ipc)
65
+#
66
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
67
+#   (unless you are already familiar with Perl)
68
+#
69
+# Verifies the _NET_CURRENT_DESKTOP property correctly tracks the currently
70
+# active workspace. Specifically checks that the property is 0 on startup with
71
+# an empty config, tracks changes when switching workspaces and when
72
+# workspaces are created and deleted.
73
+#
74
+# The property not being set on startup was last present in commit
75
+# 6578976b6159437c16187cf8d1ea38aa9fec9fc8.
76
+
77
+use i3test i3_autostart => 0;
78
+use X11::XCB qw(PROP_MODE_REPLACE);
79
+
80
+my $config = <<EOT;
81
+# i3 config file (v4)
82
+font font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
83
+EOT
84
+
85
+my $root = $x->get_root_window;
86
+# Manually intern _NET_CURRENT_DESKTOP as $x->atom will not create atoms if
87
+# they are not yet interned.
88
+my $atom_cookie = $x->intern_atom(0, length("_NET_CURRENT_DESKTOP"), "_NET_CURRENT_DESKTOP");
89
+my $_NET_CURRENT_DESKTOP = $x->intern_atom_reply($atom_cookie->{sequence})->{atom};
90
+my $CARDINAL = $x->atom(name => 'CARDINAL')->id;
91
+
92
+$x->delete_property($root, $_NET_CURRENT_DESKTOP);
93
+
94
+$x->flush();
95
+
96
+sub current_desktop_index {
97
+    # Returns the _NET_CURRENT_DESKTOP property from the root window. This is
98
+    # the 0 based index of the current desktop.
99
+
100
+    my $cookie = $x->get_property(0, $root, $_NET_CURRENT_DESKTOP,
101
+                                  $CARDINAL, 0, 1);
102
+    my $reply = $x->get_property_reply($cookie->{sequence});
103
+
104
+    return undef if $reply->{value_len} != 1;
105
+    return undef if $reply->{format} != 32;
106
+    return undef if $reply->{type} != $CARDINAL;
107
+
108
+    return unpack 'L', $reply->{value};
109
+}
110
+
111
+my $pid = launch_with_config($config);
112
+
113
+is(current_desktop_index, 0, "Starting on desktop 0");
114
+cmd 'workspace 1';
115
+is(current_desktop_index, 0, "Change from empty to empty");
116
+open_window;
117
+cmd 'workspace 0';
118
+is(current_desktop_index, 0, "Open on 1 and view 0");
119
+open_window;
120
+cmd 'workspace 1';
121
+is(current_desktop_index, 1, "Open on 0 and view 1");
122
+cmd 'workspace 2';
123
+is(current_desktop_index, 2, "Open and view empty");
124
+
125
+exit_gracefully($pid);
126
+
127
+done_testing;