-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-dpi.el
42 lines (35 loc) · 1.35 KB
/
get-dpi.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(require 'cl-lib)
(defun get-dpi ()
(or (get-dpi-connected) 0))
(defun get-dpi-connected ()
(with-temp-buffer
(insert (shell-command-to-string "xrandr"))
(keep-lines " connected" (point-min) (point-max))
(when (< 0 (cl-first (wc-count)))
(gd--compute-dpi))))
;; (defun gd--compute-dpi ()
;; (let* ((line (buffer-substring-no-properties (point-min)
;; (point-max)))
;; (words (split-string line " "))
;; (n (max (or (cl-position "connected" words :test #'equal) 0)
;; (or (cl-position "primary" words :test #'equal) 0)))
;; (sz (nth (1+ n) words))
;; (sx (first (split-string sz "[x+]" )))
;; (sy (second (split-string sz "[x+]" )))
;; (lx (caddr (reverse words)))
;; (ly (first (reverse words))))
;; (pcase-let ((`(,sx ,sy ,lx ,ly) (mapcar #'string-to-number
;; `(,sx ,sy ,lx ,ly))))
;; (* 0.5 25.4 (+ (/ sx lx 1.0) (/ sy ly 1.0))))
;; ))
(defun gd--compute-dpi ()
(pcase-let
((`(x0 y0 ,W ,H) (frame-monitor-attribute 'geometry))
(`(,Wmm ,Hmm) (frame-monitor-attribute 'mm-size)))
(* 0.5 25.4
(+ (/ W Wmm 1.0)
(/ H Hmm 1.0)))))
(defun insert-dpi ()
(interactive)
(insert (number-to-string (get-dpi))))
(provide 'get-dpi)