From a9c094b7313b48491c182a5da1194a0bb06747aa Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 23 Jun 2014 17:44:24 -0400 Subject: [PATCH] Implement EWMH desktop names 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 | 1 + include/ewmh.h | 6 ++++++ src/commands.c | 3 +++ src/ewmh.c | 40 +++++++++++++++++++++++++++++++++++++++- src/main.c | 1 + src/workspace.c | 2 ++ 6 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/atoms.xmacro b/include/atoms.xmacro index ccae87c5..cb928dc0 100644 --- a/include/atoms.xmacro +++ b/include/atoms.xmacro @@ -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) diff --git a/include/ewmh.h b/include/ewmh.h index 99ff655e..3b580628 100644 --- a/include/ewmh.h +++ b/include/ewmh.h @@ -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. diff --git a/src/commands.c b/src/commands.c index 50180b71..bf9942e2 100644 --- a/src/commands.c +++ b/src/commands.c @@ -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(); } /* diff --git a/src/ewmh.c b/src/ewmh.c index 433a202b..da5dba5f 100644 --- a/src/ewmh.c +++ b/src/ewmh.c @@ -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); } diff --git a/src/main.c b/src/main.c index 67024e6e..77384347 100644 --- a/src/main.c +++ b/src/main.c @@ -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)); diff --git a/src/workspace.c b/src/workspace.c index 2dcab4fa..f585f2d5 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -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(); } } -- 2.39.5