fix(tazjin/emacs): pick new primary monitor when disabling current

By default, this will be the (only) remaining monitor. In N>2
situations, ask the user.

Change-Id: Id68fcf60d56d0414d1072b8ffeef72c608678f52
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10121
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2023-11-25 17:47:04 +03:00 committed by clbot
parent dedcfc3d71
commit 53008771ae

View file

@ -387,12 +387,24 @@ given monitor and assigns a workspace to it."
"Interactively choose a monitor to disable."
(interactive)
(let* ((active (seq-map #'car (cadr (exwm-randr--get-monitors))))
(let* ((all (exwm-randr--get-monitors))
(active (seq-map #'car (cadr all)))
(monitor (if (> (seq-length active) 1)
(completing-read "Disable which monitor? " active nil t)
(error "Only one monitor is active!")))
(xrandr-cmd (format "xrandr --output %s --off" monitor)))
(shell-command xrandr-cmd)
;; If this monitor was primary, pick another active one instead.
(remaining (seq-filter (lambda (s) (not (equal s monitor))) active))
(new-primary
(when (equal monitor (car all))
(pcase (seq-length remaining)
(1 (car remaining))
(_ (completing-read "New primary? " remaining nil t))))))
(when new-primary
(shell-command (format "xrandr --output %s --primary" new-primary)))
(shell-command (format "xrandr --output %s --off" monitor))
(exwm-assign-workspaces)))
(exwm-input-set-key (kbd "s-m e") #'exwm-enable-monitor)