Support cycling through display configurations
Today when I opened my laptop, I wasn't sure if it was powered off or on because the display was blank. Thankfully the volume was muted and the LED indicator was on, which informed me that the laptop was powered on. This saved me from unnecessarily rebooting. What happened was that last night I was working from home and using my external monitor. Usually I enable my external display and disable my laptop display. But when I left for work this morning, I unplugged the HDMI cable from my laptop without disabling the external display or enabling the laptop display. I noticed a XF86 button on my laptop entitled XF86Display. I figured that this could be a nice place to bind a key to toggle my laptop display on or off. At the last minute, I had the idea to just cycle through all possible display configurations that I use; there are only three anyways. When dealing with more than two states, I realized I should use a cycle to model the configuration states. Now I'm thinking that I should be using cycles to model toggles as well - instead of just using a top-level variable that I `setq` over. I haven't refactored existing toggles to be cycles, but I am excited about this new keybinding. This commit additionally: - Moves keybindings out of display.el and into keybindings.el - Conditionally sets KBDs if using work laptop
This commit is contained in:
parent
61be808a92
commit
d81f31107d
2 changed files with 31 additions and 18 deletions
|
@ -18,14 +18,12 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(require 'prelude)
|
||||
(require 'cycle)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Constants
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defconst display/install-kbds? t
|
||||
"When t, install the keybindings defined in this module.")
|
||||
|
||||
;; TODO: Consider if this logic should be conditioned by `device/work-laptop?'.
|
||||
(defconst display/laptop-monitor "eDP1"
|
||||
"The xrandr identifier for my primary screen (on work laptop).")
|
||||
|
@ -34,6 +32,11 @@
|
|||
(defconst display/4k-monitor "HDMI1"
|
||||
"The xrandr identifer for my 4K monitor.")
|
||||
|
||||
(defconst display/display-states (cycle/from-list '((t . t) (t . nil) (nil . t)))
|
||||
"A list of cons cells modelling enabled and disabled states for my displays.
|
||||
The car models the enabled state of my laptop display; the cdr models the
|
||||
enabled state of my external monitor.")
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Library
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -78,21 +81,12 @@ Sometimes this is useful when I'm sharing my screen in a Google Hangout and I
|
|||
:command (string/format "xrandr --output %s --off"
|
||||
display/laptop-monitor)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Keybindings
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(when display/install-kbds?
|
||||
(general-define-key
|
||||
:prefix "<SPC>"
|
||||
:states '(normal)
|
||||
"d0" #'display/disable-laptop
|
||||
"d1" #'display/enable-laptop)
|
||||
(general-define-key
|
||||
:prefix "<SPC>"
|
||||
:states '(normal)
|
||||
"D0" #'display/disable-4k
|
||||
"D1" #'display/enable-4k))
|
||||
(defun display/cycle-display-states ()
|
||||
"Cycle through `display/display-states' enabling and disabling displays."
|
||||
(interactive)
|
||||
(let ((state (cycle/next display/display-states)))
|
||||
(if (car state) (display/enable-laptop) (display/disable-laptop))
|
||||
(if (cdr state) (display/enable-4k) (display/disable-4k))))
|
||||
|
||||
(provide 'display)
|
||||
;;; display.el ends here
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
(require 'window-manager)
|
||||
(require 'vterm-mgt)
|
||||
(require 'buffer)
|
||||
(require 'display)
|
||||
(require 'device)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Configuration
|
||||
|
@ -66,5 +68,22 @@
|
|||
"<C-S-iso-lefttab>" #'vterm-mgt-prev
|
||||
"<s-backspace>" #'vterm-mgt-rename-buffer)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Displays
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(when (device/work-laptop?)
|
||||
(keybinding/exwm "<XF86Display>" #'display/cycle-display-states)
|
||||
(general-define-key
|
||||
:prefix "<SPC>"
|
||||
:states '(normal)
|
||||
"d0" #'display/disable-laptop
|
||||
"d1" #'display/enable-laptop)
|
||||
(general-define-key
|
||||
:prefix "<SPC>"
|
||||
:states '(normal)
|
||||
"D0" #'display/disable-4k
|
||||
"D1" #'display/enable-4k))
|
||||
|
||||
(provide 'keybindings)
|
||||
;;; keybindings.el ends here
|
||||
|
|
Loading…
Reference in a new issue