i3 - improved tiling WM


Handle EWMH requests to change current desktop

Patch status: needinfo

Patch by Tony Crisci

Long description:

This request is used by pagers and bars to change the current
desktop likely as a result of some user action. We interpret this as
a request to focus the given workspace.

for more information see:

http://standards.freedesktop.org/wm-spec/latest/ar01s03.html#idm140251368135008

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

b/src/handlers.c

20
@@ -806,6 +806,39 @@ static void handle_client_message(xcb_client_message_event_t *event) {
21
             DLOG("Not handling WM_CHANGE_STATE request. (window = %d, state = %d)\n", event->window, event->data.data32[0]);
22
         }
23
 
24
+    } else if (event->type == A__NET_CURRENT_DESKTOP) {
25
+        /* This request is used by pagers and bars to change the current
26
+         * desktop likely as a result of some user action. We interpret this as
27
+         * a request to focus the given workspace. See
28
+         * http://standards.freedesktop.org/wm-spec/latest/ar01s03.html#idm140251368135008
29
+         * */
30
+        Con *output;
31
+        uint32_t idx = 0;
32
+        DLOG("Request to change current desktop to index %d\n", event->data.data32[0]);
33
+
34
+        TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
35
+            Con *ws;
36
+            TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
37
+                if (STARTS_WITH(ws->name, "__"))
38
+                    continue;
39
+
40
+                if (idx == event->data.data32[0]) {
41
+                    /* data32[1] is a timestamp used to prevent focus race conditions */
42
+                    if (event->data.data32[1])
43
+                        last_timestamp = event->data.data32[1];
44
+
45
+
46
+                    DLOG("Handling request to focus workspace %s\n", ws->name);
47
+
48
+                    workspace_show(ws);
49
+                    tree_render();
50
+
51
+                    return;
52
+                }
53
+
54
+                ++idx;
55
+            }
56
+        }
57
     } else {
58
         DLOG("unhandled clientmessage\n");
59
         return;