]> git.sur5r.net Git - i3/i3/commitdiff
Implement EWMH number of desktops property
authorTony Crisci <tony@dubstepdish.com>
Mon, 16 Jun 2014 06:50:47 +0000 (02:50 -0400)
committerMichael Stapelberg <michael@stapelberg.de>
Thu, 19 Jun 2014 09:21:03 +0000 (11:21 +0200)
_NET_NUMBER_OF_DESKTOPS:

> This property SHOULD be set and updated by the Window Manager to
> indicate the number of virtual desktops.

We interpret this property as the number of noninternal workspaces.

include/atoms.xmacro
include/ewmh.h
src/ewmh.c
src/main.c
src/workspace.c

index 90b026165ec00d75da9dab709e45afacecbd03ed..12e9ee28ee99f50812a0a385738692b796241c28 100644 (file)
@@ -16,6 +16,7 @@ xmacro(_NET_WM_STRUT_PARTIAL)
 xmacro(_NET_CLIENT_LIST)
 xmacro(_NET_CLIENT_LIST_STACKING)
 xmacro(_NET_CURRENT_DESKTOP)
+xmacro(_NET_NUMBER_OF_DESKTOPS)
 xmacro(_NET_ACTIVE_WINDOW)
 xmacro(_NET_STARTUP_ID)
 xmacro(_NET_WORKAREA)
index 46d6c98575b574295a14783fbaf3e4e79e2f8408..38d612da8cd44d8689aecde5d8e5ef1cf5483894 100644 (file)
  */
 void ewmh_update_current_desktop(void);
 
+/**
+ * Updates _NET_NUMBER_OF_DESKTOPS which we interpret as the number of
+ * noninternal workspaces.
+ */
+void ewmh_update_number_of_desktops(void);
+
 /**
  * Updates _NET_ACTIVE_WINDOW with the currently focused window.
  *
index 0c860ad01553d01b01f1cd47e1ff4586be84daf8..7ab0c22adfd2c14e94712af09b1c38bbd33563c0 100644 (file)
@@ -40,6 +40,27 @@ void ewmh_update_current_desktop(void) {
     }
 }
 
+/*
+ * Updates _NET_NUMBER_OF_DESKTOPS which we interpret as the number of
+ * noninternal workspaces.
+ */
+void ewmh_update_number_of_desktops(void) {
+    Con *output;
+    uint32_t idx = 0;
+
+    TAILQ_FOREACH (output, &(croot->nodes_head), nodes) {
+        Con *ws;
+        TAILQ_FOREACH (ws, &(output_get_content(output)->nodes_head), nodes) {
+            if (STARTS_WITH(ws->name, "__"))
+                continue;
+            ++idx;
+        }
+    }
+
+    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
+            A__NET_NUMBER_OF_DESKTOPS, XCB_ATOM_CARDINAL, 32, 1, &idx);
+}
+
 /*
  * Updates _NET_ACTIVE_WINDOW with the currently focused window.
  *
@@ -133,7 +154,7 @@ void ewmh_setup_hints(void) {
         NULL);
     xcb_change_property(conn, XCB_PROP_MODE_REPLACE, child_window, A__NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 32, 1, &child_window);
     xcb_change_property(conn, XCB_PROP_MODE_REPLACE, child_window, A__NET_WM_NAME, A_UTF8_STRING, 8, strlen("i3"), "i3");
-    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 32, 1, &child_window);
+    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 33, 1, &child_window);
 
     /* I’m not entirely sure if we need to keep _NET_WM_NAME on root. */
     xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_WM_NAME, A_UTF8_STRING, 8, strlen("i3"), "i3");
index 632e68c4eef6e0f0a7780ce9645e6a0ffed88066..917ae1cba23982c5e996e0af77e24c72a50a885a 100644 (file)
@@ -765,8 +765,9 @@ int main(int argc, char *argv[]) {
     x_set_i3_atoms();
     ewmh_update_workarea();
 
-    /* Set the _NET_CURRENT_DESKTOP property. */
+    /* Set the ewmh desktop properties. */
     ewmh_update_current_desktop();
+    ewmh_update_number_of_desktops();
 
     struct ev_io *xcb_watcher = scalloc(sizeof(struct ev_io));
     struct ev_io *xkb = scalloc(sizeof(struct ev_io));
index d626d17c92c124001fcc39229834c0d2f2b0bdb4..41c029523e189afc34b47b33d114b733e31a479d 100644 (file)
@@ -92,6 +92,7 @@ Con *workspace_get(const char *num, bool *created) {
         con_attach(workspace, content, false);
 
         ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}");
+        ewmh_update_number_of_desktops();
         if (created != NULL)
             *created = true;
     } else if (created != NULL) {
@@ -424,6 +425,7 @@ static void _workspace_show(Con *workspace) {
             LOG("Closing old workspace (%p / %s), it is empty\n", old, old->name);
             tree_close(old, DONT_KILL_WINDOW, false, false);
             ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"empty\"}");
+            ewmh_update_number_of_desktops();
         }
     }