about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteven Allen <steven@stebalien.com>2024-02-04T20·57-0800
committerGitHub <noreply@github.com>2024-02-04T20·57-0800
commitfbc1e81ed65a2a7caeb6e73aab88fe8769e0f952 (patch)
treeb0d569208f97a46ce48b34b49ee0cef08aa779cc
parentc2856d15e8b76e6faec5e2f44a9c80865a39f55a (diff)
Set the EXWM buffer's default directory to match the process's CWD (#14)
* exwm-manage.el (exwm-manage--update-default-directory):
  define a function to update the default-directory of an X window based on it's CID.
  (exwm-manage--manage-window):
  call `exwm-manage--update-update-default-directory` on manage (fixes #12).
-rw-r--r--exwm-manage.el18
1 files changed, 18 insertions, 0 deletions
diff --git a/exwm-manage.el b/exwm-manage.el
index c344c4cfb1..d1eeaa7c87 100644
--- a/exwm-manage.el
+++ b/exwm-manage.el
@@ -234,6 +234,23 @@ Override current hinds if FORCE is non-nil."
                           (elt value 2))) ;MotifWmHints.decorations
               (setq exwm--mwm-hints-decorations nil))))))))
 
+(defun exwm-manage--update-default-directory (id)
+  "Update the `default-directory' of X window ID.
+Sets the `default-directory' of the EXWM buffer associated with X window to
+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))
+              (cwd (file-symlink-p (format "/proc/%d/cwd" pid)))
+              ((file-accessible-directory-p cwd)))
+        (setq default-directory cwd)
+      (setq default-directory (expand-file-name "~/")))))
+
+
 (defun exwm-manage--set-client-list ()
   "Set _NET_CLIENT_LIST."
   (exwm--log)
@@ -400,6 +417,7 @@ Override current hinds if FORCE is non-nil."
       (setq exwm-workspace--switch-history-outdated t)
       (exwm--update-desktop id)
       (exwm-manage--update-ewmh-state id)
+      (exwm-manage--update-default-directory id)
       (when (or (plist-get exwm--configurations 'fullscreen)
                 (exwm-layout--fullscreen-p))
         (setq exwm--ewmh-state (delq xcb:Atom:_NET_WM_STATE_FULLSCREEN