branch: externals/exwm
commit 22cba35ad9f8f21fcabdd35278e44691d231fdbe
Author: Steven Allen <[email protected]>
Commit: Steven Allen <[email protected]>

    Add a new exwm-manage-get-pid function
    
    * exwm-manage.el (exwm-manage-get-pid): Add a new function to get the
    PID of the current X window.
    (exwm-manage--update-mwm-hints): Use it.
---
 exwm-manage.el | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/exwm-manage.el b/exwm-manage.el
index 9f06a2c352..2cb0c15790 100644
--- a/exwm-manage.el
+++ b/exwm-manage.el
@@ -180,6 +180,17 @@ want to match against EXWM internal variables such as 
`exwm-title',
 (declare-function exwm-workspace--update-workareas "exwm-workspace.el" ())
 (declare-function exwm-workspace--workarea "exwm-workspace.el" (frame))
 
+(defun exwm-manage-get-pid (&optional id)
+  "Return the PID of the X window ID, if known.
+
+If ID is unspecified, the PID of the current window is returned."
+  (unless id (setq id (exwm--buffer->id (window-buffer))))
+  (when-let* ((response
+               (and id (xcb:+request-unchecked+reply exwm--connection
+                           (make-instance 'xcb:ewmh:get-_NET_WM_PID
+                                          :window id)))))
+    (slot-value response 'value)))
+
 (defun exwm-manage--update-geometry (id &optional force)
   "Update geometry of X window ID.
 Override current geometry if FORCE is non-nil."
@@ -240,10 +251,7 @@ match its current working directory.
 
 This only works when procfs is mounted, which may not be the case on some 
BSDs."
   (with-current-buffer (exwm--id->buffer id)
-    (if-let* ((response (xcb:+request-unchecked+reply exwm--connection
-                            (make-instance 'xcb:ewmh:get-_NET_WM_PID
-                                           :window id)))
-              (pid (slot-value response 'value))
+    (if-let* ((pid (exwm-manage-get-pid))
               (cwd (file-symlink-p (format "/proc/%d/cwd" pid)))
               ((file-accessible-directory-p cwd)))
         (setq default-directory (file-name-as-directory cwd))

Reply via email to