diff --git a/.emacs.d/lisp/init-exwm.el b/.emacs.d/lisp/init-exwm.el index 35cafadf..d81d9a73 100644 --- a/.emacs.d/lisp/init-exwm.el +++ b/.emacs.d/lisp/init-exwm.el @@ -195,6 +195,7 @@ ;; Function to automatically toggle between internal/external screens. (defun ambrevar/exwm-change-screen-hook () (let ((xrandr-output-regexp "\n\\([^ ]+\\) connected ") + (xrandr-monitor-regexp "\n .* \\([^ \n]+\\)") default-output) (with-temp-buffer (call-process "xrandr" nil t nil) @@ -203,12 +204,22 @@ (setq default-output (match-string 1)) (forward-line) (if (not (re-search-forward xrandr-output-regexp nil 'noerror)) - (call-process "xrandr" nil nil nil "--output" default-output "--auto") + (progn + (call-process "xrandr" nil nil nil "--output" default-output "--auto" "--primary") + (with-temp-buffer + ;; Turn off all monitors that are not DEFAULT-OUTPUT. + ;; See "--auto" in xrandr(1) and https://github.com/ch11ng/exwm/issues/529. + (call-process "xrandr" nil t nil "--listactivemonitors") + (goto-char (point-min)) + (while (not (eobp)) + (when (and (re-search-forward xrandr-monitor-regexp nil 'noerror) + (not (string= (match-string 1) default-output))) + (call-process "xrandr" nil nil nil "--output" (match-string 1) "--auto"))))) (call-process "xrandr" nil nil nil "--output" (match-string 1) "--primary" "--auto" "--output" default-output "--off") - (setq exwm-randr-workspace-output-plist (list 0 (match-string 1))))))) + (setq exwm-randr-workspace-monitor-plist (list 0 (match-string 1))))))) (require 'exwm-randr) (add-hook 'exwm-randr-screen-change-hook 'ambrevar/exwm-change-screen-hook)