diff --git a/init.el b/init.el index cb7e9c4..70e57e9 100644 --- a/init.el +++ b/init.el @@ -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