From 530bda1ceeb92b17e82669e32ef9dd8e35aef2d4 Mon Sep 17 00:00:00 2001 From: Tiago Vignatti Date: Wed, 29 Dec 2010 19:53:55 +0200 Subject: [PATCH app/xrestop] Implement client PID tracking using XRes It relies on version 1.2 of the extension Signed-off-by: Tiago Vignatti --- xrestop.c | 60 +++++++++++++++++++++++++----------------------------------- 1 files changed, 25 insertions(+), 35 deletions(-) diff --git a/xrestop.c b/xrestop.c index 6af2030..0cc8687 100644 --- a/xrestop.c +++ b/xrestop.c @@ -167,31 +167,6 @@ untrap_errors(void) /* Misc util funcs */ -static pid_t -window_get_pid(XResTopApp *app, Window win) -{ - Atom type; - unsigned long bytes_after, n_items; - long *data = NULL; - pid_t result = -1; - int format; - - if (XGetWindowProperty (app->dpy, win, - app->atoms[ATOM_NET_WM_PID], - 0, 2L, - False, XA_CARDINAL, - &type, &format, &n_items, - &bytes_after, (unsigned char **)&data) == Success - && n_items && data != NULL) - { - result = *data; - } - - if (data) XFree(data); - - return result; -} - static char* window_get_utf8_name(XResTopApp *app, Window win) { @@ -390,11 +365,7 @@ xrestop_client_get_info(XResTopApp *app, XResTopClient *client) found = recurse_win_tree(app, client, app->win_root); - if (found) - { - client->pid = window_get_pid(app, found); - } - else + if (!found) { client->identifier = strdup(""); } @@ -465,8 +436,14 @@ xrestop_client_get_stats(XResTopApp *app, XResTopClient *client) static void xrestop_populate_client_data(XResTopApp *app) { - int i; + int i, c; XResClient *clients; + long num_ids; + XResClientIdValue *client_ids; + XResClientIdSpec client_specs[3]; + + client_specs[0].client = None; + client_specs[0].mask = 0; for (i=0; i < app->n_clients; i++) xrestop_client_free(app->clients[i]); @@ -474,6 +451,7 @@ xrestop_populate_client_data(XResTopApp *app) trap_errors(); XResQueryClients(app->dpy, &app->n_clients, &clients); + XResQueryClientIds(app->dpy, 1, client_specs, &num_ids, &client_ids); if (untrap_errors()) { @@ -493,6 +471,16 @@ xrestop_populate_client_data(XResTopApp *app) xrestop_client_get_stats(app, app->clients[i]); } + i = 0; + for(c = 0; c < num_ids; ++c) + { + XResClientIdValue *value = client_ids + c; + if (XResGetClientIdType(value) == XRES_CLIENT_ID_PID) { + app->clients[i]->pid = XResGetClientPid(value); + i++; + } + } + cleanup: if (clients) XFree(clients); @@ -552,11 +540,7 @@ xrestop_display(XResTopApp *app) nice_bytes(pretty_total_bytes, 16, app->clients[i]->pixmap_bytes + app->clients[i]->other_bytes); - if (app->clients[i]->pid > -1) snprintf(pretty_pid, 16, "%5d", app->clients[i]->pid); - else - snprintf(pretty_pid, 16, " ? "); - if (!app->want_batch_mode) { @@ -716,6 +700,12 @@ main(int argc, char **argv) return 1; } + if (major != 1 || minor < 2) { + fprintf(stderr, "Invalid X-Resource extension version %d.%d. " + "Atleast minor 2 expected\n", major, minor); + return 1; + } + app->n_clients = 0; /* Create our own never mapped window so we can figure out this connection */ -- 1.7.0.4