diff options
author | Vincent Ambo <tazjin@tvl.su> | 2023-11-25T14·39+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-11-25T15·24+0000 |
commit | dedcfc3d71260543bea0052bcb71cf4705720dd6 (patch) | |
tree | 59b1fbc4f83810af72067747d13322338ace41cf /users/tazjin/emacs | |
parent | 512346ba0b85c89fc0d16558962c3a946a8c98c3 (diff) |
feat(tazjin/emacs): add interactive commands for configuring screens r/7056
Uses a bunch of weird xrandr invocations and completing reads to configure screens the way I want. Note that this has a known bug where disconnecting a primary screen will *not* make one of the remaining screens primary. Change-Id: Ide5322df446685cc4740d4ddd7b6ca8682375050 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10120 Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/emacs')
-rw-r--r-- | users/tazjin/emacs/config/desktop.el | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/users/tazjin/emacs/config/desktop.el b/users/tazjin/emacs/config/desktop.el index 51a3f208481d..856265bcdb73 100644 --- a/users/tazjin/emacs/config/desktop.el +++ b/users/tazjin/emacs/config/desktop.el @@ -346,6 +346,58 @@ ring." (exwm-input-set-key (kbd "s-m 2") #'randr-khamovnik-layout-office) (exwm-input-set-key (kbd "s-m s") #'randr-khamovnik-layout-single))) +(defun list-available-monitors () + "List connected, but unused monitors." + (let* ((all-connected + (seq-map (lambda (line) (car (s-split " " line))) + (s-lines (s-trim (shell-command-to-string "xrandr | grep connected | grep -v disconnected"))))) + (all-active (seq-map #'car (cadr (exwm-randr--get-monitors))))) + (seq-filter (lambda (s) (not (seq-contains-p all-active s))) + all-connected))) + +(defun exwm-enable-monitor () + "Interactively construct an EXWM invocation that enable the +given monitor and assigns a workspace to it." + (interactive) + + (let* ((monitors (list-available-monitors)) + (primary (car (exwm-randr--get-monitors))) + (monitor (pcase (seq-length monitors) + (0 (error "No available monitors.")) + (1 (car monitors)) + (_ + (completing-read "Which monitor? " (list-available-monitors) nil t)))) + + (configurations `(("secondary (left)" . ,(format "--left-of %s" primary)) + ("secondary (right)" . ,(format "--right-of %s" primary)) + ("primary (left)" . ,(format "--left-of %s --primary" primary)) + ("primary (right)" . ,(format "--right-of %s --primary" primary)) + ("mirror" . ,(format "--same-as %s" primary)))) + + (where (completing-read (format "%s should be " monitor) + (seq-map #'car configurations) + nil t)) + (xrandr-pos (cdr (assoc where configurations))) + (xrandr-cmd (format "xrandr --output %s --auto %s" monitor xrandr-pos))) + (message "Invoking '%s'" xrandr-cmd) + (shell-command xrandr-cmd) + (exwm-assign-workspaces))) + +(defun exwm-disable-monitor () + "Interactively choose a monitor to disable." + (interactive) + + (let* ((active (seq-map #'car (cadr (exwm-randr--get-monitors)))) + (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) + (exwm-assign-workspaces))) + +(exwm-input-set-key (kbd "s-m e") #'exwm-enable-monitor) +(exwm-input-set-key (kbd "s-m d") #'exwm-disable-monitor) + ;; Notmuch shortcuts as EXWM globals ;; (g m => gmail) (exwm-input-set-key (kbd "s-g m") #'notmuch) |