summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2019-10-07 10:08:42 -0700
committerKeith Packard <keithp@keithp.com>2019-10-07 10:08:42 -0700
commit19f72d344367a2bd250b5700f412625b249a90fd (patch)
treee33a4c08764ad406c416a27e064d157fef9d3a9a
parent956c0e145a87d2b19144d820c33c3d64ac348043 (diff)
Use XResQueryClientIds to get pid instead of window property
Using the extension is more reliable than a window property, plus works for clients which have no windows. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--xrestop.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/xrestop.c b/xrestop.c
index c3e2d3a..c8577d4 100644
--- a/xrestop.c
+++ b/xrestop.c
@@ -374,17 +374,12 @@ xrestop_client_get_info(XResTopApp *app, XResTopClient *client)
== (app->win_dummy & ~client->resource_mask) )
{
client->identifier = strdup("xrestop");
- client->pid = getpid();
return;
}
found = recurse_win_tree(app, client, app->win_root);
- if (found)
- {
- client->pid = window_get_pid(app, found);
- }
- else
+ if (!found)
{
client->identifier = strdup("<unknown>");
}
@@ -397,6 +392,14 @@ xrestop_client_get_stats(XResTopApp *app, XResTopClient *client)
XResType *types = NULL;
int n_types;
+ XResClientIdSpec client_specs = {
+ .client = client->resource_base,
+ .mask = XRES_CLIENT_ID_PID_MASK
+ };
+
+ long num_ids;
+ XResClientIdValue *client_ids = NULL;
+
trap_errors();
XResQueryClientResources (app->dpy, client->resource_base, &n_types, &types);
@@ -404,6 +407,8 @@ xrestop_client_get_stats(XResTopApp *app, XResTopClient *client)
XResQueryClientPixmapBytes (app->dpy, client->resource_base,
&client->pixmap_bytes);
+ XResQueryClientIds (app->dpy, 1, &client_specs, &num_ids, &client_ids);
+
if (untrap_errors())
{
app->n_xerrors++;
@@ -435,6 +440,15 @@ xrestop_client_get_stats(XResTopApp *app, XResTopClient *client)
else client->n_other += types[j].count;
}
+ for (j = 0; j < num_ids; j++)
+ {
+ if (client_ids[j].spec.mask == XRES_CLIENT_ID_PID_MASK && client_ids[j].length == sizeof(uint32_t)) {
+ uint32_t pid;
+ memcpy(&pid, client_ids[j].value, sizeof(uint32_t));
+ client->pid = pid;
+ }
+ }
+
/* All approx currently - same as gnome system monitor */
client->other_bytes += client->n_windows * 24;
client->other_bytes += client->n_gcs * 24;
@@ -448,6 +462,7 @@ xrestop_client_get_stats(XResTopApp *app, XResTopClient *client)
cleanup:
XFree(types);
+ XFree(client_ids);
return;
}