window: Add get_client_pid() method

It is often useful to identify the client process that created
a particular window, however the existing meta_window_get_pid()
method relies on _NET_WM_PID, which is only available on X11 and
depends on applications to set it correctly (which may not even
be possible when the app runs in its own PID namespace as Flatpak
apps do). So add a get_client_pid() method that uses windowing
system facilities to resolve the PID associated with a particular
window.

https://bugzilla.gnome.org/show_bug.cgi?id=772613
This commit is contained in:
Florian Müllner
2016-10-07 17:55:32 +02:00
parent f89162ee73
commit 1fab6e69b7
5 changed files with 78 additions and 0 deletions

View File

@ -253,6 +253,12 @@ meta_window_real_update_icon (MetaWindow *window,
return FALSE;
}
static uint32_t
meta_window_real_get_client_pid (MetaWindow *window)
{
return 0;
}
static void
meta_window_finalize (GObject *object)
{
@ -420,6 +426,7 @@ meta_window_class_init (MetaWindowClass *klass)
klass->update_struts = meta_window_real_update_struts;
klass->get_default_skip_hints = meta_window_real_get_default_skip_hints;
klass->update_icon = meta_window_real_update_icon;
klass->get_client_pid = meta_window_real_get_client_pid;
obj_props[PROP_TITLE] =
g_param_spec_string ("title",
@ -7055,6 +7062,21 @@ meta_window_get_transient_for (MetaWindow *window)
return NULL;
}
/**
* meta_window_get_client_pid:
* @window: a #MetaWindow
*
* Returns the pid of the process that created this window, if available
* to the windowing system.
*
* Return value: the pid, or 0 if not known.
*/
uint32_t
meta_window_get_client_pid (MetaWindow *window)
{
return META_WINDOW_GET_CLASS (window)->get_client_pid (window);
}
/**
* meta_window_get_pid:
* @window: a #MetaWindow