i3 - improved tiling WM


Set EWMH desktop properties on startup.

Patch status: needinfo

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/395/raw.patch | git am

b/src/ewmh.c

23
@@ -27,7 +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 (ws == focused_ws) {
28
+	    if (STARTS_WITH(ws->name, "__"))
29
+		continue;
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);
33
                 return;

b/src/main.c

38
@@ -760,6 +760,9 @@ int main(int argc, char *argv[]) {
39
     /* Set up i3 specific atoms like I3_SOCKET_PATH and I3_CONFIG_PATH */
40
     x_set_i3_atoms();
41
     ewmh_update_workarea();
42
+    
43
+    /* Set the _NET_CURRENT_DESKTOP property. */
44
+    ewmh_update_current_desktop();
45
 
46
     struct ev_io *xcb_watcher = scalloc(sizeof(struct ev_io));
47
     struct ev_io *xkb = scalloc(sizeof(struct ev_io));

b/testcases/t/217-NET_CURRENT_DESKTOP.t

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