[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [STUMP] Lisp toggle code / xrandr projector control
From: |
Roderick Hoybach |
Subject: |
Re: [STUMP] Lisp toggle code / xrandr projector control |
Date: |
Thu, 01 May 2014 13:02:31 -0700 |
User-agent: |
mu4e 0.9.9.5; emacs 24.3.1 |
Hi Johnny,
I have also been doing some fiddling with projectors. I do have one
command that toggles between enabling and disabling the projector,
though the rest of the features that you are looking for are still
missing. I have been thinking of finding a "greatest common resolution"
between the projector and primary monitor's available resolutions,
though haven't added that yet.
Perhaps the following might be useful for you, though at the very least
the output names and the resolution would need to changed:
---------BEGIN---------
(defcommand projector-toggle () ()
"Toggle the projector (mirrorred display) on or off."
(let ((xrandr-q (run-shell-command "xrandr -q" t)))
(with-input-from-string (s xrandr-q)
;; If an output is on, xrandr shows its mode after the "NAME connected"
;; and before the parentheses.
(let* ((displays (loop for line = (read-line s nil :EOF)
until (eql line :EOF)
for matches = (multiple-value-bind (str matches)
(ppcre:scan-to-strings
"^(.+) connected (.*)\\("
line)
(declare (ignore str))
matches)
when matches
;; matches[0] = output name
;; matches[1] = current mode (if connected)
collect (cons (svref matches 0)
(if (string= (svref matches 1) "")
:OFF
:ON))))
(vga (find "VGA" displays :test #'ppcre:scan :key #'car))
(lvds (find "LVDS" displays :test #'ppcre:scan :key #'car)))
(when vga
(if (eql (cdr vga) :off)
(run-shell-command
(format nil
"xrandr --output ~A --mode 1024x768 --same-as ~A
--output ~A --mode 1024x768"
(car vga)
(car lvds)
(car lvds)))
(run-shell-command
(format nil "xrandr --output ~A --off --output ~A --auto"
(car vga)
(car lvds)))))))))
----------END----------
Best regards,
Roderick