
Untitled
By: a guest on
Jul 11th, 2012 | syntax:
None | size: 1.44 KB | hits: 15 | expires: Never
;; This file is built for ECL
;;;;;;;;;;;;;;;;
;;;; compilation
;; > ecl
;; (compile-file "monitor-screen-rotation.lisp" :system-p t)
;; (c:build-program "monitor-screen-rotation" :lisp-files '("monitor-screen-rotation.o") :epilogue-code '(start))
(declaim (optimize (speed 3) (safety 0) (debug 0)))
;;;;;;;;;;;;;;;;;;;;
;;;; supporting code
(declaim (inline run! sys-tablet-p))
(defun run! (command &rest arguments)
"Runs the script at <command> with arguments <arguments>"
(ext:run-program command arguments)) ;; ecl-specific
;;;;;;;;;;;
;;;; output
(let ((normal "/home/madnificent/bin/rotate_normal")
(tablet "/home/madnificent/bin/rotate_left"))
(defun rotate (mode)
"Allows you to switch the screen to tablet mode and back.
<mode> must be one of :laptop or :tablet"
(if (eq mode :laptop)
(run! normal)
(run! tablet))))
;;;;;;;;;;
;;;; input
(defun sys-tablet-p ()
"Returns the tablet value as exported by the hp-wmi driver
non-nil means we're in laptop mode
nil means we're in tablet mode"
(with-open-file (s "/sys/devices/platform/hp-wmi/tablet")
(let ((line (read-line s)))
(if (eql (parse-integer line) 0)
:laptop
:tablet))))
;;;;;;;;;;;;;;;;;
;;;; control loop
(defun start ()
(let ((mode :laptop))
(loop for new-mode = (sys-tablet-p)
do (progn
(unless (eq mode new-mode)
(setf mode new-mode)
(rotate mode))
(sleep 1)))))