From d9496152e3f427e3c783043b6ce3263532c805ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 8 Dec 2020 19:08:06 +0100 Subject: [PATCH] =?UTF-8?q?module/i3:=20add=20new=20tag=20=E2=80=98mode?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This tag is a string: the name of the currently active mode --- CHANGELOG.md | 1 + doc/yambar-modules.5.scd | 3 +++ modules/i3.c | 30 ++++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46ecdeb..f5301e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ list is sorted. Can be set to one of `none`, `ascending` or `descending`. Default is `none` (https://codeberg.org/dnkl/yambar/issues/17). +* i3: `mode` tag: the name of the currently active mode ### Deprecated diff --git a/doc/yambar-modules.5.scd b/doc/yambar-modules.5.scd index 693f502..5bc15e1 100644 --- a/doc/yambar-modules.5.scd +++ b/doc/yambar-modules.5.scd @@ -361,6 +361,9 @@ with the _application_ and _title_ tags to replace the X11-only | title : string : This workspace's focused window's title +| mode +: string +: The name of the current mode ## CONFIGURATION diff --git a/modules/i3.c b/modules/i3.c index 02bd575..89083ce 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -49,6 +49,8 @@ struct private { bool dirty; + char *mode; + struct { struct ws_content *v; size_t count; @@ -459,6 +461,25 @@ handle_window_event(int type, const struct json_object *json, void *_mod) return true; } +static bool +handle_mode_event(int type, const struct json_object *json, void *_mod) +{ + struct module *mod = _mod; + struct private *m = mod->private; + + struct json_object *change; + if (!json_object_object_get_ex(json, "change", &change)) { + LOG_ERR("mode event without 'change' property"); + return false; + } + + const char *current_mode = json_object_get_string(change); + free(m->mode); + m->mode = strdup(current_mode); + m->dirty = true; + return true; +} + static void burst_done(void *_mod) { @@ -492,7 +513,7 @@ run(struct module *mod) } i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_VERSION, NULL); - i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\", \"window\"]"); + i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\", \"window\", \"mode\"]"); i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); static const struct i3_ipc_callbacks callbacks = { @@ -502,6 +523,7 @@ run(struct module *mod) .reply_workspaces = &handle_get_workspaces_reply, .event_workspace = &handle_workspace_event, .event_window = &handle_window_event, + .event_mode = &handle_mode_event, }; bool ret = i3_receive_loop(mod->abort_fd, sock, &callbacks, mod); @@ -523,6 +545,7 @@ destroy(struct module *mod) free(m->ws_content.v); workspaces_free(m); + free(m->mode); free(m); module_default_destroy(mod); } @@ -578,8 +601,10 @@ content(struct module *mod) tag_new_string(mod, "application", ws->window.application), tag_new_string(mod, "title", ws->window.title), + + tag_new_string(mod, "mode", m->mode), }, - .count = 7, + .count = 8, }; if (ws->focused) { @@ -620,6 +645,7 @@ i3_new(struct i3_workspaces workspaces[], size_t workspace_count, { struct private *m = calloc(1, sizeof(*m)); + m->mode = strdup("default"); m->left_spacing = left_spacing; m->right_spacing = right_spacing;