From 62bf51d706c14b3c4261a7b780a479ba1a05df5a Mon Sep 17 00:00:00 2001 From: Akos Horvath Date: Sat, 25 Nov 2023 13:57:49 +0100 Subject: [PATCH] add pid field to client --- src/client.c | 20 +++++++++++++++----- src/client.h | 2 ++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/client.c b/src/client.c index 1f55ff2..dda1f92 100644 --- a/src/client.c +++ b/src/client.c @@ -20,6 +20,7 @@ along with this program. If not, see . #include "client.h" #include "util.h" #include "wm.h" +#include #include #include #include @@ -74,6 +75,7 @@ Client* wm_client_create(Wm *wm, Window w) c->hidden = true; c->is_floating = false; c->name = NULL; + c->is_pid_set = false; if (xtp.value) { strln = strlen((char*)xtp.value); @@ -88,8 +90,21 @@ Client* wm_client_create(Wm *wm, Window w) wm_client_set_atom(wm, c, "_NET_WM_DESKTOP", (unsigned char*)&c->ws->index, XA_CARDINAL, 1); + unsigned char *prop_ret = NULL; + unsigned long nitems_ret; + Atom type; + bool is_normal = false; + type = wm_client_get_atom(wm, c, "_NET_WM_PID", &prop_ret, &nitems_ret); + if (!nitems_ret || !prop_ret) goto ret; + + c->pid = *((int*)prop_ret); + DEBUG_PRINT("pid: %d\n", c->pid); + c->is_pid_set = true; + +ret: XFree(xtp.value); + if (prop_ret) XFree(prop_ret); return c; } @@ -308,11 +323,6 @@ Atom wm_client_get_atom(Wm *wm, Client *c, const char *name, unsigned char **ato DEBUG_PRINT("actual format return: %d\n", format_ret) DEBUG_PRINT("actual number of items return: %ld\n", *nitems_ret) DEBUG_PRINT("bytes remaining: %ld\n", *nitems_ret) - for (int i = 0; i < *nitems_ret; i++) { - char *atom_name = XGetAtomName(wm->display, ((Atom*)*atom_ret)[i]); - printf("property return str: %s\n", atom_name); - XFree(atom_name); - } return type_ret; } diff --git a/src/client.h b/src/client.h index 448e577..b17c65c 100644 --- a/src/client.h +++ b/src/client.h @@ -44,6 +44,8 @@ struct Client { bool focused; bool has_border; bool is_floating; + pid_t pid; + bool is_pid_set; }; XWindowChanges wm_client_to_xwchanges(Client *c);