i3 - improved tiling WM


Set EWMH desktop properties on startup.

Patch status: superseded

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/397/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,71 @@
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
+# Manually intern _NET_CURRENT_DESKTOP as $x->atom will not create atoms if
88
+# they are not yet interned.
89
+my $atom_cookie = $x->intern_atom(0, length("_NET_CURRENT_DESKTOP"), "_NET_CURRENT_DESKTOP");
90
+my $_NET_CURRENT_DESKTOP = $x->intern_atom_reply($atom_cookie->{sequence})->{atom};
91
+my $CARDINAL = $x->atom(name => 'CARDINAL')->id;
92
+
93
+$x->delete_property($root, $_NET_CURRENT_DESKTOP);
94
+
95
+$x->flush();
96
+
97
+sub current_desktop {
98
+  my $cookie = $x->get_property(0, $root, $_NET_CURRENT_DESKTOP,
99
+				$CARDINAL, 0, 1);
100
+  my $reply = $x->get_property_reply($cookie->{sequence});
101
+
102
+  return 0 if $reply->{value_len} != 1;
103
+  return 0 if $reply->{format} != 32;
104
+  return 0 if $reply->{type} != $CARDINAL;
105
+  return unpack 'L', $reply->{value};
106
+}
107
+
108
+my $pid = launch_with_config($config);
109
+
110
+is(current_desktop, 0, "Starting on desktop 0");
111
+cmd 'workspace 1';
112
+is(current_desktop, 0, "Change from empty to empty");
113
+open_window;
114
+cmd 'workspace 0';
115
+is(current_desktop, 0, "Open on 1 and view 0");
116
+open_window;
117
+cmd 'workspace 1';
118
+is(current_desktop, 1, "Open on 0 and view 1");
119
+cmd 'workspace 2';
120
+is(current_desktop, 2, "Open and view empty");
121
+
122
+exit_gracefully($pid);
123
+
124
+done_testing;