The Complete Computer

External Display Test Functions

LifeTechEmacsArcology
emacs-lisp source: 
(provide 'cce/display-test-functions)

Calculating the display density is a pain in the ass because it's easier to parse xrandr output than it is to integrate with libXrandr. I guess I could write an elisp wrapper for it, but I would rather not right now. open threads

emacs-lisp source: 
(defun cce/external-display-dpis () "Returns a list of integers, the DPI of the connected external Display Port displays. assumes square pixels, sorry." (let (results (xrandr-buffer (get-buffer-create " *xrandr*"))) (with-current-buffer xrandr-buffer (erase-buffer) (call-process-shell-command "xrandr" nil xrandr-buffer) (goto-char (point-min)) (setq-local results nil) (while (re-search-forward "^\\([^e][a-zA-Z]+\\(-?[0-9]+\\)+\\)" nil t) (when-let* ((eol (save-excursion (end-of-line) (point))) (display-name (match-string 1)) (is-connected (re-search-forward "connected \\(primary \\)?\\([0-9]+\\)x\\([0-9]+\\)" eol t)) (pixels (string-to-number (match-string 3))) (has-physical (re-search-forward "\\([0-9]+\\)mm x \\([0-9]+\\)mm" eol)) (physical (string-to-number (match-string 2))) (dpi (if (equal 0 physical) 140 (floor (* 25.4 (/ (float pixels) physical)))))) (add-to-list 'results (cons display-name dpi)))) results))) (defun cce/external-display-connected () "returns t if there are external displayport monitors connected." (let ((dpis (cce/external-display-dpis))) (> (length dpis) 0))) (defun cce/connected-displays () "Returns a list of displays currently connceted" (append (list "eDP-1") (mapcar (lambda (cons) (car cons)) (cce/external-display-dpis)))) (defun cce/exwm-connected-displays () "Return a list of displays for [`exwm-randr-workspace-monitor-plist']" (apply #'append (seq-map-indexed (lambda (elt idx) (list idx elt)) (cce/connected-displays))))