about summary refs log tree commit diff
path: root/users/tazjin/emacs/config/desktop.el
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@tvl.su>2023-11-25T14·47+0300
committerclbot <clbot@tvl.fyi>2023-11-25T15·24+0000
commit53008771ae57d229bb7eb642aefeb65a08bcb9d1 (patch)
treed7ec029cba6ba8dcbed010b40f98d4bae82eeddb /users/tazjin/emacs/config/desktop.el
parentdedcfc3d71260543bea0052bcb71cf4705720dd6 (diff)
fix(tazjin/emacs): pick new primary monitor when disabling current r/7057
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
Diffstat (limited to 'users/tazjin/emacs/config/desktop.el')
-rw-r--r--users/tazjin/emacs/config/desktop.el18
1 files 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)