EXWM: Fix monitor switch

master
Pierre Neidhardt 2019-01-13 15:31:56 +01:00
parent d2af6c783f
commit 376eca4c90
1 changed files with 13 additions and 2 deletions

View File

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