tvl-depot/configs/shared/.emacs.d/wpc/display.el
William Carroll 88a315eee1 Support keybindings for using 4k monitor
I'm not sure I'm sold on the "D{0,1}" keybindings. The thought was that 0 would
indicate off and 1 would indicate on. This seems sensible to me. I'm hesitant
because I don't think I have precedent for this idiom in any of my existing
keybindings.

I'm also not sure I like these being leader-prefixed keybindings.
2020-01-17 10:56:21 +00:00

67 lines
2.1 KiB
EmacsLisp

;;; display.el --- Working with single or multiple displays -*- lexical-binding: t -*-
;; Author: William Carroll <wpcarro@gmail.com>
;;; Commentary:
;; Mostly wrappers around xrandr.
;;
;; TODO: Look into autorandr to see if it could be useful.
;;
;; Troubleshooting:
;; The following commands help me when I (infrequently) interact with xrandr.
;; - xrandr --listmonitors
;; - xrandr --query
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Dependencies
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'prelude)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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).")
;; TODO: Why is HDMI-1, eDP-1 sometimes and HDMI1, eDP1 other times.
(defconst display/4k-monitor "HDMI1"
"The xrandr identifer for my 4K monitor.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Library
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun display/enable-4k ()
"Attempt to connect to my 4K monitor."
(interactive)
(prelude/start-process
:name "display/enable-4k"
:command (string/format
"xrandr --output %s --above %s --primary --auto --dpi 144"
display/4k-monitor
display/laptop-monitor)))
(defun display/disable-4k ()
"Disconnect from the 4K monitor."
(interactive)
(prelude/start-process
:name "display/disable-4k"
:command (string/format "xrandr --output %s --off"
display/4k-monitor)))
(when display/install-kbds?
(general-define-key
:prefix "<SPC>"
:states '(normal)
"D0" #'display/disable-4k
"D1" #'display/enable-4k))
(provide 'display)
;;; display.el ends here