forked from external/yambar
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/<pid>/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.
This commit is contained in:
parent
86522d653d
commit
9675b86478
1 changed files with 20 additions and 1 deletions
21
modules/i3.c
21
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.title = title != NULL ? strdup(title) : NULL;
|
||||||
ws->window.id = json_object_get_int(id);
|
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/<pid>/comm */
|
/* If PID has changed, update application name from /proc/<pid>/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);
|
ws->window.pid = json_object_get_int(pid);
|
||||||
|
|
||||||
char path[64];
|
char path[64];
|
||||||
|
@ -398,6 +416,7 @@ handle_window_event(int type, const struct json_object *json, void *_mod)
|
||||||
free(ws->window.application);
|
free(ws->window.application);
|
||||||
ws->window.application = strdup(application);
|
ws->window.application = strdup(application);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
LOG_DBG("application: \"%s\", via 'pid'", ws->window.application);
|
||||||
}
|
}
|
||||||
|
|
||||||
m->dirty = true;
|
m->dirty = true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue