]> git.sur5r.net Git - i3/i3/commitdiff
Implement EWMH desktop names
authorTony Crisci <tony@dubstepdish.com>
Mon, 23 Jun 2014 21:44:24 +0000 (17:44 -0400)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 24 Jun 2014 07:04:05 +0000 (09:04 +0200)
Maintain the _NET_DESKTOP_NAMES property on the root window.

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

> _NET_DESKTOP_NAMES
>
> _NET_DESKTOP_NAMES, UTF8_STRING[]
>
> The names of all virtual desktops. This is a list of NULL-terminated
> strings in UTF-8 encoding [UTF8]. This property MAY be changed by a
> Pager or the Window Manager at any time.

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

index ccae87c572715aef3591ea2e35689bc910893cd0..cb928dc05eac9bd7632d054649df65f2e4ba1334 100644 (file)
@@ -17,6 +17,7 @@ xmacro(_NET_CLIENT_LIST)
 xmacro(_NET_CLIENT_LIST_STACKING)
 xmacro(_NET_CURRENT_DESKTOP)
 xmacro(_NET_NUMBER_OF_DESKTOPS)
+xmacro(_NET_DESKTOP_NAMES)
 xmacro(_NET_DESKTOP_VIEWPORT)
 xmacro(_NET_ACTIVE_WINDOW)
 xmacro(_NET_STARTUP_ID)
index 99ff655e4c81bc4770b8d145c0a3d59aa8bdda26..3b5806285b4f66badec03fd7d2bb513601cb997d 100644 (file)
@@ -24,6 +24,12 @@ void ewmh_update_current_desktop(void);
  */
 void ewmh_update_number_of_desktops(void);
 
+/**
+ * Updates _NET_DESKTOP_NAMES: "The names of all virtual desktops. This is a
+ * list of NULL-terminated strings in UTF-8 encoding"
+ */
+void ewmh_update_desktop_names(void);
+
 /**
  * Updates _NET_DESKTOP_VIEWPORT, which is an array of pairs of cardinals that
  * define the top left corner of each desktop's viewport.
index 50180b71db93d4e638e69660ff169b3472058d58..bf9942e2d46caa67f64eab9b75f9e7162e007beb 100644 (file)
@@ -1987,6 +1987,9 @@ void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name) {
     ysuccess(true);
 
     ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"rename\"}");
+    ewmh_update_desktop_names();
+    ewmh_update_desktop_viewport();
+    ewmh_update_current_desktop();
 }
 
 /*
index 433a202b59c4397a1ca5bc3b9aaf8f95c3b647a4..da5dba5fe8c8fda5b5044095adfaf03898f7f313 100644 (file)
@@ -61,6 +61,44 @@ void ewmh_update_number_of_desktops(void) {
                         A__NET_NUMBER_OF_DESKTOPS, XCB_ATOM_CARDINAL, 32, 1, &idx);
 }
 
+/*
+ * Updates _NET_DESKTOP_NAMES: "The names of all virtual desktops. This is a
+ * list of NULL-terminated strings in UTF-8 encoding"
+ */
+void ewmh_update_desktop_names(void) {
+    Con *output;
+    int msg_length = 0;
+
+    /* count the size of the property message to set */
+    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;
+            msg_length += strlen(ws->name) + 1;
+        }
+    }
+
+    char desktop_names[msg_length];
+    int current_position = 0;
+
+    /* fill the buffer with the names of the i3 workspaces */
+    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;
+
+            for (size_t i = 0; i < strlen(ws->name) + 1; i++) {
+                desktop_names[current_position++] = ws->name[i];
+            }
+        }
+    }
+
+    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
+                        A__NET_DESKTOP_NAMES, A_UTF8_STRING, 8, msg_length, desktop_names);
+}
+
 /*
  * Updates _NET_DESKTOP_VIEWPORT, which is an array of pairs of cardinals that
  * define the top left corner of each desktop's viewport.
@@ -196,5 +234,5 @@ void ewmh_setup_hints(void) {
     /* 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");
 
-    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTED, XCB_ATOM_ATOM, 32, 20, supported_atoms);
+    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, A__NET_SUPPORTED, XCB_ATOM_ATOM, 32, 21, supported_atoms);
 }
index 67024e6e9aca432444f8f8e6ec4dddab04f91544..773843470417a467c353ab7985d9e05d5074aa9d 100644 (file)
@@ -674,6 +674,7 @@ int main(int argc, char *argv[]) {
     /* Set the ewmh desktop properties. */
     ewmh_update_current_desktop();
     ewmh_update_number_of_desktops();
+    ewmh_update_desktop_names();
     ewmh_update_desktop_viewport();
 
     struct ev_io *xcb_watcher = scalloc(sizeof(struct ev_io));
index 2dcab4fa0f8d2f1d1d31e8ac1d4822f8be94d3a2..f585f2d5c2c1f9f949b69839a5a3023fc8a923cd 100644 (file)
@@ -93,6 +93,7 @@ Con *workspace_get(const char *num, bool *created) {
 
         ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}");
         ewmh_update_number_of_desktops();
+        ewmh_update_desktop_names();
         ewmh_update_desktop_viewport();
         if (created != NULL)
             *created = true;
@@ -419,6 +420,7 @@ static void _workspace_show(Con *workspace) {
             tree_close(old, DONT_KILL_WINDOW, false, false);
             ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"empty\"}");
             ewmh_update_number_of_desktops();
+            ewmh_update_desktop_names();
             ewmh_update_desktop_viewport();
         }
     }