Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 11th, 2012  |  syntax: None  |  size: 1.44 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ;; This file is built for ECL
  2.  
  3. ;;;;;;;;;;;;;;;;
  4. ;;;; compilation
  5. ;; > ecl
  6. ;; (compile-file "monitor-screen-rotation.lisp" :system-p t)
  7. ;; (c:build-program "monitor-screen-rotation" :lisp-files '("monitor-screen-rotation.o") :epilogue-code '(start))
  8.  
  9. (declaim (optimize (speed 3) (safety 0) (debug 0)))
  10.  
  11. ;;;;;;;;;;;;;;;;;;;;
  12. ;;;; supporting code
  13. (declaim (inline run! sys-tablet-p))
  14.  
  15. (defun run! (command &rest arguments)
  16.   "Runs the script at <command> with arguments <arguments>"
  17.   (ext:run-program command arguments)) ;; ecl-specific
  18.  
  19. ;;;;;;;;;;;
  20. ;;;; output
  21. (let ((normal "/home/madnificent/bin/rotate_normal")
  22.       (tablet "/home/madnificent/bin/rotate_left"))
  23.   (defun rotate (mode)
  24.     "Allows you to switch the screen to tablet mode and back.
  25.  <mode> must be one of :laptop or :tablet"
  26.     (if (eq mode :laptop)
  27.         (run! normal)
  28.         (run! tablet))))
  29.  
  30. ;;;;;;;;;;
  31. ;;;; input
  32. (defun sys-tablet-p ()
  33.   "Returns the tablet value as exported by the hp-wmi driver
  34.    non-nil means we're in laptop mode
  35.    nil means we're in tablet mode"
  36.   (with-open-file (s "/sys/devices/platform/hp-wmi/tablet")
  37.     (let ((line (read-line s)))
  38.       (if (eql (parse-integer line) 0)
  39.           :laptop
  40.           :tablet))))
  41.  
  42. ;;;;;;;;;;;;;;;;;
  43. ;;;; control loop
  44. (defun start ()
  45.   (let ((mode :laptop))
  46.     (loop for new-mode = (sys-tablet-p)
  47.        do (progn
  48.             (unless (eq mode new-mode)
  49.               (setf mode new-mode)
  50.               (rotate mode))
  51.             (sleep 1)))))