From 9675b86478e469e01795f5291f547a128cb12a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 24 Jan 2020 21:23:21 +0100 Subject: [PATCH] module/i3: window event: use 'app_id' for 'application', if available We previously used the 'pid' property of the 'container' object in a window event to lookup the application name under /proc//comm. In many cases, the application name is already available in the window event itself, in the 'app_id' property. Use this, if available, and fallback to the old PID method otherwise. A quick experiment suggests 'app_id' is set for all Wayland native applications, but not for X11 applications running under XWayland. --- modules/i3.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/i3.c b/modules/i3.c index 6f4299e..9eb0a0a 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -372,8 +372,26 @@ handle_window_event(int type, const struct json_object *json, void *_mod) ws->window.title = title != NULL ? strdup(title) : NULL; ws->window.id = json_object_get_int(id); + /* + * Sway only! + * + * Use 'app_id' for 'application' tag, if it exists. + * + * Otherwise, use 'pid' if it exists, and read application name + * from /proc/zpid>/comm + */ + + struct json_object *app_id; + if (json_object_object_get_ex(container, "app_id", &app_id) && + json_object_get_string(app_id) != NULL) + { + free(ws->window.application); + ws->window.application = strdup(json_object_get_string(app_id)); + LOG_DBG("application: \"%s\", via 'app_id'", ws->window.application); + } + /* If PID has changed, update application name from /proc//comm */ - if (ws->window.pid != json_object_get_int(pid)) { + else if (ws->window.pid != json_object_get_int(pid)) { ws->window.pid = json_object_get_int(pid); char path[64]; @@ -398,6 +416,7 @@ handle_window_event(int type, const struct json_object *json, void *_mod) free(ws->window.application); ws->window.application = strdup(application); close(fd); + LOG_DBG("application: \"%s\", via 'pid'", ws->window.application); } m->dirty = true;