[mutter] window: Cache the client PID



commit 4fac1a4862592fdb60a493722f0a3778132d5ff9
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Mon Apr 6 20:08:12 2020 +0200

    window: Cache the client PID
    
    Since the PID of a window can't change as long as the window exists, we
    can safely cache it after we got a valid PID once, so do that by adding
    a new `window->client_pid` private property.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1180

 src/core/window-private.h | 2 ++
 src/core/window.c         | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/src/core/window-private.h b/src/core/window-private.h
index d6de1256c..ed5d8059b 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -548,6 +548,8 @@ struct _MetaWindow
   } placement;
 
   guint unmanage_idle_id;
+
+  pid_t client_pid;
 };
 
 struct _MetaWindowClass
diff --git a/src/core/window.c b/src/core/window.c
index b2a7be5dd..d7faf00fc 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -1149,6 +1149,8 @@ _meta_window_shared_new (MetaDisplay         *display,
   window->is_remote = FALSE;
   window->startup_id = NULL;
 
+  window->client_pid = 0;
+
   window->xtransient_for = None;
   window->xclient_leader = None;
 
@@ -7595,7 +7597,10 @@ meta_window_get_pid (MetaWindow *window)
 {
   g_return_val_if_fail (META_IS_WINDOW (window), 0);
 
-  return META_WINDOW_GET_CLASS (window)->get_client_pid (window);
+  if (window->client_pid == 0)
+    window->client_pid = META_WINDOW_GET_CLASS (window)->get_client_pid (window);
+
+  return window->client_pid;
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]