Take another crack at making sure WAYLAND_DISPLAY is set

This commit is contained in:
Alexander Rosenberg 2024-12-26 18:19:52 -08:00
parent 0d1d4e10c1
commit 54e58aca7e
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

22
init.el
View File

@ -703,6 +703,28 @@ in the region and indents once)."
(funcall oldfun type)))
(advice-add 'xclip-get-selection :around 'my/-xclip-detect-wl-paste-error))
;; Set the WAYLAND_DISPLAY environment variable
(require 'xdg)
(defun my/detect-wayland-display ()
"Try to set the WAYLAND_DISPLAY environment variable.
This attempts to detect a running Wayland session and set the WAYLAND_DISPLAY
environment variable accordingly."
(let ((found '(nil . nil)))
(dolist (entry (directory-files-and-attributes
(xdg-runtime-dir) nil nil 'nosort)
(cdr found))
(cl-destructuring-bind (name . attrs) entry
(when-let (((string-match (rx bos "wayland-" (group (+ (any "0-9"))) eos)
name))
(id (string-to-number (match-string 1 name)))
((or (not (car found)) (< id (car found))))
;; socket
((string-prefix-p "s" (file-attribute-modes attrs))))
(setq found (cons id name)))))))
(unless (getenv "WAYLAND_DISPLAY")
(setenv "WAYLAND_DISPLAY" (my/detect-wayland-display)))
;; which-key
(use-package which-key
:diminish which-key-mode