message.scm.in 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!@GUILE@
  2. !#
  3. ;;; message.scm --- Display a message in OSD
  4. ;; Copyright © 2016 Alex Kost <alezost@gmail.com>
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;;
  10. ;; This program is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;;
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This script displays an OSD in a fancy manner.
  19. ;;; Code:
  20. (use-modules (xosd))
  21. (define (setup-osd osd)
  22. (set-osd-position! osd 'middle)
  23. (set-osd-align! osd 'center)
  24. (set-osd-font! osd "-*-dejavu sans-bold-r-normal-*-*-300-*-*-p-*-*-1")
  25. (set-osd-color! osd "yellow")
  26. (set-osd-outline-color! osd "red")
  27. (set-osd-outline-offset! osd 1))
  28. (define* (display-by-chars string osd #:key (timeout 200000))
  29. "Display STRING in the OSD object by characters.
  30. Sleep for TIMEOUT (microseconds) after each character."
  31. (let ((number-of-chars (string-length string)))
  32. (let loop ((char-number 1))
  33. (when (<= char-number number-of-chars)
  34. (display-string-in-osd osd (substring string 0 char-number))
  35. (usleep timeout)
  36. (loop (1+ char-number))))))
  37. (define* (shake-osd osd #:key (timeout 50000) (shift 10))
  38. "Shake the OSD object a bit."
  39. (let loop ((shift shift))
  40. (when (> shift 0)
  41. (set-osd-vertical-offset! osd shift)
  42. (usleep timeout)
  43. (set-osd-horizontal-offset! osd (- shift))
  44. (usleep timeout)
  45. (set-osd-vertical-offset! osd (- shift))
  46. (usleep timeout)
  47. (set-osd-horizontal-offset! osd shift)
  48. (usleep timeout)
  49. (loop (1- shift)))))
  50. (when (batch-mode?)
  51. (let ((osd (make-osd)))
  52. (setup-osd osd)
  53. (display-by-chars "Guile-XOSD is great!!" osd)
  54. (shake-osd osd)))
  55. ;;; message.scm ends here