From 53008771ae57d229bb7eb642aefeb65a08bcb9d1 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 25 Nov 2023 17:47:04 +0300 Subject: 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 Reviewed-by: tazjin Tested-by: BuildkiteCI --- users/tazjin/emacs/config/desktop.el | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/users/tazjin/emacs/config/desktop.el b/users/tazjin/emacs/config/desktop.el index 856265bcdb..7bb15da85c 100644 --- a/users/tazjin/emacs/config/desktop.el +++ b/users/tazjin/emacs/config/desktop.el @@ -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) -- cgit 1.4.1