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).
This commit is contained in:
Steven Allen 2024-02-04 12:57:58 -08:00 committed by GitHub
parent c2856d15e8
commit fbc1e81ed6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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