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 Without this
change the properties only get 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/394/raw.patch | git am

b/src/ewmh.c

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

b/src/main.c

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

b/testcases/t/217-NET_CURRENT_DESKTOP.t

52
@@ -0,0 +1,70 @@
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 behaves correctly.
70
+
71
+use i3test i3_autostart => 0;
72
+use X11::XCB qw(PROP_MODE_REPLACE);
73
+use Data::Dumper;
74
+
75
+my $config = <<EOT;
76
+# i3 config file (v4)
77
+font font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
78
+fake-outputs 1024x768+0+0
79
+EOT
80
+
81
+my $root = $x->get_root_window;
82
+my $atom_cookie = $x->intern_atom(0, length("_NET_CURRENT_DESKTOP"), "_NET_CURRENT_DESKTOP");
83
+my $atom_reply = $x->intern_atom_reply($atom_cookie->{sequence});
84
+
85
+my $_NET_CURRENT_DESKTOP = $x->atom(name => "_NET_CURRENT_DESKTOP");
86
+my $CARDINAL = $x->atom(name => "CARDINAL");
87
+
88
+$x->delete_property($root, $_NET_CURRENT_DESKTOP->id);
89
+
90
+$x->flush();
91
+
92
+sub is_current_desktop_set_to {
93
+  my $to = shift;
94
+
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 == $to;
104
+}
105
+
106
+my $pid = launch_with_config($config);
107
+
108
+ok(is_current_desktop_set_to(0), "Starting on desktop 0");
109
+cmd('workspace 1');
110
+ok(is_current_desktop_set_to(0), "Change from empty to empty");
111
+open_window;
112
+cmd('workspace 0');
113
+ok(is_current_desktop_set_to(0), "Open on 1 and view 0");
114
+open_window;
115
+cmd('workspace 1');
116
+ok(is_current_desktop_set_to(1), "Open on 0 and view 1");
117
+cmd('workspace 2');
118
+ok(is_current_desktop_set_to(2), "Open and view empty");
119
+
120
+exit_gracefully($pid);
121
+
122
+done_testing;