diff options
author | Jan Novotný <[email protected]> | 2022-11-07 15:32:33 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2022-11-12 17:27:19 +0100 |
commit | d3add65f6960dd3c95aaa2fe63cc8c563747695d (patch) | |
tree | dda02a7007261af5bd0b911a431772e9055801dd /src | |
parent | 85ce3f72a00c620aa7631b33eba1e8f4fc8b131f (diff) | |
download | marco-d3add65f6960dd3c95aaa2fe63cc8c563747695d.tar.bz2 marco-d3add65f6960dd3c95aaa2fe63cc8c563747695d.tar.xz |
replace _NET_WM_PID with XResGetClientPid (#741)
window-props: use XResQueryClientIds to get pid
_NET_WM_PID is unreliable! It can be faked or pid might be from
different namespace. Ignore _NET_WM_PID and use XResQueryClientIds
to get pid.
https://gitlab.gnome.org/GNOME/metacity/-/commit/bcbe966511362a8eb8c8c64035ab160086c931f8
Diffstat (limited to 'src')
-rw-r--r-- | src/core/window-props.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/core/window-props.c b/src/core/window-props.c index fb8ac4c1..b5883ad1 100644 --- a/src/core/window-props.c +++ b/src/core/window-props.c @@ -47,6 +47,7 @@ #include "frame-private.h" #include "group.h" #include <X11/Xatom.h> +#include <X11/extensions/XRes.h> #include <unistd.h> #include <string.h> #include <errno.h> @@ -294,11 +295,56 @@ reload_wm_window_role (MetaWindow *window, meta_window_update_role (window); } +static pid_t +get_local_pid (MetaWindow *window) +{ + pid_t pid; + XResClientIdSpec spec; + long num_ids; + XResClientIdValue *client_ids; + long i; + + pid = -1; + + spec.client = window->xwindow; + spec.mask = XRES_CLIENT_ID_PID_MASK; + + XResQueryClientIds (window->display->xdisplay, + 1, + &spec, + &num_ids, + &client_ids); + + for (i = 0; i < num_ids; i++) + { + if (client_ids[i].spec.mask == XRES_CLIENT_ID_PID_MASK) + { + pid = XResGetClientPid (&client_ids[i]); + break; + } + } + + XResClientIdsDestroy (num_ids, client_ids); + + return pid; +} + static void reload_net_wm_pid (MetaWindow *window, MetaPropValue *value, gboolean initial) { + pid_t pid; + + pid = get_local_pid (window); + + if (pid != -1) + { + meta_verbose ("Using XResGetClientPid instead of _NET_WM_PID\n"); + + window->net_wm_pid = pid; + return; + } if (value->type != META_PROP_VALUE_INVALID) { gulong cardinal = (int) value->v.cardinal; |