From fbc1e81ed65a2a7caeb6e73aab88fe8769e0f952 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sun, 4 Feb 2024 12:57:58 -0800 Subject: 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). --- exwm-manage.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 -- cgit 1.4.1