From b8e3f5a536343865b2fd2dfffb023ed927331a01 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 23 Dec 2022 12:25:19 +0100 Subject: [PATCH] shell: Move _NET_WM_PID query to NaTrayChild It already does some other poking on the plug window, it can do this as well. Part-of: --- src/shell-tray-icon.c | 28 +--------------------------- src/tray/na-tray-child.c | 34 ++++++++++++++++++++++++++++++++++ src/tray/na-tray-child.h | 3 +++ 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/shell-tray-icon.c b/src/shell-tray-icon.c index cac801654..9b3076549 100644 --- a/src/shell-tray-icon.c +++ b/src/shell-tray-icon.c @@ -238,18 +238,10 @@ shell_tray_icon_set_child (ShellTrayIcon *tray_icon, NaTrayChild *tray_child) { MetaDisplay *display = shell_global_get_display (shell_global_get ()); - MetaX11Display *x11_display; - Display *xdisplay; - Window plug_xid; - Atom type; - int result, format; - gulong nitems, bytes_after, *val = NULL; g_return_if_fail (tray_icon != NULL); g_return_if_fail (tray_child != NULL); - x11_display = meta_display_get_x11_display (display); - /* We do all this now rather than computing it on the fly later, * because the shell may want to see their values from a * tray-icon-removed signal handler, at which point the plug has @@ -261,25 +253,7 @@ shell_tray_icon_set_child (ShellTrayIcon *tray_icon, tray_icon->title = na_tray_child_get_title (tray_icon->tray_child); na_tray_child_get_wm_class (tray_icon->tray_child, NULL, &tray_icon->wm_class); - - plug_xid = na_xembed_get_plug_window (NA_XEMBED (tray_icon->tray_child)); - - xdisplay = meta_x11_display_get_xdisplay (x11_display); - meta_x11_error_trap_push (x11_display); - result = XGetWindowProperty (xdisplay, plug_xid, - XInternAtom (xdisplay, "_NET_WM_PID", False), - 0, G_MAXLONG, False, XA_CARDINAL, - &type, &format, &nitems, - &bytes_after, (guchar **)&val); - - if (!meta_x11_error_trap_pop_with_return (x11_display) && - result == Success && - type == XA_CARDINAL && - nitems == 1) - tray_icon->pid = *val; - - if (val) - XFree (val); + tray_icon->pid = na_tray_child_get_pid (tray_icon->tray_child); tray_icon->window_created_handler = g_signal_connect (display, diff --git a/src/tray/na-tray-child.c b/src/tray/na-tray-child.c index 1f1bae9b1..cec02e458 100644 --- a/src/tray/na-tray-child.c +++ b/src/tray/na-tray-child.c @@ -219,3 +219,37 @@ na_tray_child_get_wm_class (NaTrayChild *child, res_class, res_name); } + +pid_t +na_tray_child_get_pid (NaTrayChild *child) +{ + MetaX11Display *x11_display; + Display *xdisplay; + Atom type; + int result, format; + gulong nitems, bytes_after, *val = NULL; + pid_t pid = 0; + + x11_display = na_xembed_get_x11_display (NA_XEMBED (child)); + xdisplay = meta_x11_display_get_xdisplay (x11_display); + + xdisplay = meta_x11_display_get_xdisplay (x11_display); + meta_x11_error_trap_push (x11_display); + result = XGetWindowProperty (xdisplay, + na_xembed_get_plug_window (NA_XEMBED (child)), + XInternAtom (xdisplay, "_NET_WM_PID", False), + 0, G_MAXLONG, False, XA_CARDINAL, + &type, &format, &nitems, + &bytes_after, (guchar **)&val); + + if (!meta_x11_error_trap_pop_with_return (x11_display) && + result == Success && + type == XA_CARDINAL && + nitems == 1) + pid = *val; + + if (val) + XFree (val); + + return pid; +} diff --git a/src/tray/na-tray-child.h b/src/tray/na-tray-child.h index c50a0f928..ce1aaf9f6 100644 --- a/src/tray/na-tray-child.h +++ b/src/tray/na-tray-child.h @@ -37,6 +37,9 @@ void na_tray_child_get_wm_class (NaTrayChild *child, char **res_name, char **res_class); +pid_t na_tray_child_get_pid (NaTrayChild *child); + + G_END_DECLS #endif /* __NA_TRAY_CHILD_H__ */