PageRenderTime 36ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/src/clx/dpms.lisp

https://gitlab.com/lexicall/ecl
Lisp | 168 lines | 132 code | 20 blank | 16 comment | 5 complexity | ac25865cd915e2aa46488d563b3f68fd MD5 | raw file
  1. ;;;; Original Author: Matthew Kennedy <mkennedy@gentoo.org>
  2. ;;;;
  3. ;;;; Documentation strings derived from DPMS.txt distributed with the Xorg X11
  4. ;;;; server implementation. DPMS.txt contains the following copyright:
  5. ;;;;
  6. ;;;; Copyright (C) Digital Equipment Corporation, 1996
  7. ;;;;
  8. ;;;; Permission to use, copy, modify, distribute, and sell this documentation
  9. ;;;; for any purpose is hereby granted without fee, provided that the above
  10. ;;;; copyright notice and this permission notice appear in all copies. Digital
  11. ;;;; Equipment Corporation makes no representations about the suitability for
  12. ;;;; any purpose of the information in this document. This documentation is
  13. ;;;; provided ``as is'' without express or implied warranty.
  14. (defpackage :dpms
  15. (:use :common-lisp)
  16. (:import-from :xlib
  17. "DEFINE-EXTENSION"
  18. "DISPLAY"
  19. "WITH-BUFFER-REQUEST-AND-REPLY"
  20. "WITH-BUFFER-REQUEST"
  21. "EXTENSION-OPCODE"
  22. "CARD8-GET"
  23. "CARD16-GET"
  24. "BOOLEAN-GET"
  25. "CARD8"
  26. "CARD16"
  27. "DATA")
  28. (:export "DPMS-GET-VERSION"
  29. "DPMS-CAPABLE"
  30. "DPMS-GET-TIMEOUTS"
  31. "DPMS-SET-TIMEOUTS"
  32. "DPMS-ENABLE"
  33. "DPMS-DISABLE"
  34. "DPMS-FORCE-LEVEL"
  35. "DPMS-INFO"))
  36. (in-package :dpms)
  37. (define-extension "DPMS")
  38. (defmacro dpms-opcode (display)
  39. `(extension-opcode ,display "DPMS"))
  40. (defconstant +get-version+ 0)
  41. (defconstant +capable+ 1)
  42. (defconstant +get-timeouts+ 2)
  43. (defconstant +set-timeouts+ 3)
  44. (defconstant +enable+ 4)
  45. (defconstant +disable+ 5)
  46. (defconstant +force-level+ 6)
  47. (defconstant +info+ 7)
  48. (defun dpms-get-version (display &optional (major-version 1) (minor-version 1))
  49. "Return two values: the major and minor version of the DPMS
  50. implementation the server supports.
  51. If supplied, the MAJOR-VERSION and MINOR-VERSION indicate what
  52. version of the protocol the client wants the server to implement."
  53. (declare (type display display))
  54. (with-buffer-request-and-reply (display (dpms-opcode display) nil)
  55. ((data +get-version+)
  56. (card16 major-version)
  57. (card16 minor-version))
  58. (values (card16-get 8)
  59. (card16-get 10))))
  60. (defun dpms-capable (display)
  61. "True if the currently running server's devices are capable of
  62. DPMS operations.
  63. The truth value of this request is implementation defined, but is
  64. generally based on the capabilities of the graphic card and
  65. monitor combination. Also, the return value in the case of
  66. heterogeneous multi-head servers is implementation defined."
  67. (declare (type display display))
  68. (with-buffer-request-and-reply (display (dpms-opcode display) nil)
  69. ((data +capable+))
  70. (boolean-get 8)))
  71. (defun dpms-get-timeouts (display)
  72. "Return three values: the current values of the DPMS timeout
  73. values. The timeout values are (in order returned): standby,
  74. suspend and off. All values are in units of seconds. A value of
  75. zero for any timeout value indicates that the mode is disabled."
  76. (declare (type display display))
  77. (with-buffer-request-and-reply (display (dpms-opcode display) nil)
  78. ((data +get-timeouts+))
  79. (values (card16-get 8)
  80. (card16-get 10)
  81. (card16-get 12))))
  82. (defun dpms-set-timeouts (display standby suspend off)
  83. "Set the values of the DPMS timeouts. All values are in units
  84. of seconds. A value of zero for any timeout value disables that
  85. mode."
  86. (declare (type display display))
  87. (with-buffer-request (display (dpms-opcode display))
  88. (data +set-timeouts+)
  89. (card16 standby)
  90. (card16 suspend)
  91. (card16 off)
  92. (card16 0)) ;unused
  93. (values))
  94. (defun dpms-enable (display)
  95. "Enable the DPMS characteristics of the server using the
  96. server's currently stored timeouts. If DPMS is already enabled,
  97. no change is affected."
  98. (declare (type display display))
  99. (with-buffer-request (display (dpms-opcode display))
  100. (data +enable+))
  101. (values))
  102. (defun dpms-disable (display)
  103. "Disable the DPMS characteristics of the server. It does not
  104. affect the core or extension screen savers. If DPMS is already
  105. disabled, no change is effected.
  106. This request is provided so that DPMS may be disabled without
  107. damaging the server's stored timeout values."
  108. (declare (type display display))
  109. (with-buffer-request (display (dpms-opcode display))
  110. ((data +disable+)))
  111. (values))
  112. (defun dpms-force-level (display power-level)
  113. "Forces a specific DPMS level on the server. Valid keyword
  114. values for POWER-LEVEL are: DPMS-MODE-ON, DPMS-MODE-STANDBY,
  115. DPMS-MODE-SUSPEND and DPMS-MODE-OFF."
  116. (declare (type display display))
  117. (with-buffer-request (display (dpms-opcode display))
  118. (data +force-level+)
  119. (card16 (ecase power-level
  120. (:dpms-mode-on 0)
  121. (:dpms-mode-standby 1)
  122. (:dpms-mode-suspend 2)
  123. (:dpms-mode-off 3)))
  124. (card16 0)) ;unused
  125. (values))
  126. (defun dpms-info (display)
  127. "Returns two valus: the DPMS power-level and state value for the display.
  128. State is one of the keywords DPMS-ENABLED or DPMS-DISABLED.
  129. If state is DPMS-ENABLED, then power level is returned as one of
  130. the keywords DPMS-MODE-ON, DPMS-MODE-STANDBY, DPMS-MODE-SUSPEND
  131. or DPMS-MODE-OFF. If state is DPMS-DISABLED, then power-level is
  132. undefined and returned as NIL."
  133. (declare (type display display))
  134. (with-buffer-request-and-reply (display (dpms-opcode display) nil)
  135. ((data +info+))
  136. (let ((state (if (boolean-get 10)
  137. :dpms-enabled
  138. :dpms-disabled)))
  139. (values (unless (eq state :dpms-disabled)
  140. (ecase (card16-get 8)
  141. (0 :dpms-mode-on)
  142. (1 :dpms-mode-standby)
  143. (2 :dpms-mode-suspend)
  144. (3 :dpms-mode-off)))
  145. state))))
  146. ;;; Local Variables:
  147. ;;; indent-tabs-mode: nil
  148. ;;; End: