2019-10-09 13:13:56 +02:00
|
|
|
;;; display.el --- Working with single or multiple displays -*- lexical-binding: t -*-
|
2020-09-01 11:17:43 +02:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
2020-09-01 11:17:43 +02:00
|
|
|
;; Version: 0.0.1
|
|
|
|
;; URL: https://git.wpcarro.dev/wpcarro/briefcase
|
|
|
|
;; Package-Requires: ((emacs "24"))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
;;; 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:
|
|
|
|
|
2019-12-23 18:31:42 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(require 'prelude)
|
2020-02-11 12:00:24 +01:00
|
|
|
(require 'cycle)
|
2019-12-23 18:31:42 +01:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Constants
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
;; TODO: Consider if this logic should be conditioned by `device-work-laptop?'.
|
|
|
|
(defconst display-laptop-monitor "eDP1"
|
2019-10-09 13:13:56 +02:00
|
|
|
"The xrandr identifier for my primary screen (on work laptop).")
|
|
|
|
|
2020-01-11 21:01:57 +01:00
|
|
|
;; TODO: Why is HDMI-1, eDP-1 sometimes and HDMI1, eDP1 other times.
|
2020-09-01 11:17:43 +02:00
|
|
|
(defconst display-4k-monitor "HDMI1"
|
2019-10-09 13:13:56 +02:00
|
|
|
"The xrandr identifer for my 4K monitor.")
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defconst display-display-states (cycle-from-list '((t . nil) (nil . t)))
|
2020-02-11 12:00:24 +01:00
|
|
|
"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.")
|
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Library
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-01-15 23:14:51 +01:00
|
|
|
;; TODO: Debug why something this scales to 4k appropriately and other times it
|
|
|
|
;; doesn't.
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun display-enable-4k ()
|
2019-10-09 13:13:56 +02:00
|
|
|
"Attempt to connect to my 4K monitor."
|
|
|
|
(interactive)
|
2020-08-31 18:05:31 +02:00
|
|
|
(prelude-start-process
|
2020-09-01 11:17:43 +02:00
|
|
|
:name "display-enable-4k"
|
2020-09-01 00:28:47 +02:00
|
|
|
:command (string-format
|
2020-02-02 13:16:27 +01:00
|
|
|
"xrandr --output %s --above %s --primary --auto --size 3840x2160 --rate 30.00 --dpi 144"
|
2020-09-01 11:17:43 +02:00
|
|
|
display-4k-monitor
|
|
|
|
display-laptop-monitor)))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun display-disable-4k ()
|
2019-10-09 13:13:56 +02:00
|
|
|
"Disconnect from the 4K monitor."
|
|
|
|
(interactive)
|
2020-08-31 18:05:31 +02:00
|
|
|
(prelude-start-process
|
2020-09-01 11:17:43 +02:00
|
|
|
:name "display-disable-4k"
|
2020-09-01 00:28:47 +02:00
|
|
|
:command (string-format "xrandr --output %s --off"
|
2020-09-01 11:17:43 +02:00
|
|
|
display-4k-monitor)))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun display-enable-laptop ()
|
2020-01-16 02:18:32 +01:00
|
|
|
"Turn the laptop monitor off.
|
|
|
|
Sometimes this is useful when I'm sharing my screen in a Google Hangout and I
|
|
|
|
only want to present one of my monitors."
|
|
|
|
(interactive)
|
2020-08-31 18:05:31 +02:00
|
|
|
(prelude-start-process
|
2020-09-01 11:17:43 +02:00
|
|
|
:name "display-disable-laptop"
|
2020-09-01 00:28:47 +02:00
|
|
|
:command (string-format "xrandr --output %s --auto"
|
2020-09-01 11:17:43 +02:00
|
|
|
display-laptop-monitor)))
|
2020-01-16 02:18:32 +01:00
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun display-disable-laptop ()
|
2020-01-16 02:18:32 +01:00
|
|
|
"Turn the laptop monitor off.
|
|
|
|
Sometimes this is useful when I'm sharing my screen in a Google Hangout and I
|
|
|
|
only want to present one of my monitors."
|
|
|
|
(interactive)
|
2020-08-31 18:05:31 +02:00
|
|
|
(prelude-start-process
|
2020-09-01 11:17:43 +02:00
|
|
|
:name "display-disable-laptop"
|
2020-09-01 00:28:47 +02:00
|
|
|
:command (string-format "xrandr --output %s --off"
|
2020-09-01 11:17:43 +02:00
|
|
|
display-laptop-monitor)))
|
2020-01-16 02:18:32 +01:00
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun display-cycle-display-states ()
|
|
|
|
"Cycle through `display-display-states' enabling and disabling displays."
|
2020-02-11 12:00:24 +01:00
|
|
|
(interactive)
|
2020-09-01 11:17:43 +02:00
|
|
|
(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))))
|
2020-01-13 11:27:26 +01:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
(provide 'display)
|
|
|
|
;;; display.el ends here
|