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.
|
|
|
|
;;
|
|
|
|
;; 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
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Library
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-09-28 14:41:24 +02:00
|
|
|
(cl-defmacro display-register (name &key
|
|
|
|
output
|
|
|
|
primary
|
|
|
|
position
|
|
|
|
size
|
|
|
|
rate
|
|
|
|
dpi
|
|
|
|
rotate)
|
|
|
|
"Macro to define a constant and two functions for {en,dis}abling a display.
|
|
|
|
|
|
|
|
NAME - the human-readable identifier for the display
|
|
|
|
OUTPUT - the xrandr identifier for the display
|
|
|
|
PRIMARY - if true, send --primary flag to xrandr
|
|
|
|
POSITION - one of {left-of,right-of,above,below,same-as}
|
|
|
|
SIZE - the pixel resolution of the display
|
|
|
|
RATE - the refresh rate
|
|
|
|
DPI - the pixel density in dots per square inch
|
|
|
|
rotate - one of {normal,left,right,inverted}
|
|
|
|
|
|
|
|
See the man-page for xrandr for more details."
|
|
|
|
`(progn
|
|
|
|
(defconst ,(intern (format "display-%s" name)) ,output
|
|
|
|
,(format "The xrandr identifier for %s" name))
|
|
|
|
(defun ,(intern (format "display-enable-%s" name)) ()
|
|
|
|
,(format "Attempt to enable my %s monitor" name)
|
|
|
|
(interactive)
|
|
|
|
(prelude-start-process
|
|
|
|
:name ,(format "display-enable-%s" name)
|
|
|
|
:command ,(format
|
2020-09-29 11:10:24 +02:00
|
|
|
"xrandr --output %s --%s %s --auto --size %dx%d --rate %0.2f --dpi %d --rotate %s"
|
2020-09-28 14:41:24 +02:00
|
|
|
output
|
|
|
|
(if primary "primary" "noprimary")
|
2020-09-29 11:10:24 +02:00
|
|
|
(if position
|
|
|
|
(format "--%s %s"
|
|
|
|
(car position)
|
|
|
|
(eval (cadr position)))
|
|
|
|
"")
|
2020-09-28 14:41:24 +02:00
|
|
|
(car size) (cadr size)
|
|
|
|
rate
|
|
|
|
dpi
|
|
|
|
rotate)))
|
|
|
|
(defun ,(intern (format "display-disable-%s" name)) ()
|
|
|
|
,(format "Attempt to disable my %s monitor." name)
|
|
|
|
(interactive)
|
|
|
|
(prelude-start-process
|
|
|
|
:name ,(format "display-disable-%s" name)
|
|
|
|
:command ,(format
|
|
|
|
"xrandr --output %s --off"
|
|
|
|
output)))))
|
|
|
|
|
2020-09-29 11:10:24 +02:00
|
|
|
;; I'm omitting the position argument to avoid a circular dependency between
|
|
|
|
;; laptop and 4k-horizontal.
|
2020-09-28 14:41:24 +02:00
|
|
|
(display-register laptop
|
|
|
|
:output "eDP1"
|
|
|
|
:primary nil
|
|
|
|
:size (3840 2160)
|
|
|
|
:rate 30.0
|
|
|
|
:dpi 144
|
|
|
|
:rotate normal)
|
|
|
|
|
|
|
|
(display-register 4k-horizontal
|
|
|
|
:output "HDMI1"
|
|
|
|
:primary t
|
|
|
|
:position (above display-laptop)
|
|
|
|
:size (3840 2160)
|
|
|
|
:rate 30.0
|
|
|
|
:dpi 144
|
|
|
|
:rotate normal)
|
|
|
|
|
|
|
|
(display-register 4k-vertical
|
|
|
|
:output "DP2"
|
|
|
|
:primary nil
|
|
|
|
:position (right-of display-4k-horizontal)
|
|
|
|
:size (3840 2160)
|
|
|
|
:rate 30.0
|
|
|
|
:dpi 144
|
|
|
|
:rotate right)
|
2020-01-13 11:27:26 +01:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
(provide 'display)
|
|
|
|
;;; display.el ends here
|