From f4e456a0ad1440d2fb96c2023db386d0504954c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 24 Jan 2020 18:42:37 +0100 Subject: [PATCH] module/i3: 'pid' is not a standard property of windows event Don't fail (and terminate the i3 plugin) if we receive a window event where the 'container' doesn't have a 'pid' property. This means we won't be able to determine the application the window belongs to. Closes #2 --- modules/i3.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/i3.c b/modules/i3.c index 9eb0a0a..bc6a8a6 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -350,11 +350,10 @@ handle_window_event(int type, const struct json_object *json, void *_mod) } - struct json_object *container, *id, *name, *pid; + struct json_object *container, *id, *name; if (!json_object_object_get_ex(json, "container", &container) || !json_object_object_get_ex(container, "id", &id) || - !json_object_object_get_ex(container, "name", &name) || - !json_object_object_get_ex(container, "pid", &pid)) + !json_object_object_get_ex(container, "name", &name)) { mtx_unlock(&mod->lock); return false; @@ -382,6 +381,8 @@ handle_window_event(int type, const struct json_object *json, void *_mod) */ struct json_object *app_id; + struct json_object *pid; + if (json_object_object_get_ex(container, "app_id", &app_id) && json_object_get_string(app_id) != NULL) { @@ -391,7 +392,9 @@ handle_window_event(int type, const struct json_object *json, void *_mod) } /* If PID has changed, update application name from /proc//comm */ - else if (ws->window.pid != json_object_get_int(pid)) { + else if (json_object_object_get_ex(container, "pid", &pid) && + ws->window.pid != json_object_get_int(pid)) + { ws->window.pid = json_object_get_int(pid); char path[64];