PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/nx-3.5.0/nx-X11/lib/Xext/DPMS.c

#
C | 293 lines | 206 code | 45 blank | 42 comment | 15 complexity | c64c1ed8edcc786977796820e51e9dc1 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. /* $Xorg: DPMS.c,v 1.3 2000/08/17 19:45:50 cpqbld Exp $ */
  2. /*****************************************************************
  3. Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts.
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software.
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  14. DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
  15. BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
  16. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  17. IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. Except as contained in this notice, the name of Digital Equipment Corporation
  19. shall not be used in advertising or otherwise to promote the sale, use or other
  20. dealings in this Software without prior written authorization from Digital
  21. Equipment Corporation.
  22. ******************************************************************/
  23. /* $XFree86: xc/lib/Xext/DPMS.c,v 3.5 2002/10/16 00:37:27 dawes Exp $ */
  24. /*
  25. * HISTORY
  26. */
  27. #define NEED_REPLIES
  28. #ifdef HAVE_CONFIG_H
  29. #include <config.h>
  30. #endif
  31. #include <X11/Xlibint.h>
  32. #include <X11/extensions/dpms.h>
  33. #include <X11/extensions/dpmsstr.h>
  34. #include <X11/extensions/Xext.h>
  35. #include <X11/extensions/extutil.h>
  36. #include <stdio.h>
  37. static XExtensionInfo _dpms_info_data;
  38. static XExtensionInfo *dpms_info = &_dpms_info_data;
  39. static char *dpms_extension_name = DPMSExtensionName;
  40. #define DPMSCheckExtension(dpy,i,val) \
  41. XextCheckExtension (dpy, i, dpms_extension_name, val)
  42. /*****************************************************************************
  43. * *
  44. * private utility routines *
  45. * *
  46. *****************************************************************************/
  47. static int close_display(Display *dpy, XExtCodes *codes);
  48. static /* const */ XExtensionHooks dpms_extension_hooks = {
  49. NULL, /* create_gc */
  50. NULL, /* copy_gc */
  51. NULL, /* flush_gc */
  52. NULL, /* free_gc */
  53. NULL, /* create_font */
  54. NULL, /* free_font */
  55. close_display, /* close_display */
  56. NULL, /* wire_to_event */
  57. NULL, /* event_to_wire */
  58. NULL, /* error */
  59. NULL /* error_string */
  60. };
  61. static XEXT_GENERATE_FIND_DISPLAY (find_display, dpms_info,
  62. dpms_extension_name,
  63. &dpms_extension_hooks, DPMSNumberEvents,
  64. NULL)
  65. static XEXT_GENERATE_CLOSE_DISPLAY (close_display, dpms_info)
  66. /*****************************************************************************
  67. * *
  68. * public routines *
  69. * *
  70. *****************************************************************************/
  71. Bool
  72. DPMSQueryExtension (Display *dpy, int *event_basep, int *error_basep)
  73. {
  74. XExtDisplayInfo *info = find_display (dpy);
  75. if (XextHasExtension(info)) {
  76. *event_basep = info->codes->first_event;
  77. *error_basep = info->codes->first_error;
  78. return True;
  79. } else {
  80. return False;
  81. }
  82. }
  83. Status
  84. DPMSGetVersion(Display *dpy, int *major_versionp, int *minor_versionp)
  85. {
  86. XExtDisplayInfo *info = find_display (dpy);
  87. xDPMSGetVersionReply rep;
  88. register xDPMSGetVersionReq *req;
  89. DPMSCheckExtension (dpy, info, 0);
  90. LockDisplay (dpy);
  91. GetReq (DPMSGetVersion, req);
  92. req->reqType = info->codes->major_opcode;
  93. req->dpmsReqType = X_DPMSGetVersion;
  94. if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
  95. UnlockDisplay (dpy);
  96. SyncHandle ();
  97. return 0;
  98. }
  99. *major_versionp = rep.majorVersion;
  100. *minor_versionp = rep.minorVersion;
  101. UnlockDisplay (dpy);
  102. SyncHandle ();
  103. return 1;
  104. }
  105. Bool
  106. DPMSCapable(Display *dpy)
  107. {
  108. XExtDisplayInfo *info = find_display (dpy);
  109. register xDPMSCapableReq *req;
  110. xDPMSCapableReply rep;
  111. DPMSCheckExtension (dpy, info, 0);
  112. LockDisplay(dpy);
  113. GetReq(DPMSCapable, req);
  114. req->reqType = info->codes->major_opcode;
  115. req->dpmsReqType = X_DPMSCapable;
  116. if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
  117. UnlockDisplay(dpy);
  118. SyncHandle();
  119. return False;
  120. }
  121. UnlockDisplay(dpy);
  122. SyncHandle();
  123. return rep.capable;
  124. }
  125. Status
  126. DPMSSetTimeouts(Display *dpy, CARD16 standby, CARD16 suspend, CARD16 off)
  127. {
  128. XExtDisplayInfo *info = find_display (dpy);
  129. register xDPMSSetTimeoutsReq *req;
  130. if ((off != 0)&&(off < suspend))
  131. {
  132. return BadValue;
  133. }
  134. if ((suspend != 0)&&(suspend < standby))
  135. {
  136. return BadValue;
  137. }
  138. DPMSCheckExtension (dpy, info, 0);
  139. LockDisplay(dpy);
  140. GetReq(DPMSSetTimeouts, req);
  141. req->reqType = info->codes->major_opcode;
  142. req->dpmsReqType = X_DPMSSetTimeouts;
  143. req->standby = standby;
  144. req->suspend = suspend;
  145. req->off = off;
  146. UnlockDisplay(dpy);
  147. SyncHandle();
  148. return 1;
  149. }
  150. Bool
  151. DPMSGetTimeouts(Display *dpy, CARD16 *standby, CARD16 *suspend, CARD16 *off)
  152. {
  153. XExtDisplayInfo *info = find_display (dpy);
  154. register xDPMSGetTimeoutsReq *req;
  155. xDPMSGetTimeoutsReply rep;
  156. DPMSCheckExtension (dpy, info, 0);
  157. LockDisplay(dpy);
  158. GetReq(DPMSGetTimeouts, req);
  159. req->reqType = info->codes->major_opcode;
  160. req->dpmsReqType = X_DPMSGetTimeouts;
  161. if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
  162. UnlockDisplay(dpy);
  163. SyncHandle();
  164. return False;
  165. }
  166. UnlockDisplay(dpy);
  167. SyncHandle();
  168. *standby = rep.standby;
  169. *suspend = rep.suspend;
  170. *off = rep.off;
  171. return 1;
  172. }
  173. Status
  174. DPMSEnable(Display *dpy)
  175. {
  176. XExtDisplayInfo *info = find_display (dpy);
  177. register xDPMSEnableReq *req;
  178. DPMSCheckExtension (dpy, info, 0);
  179. LockDisplay(dpy);
  180. GetReq(DPMSEnable, req);
  181. req->reqType = info->codes->major_opcode;
  182. req->dpmsReqType = X_DPMSEnable;
  183. UnlockDisplay(dpy);
  184. SyncHandle();
  185. return 1;
  186. }
  187. Status
  188. DPMSDisable(Display *dpy)
  189. {
  190. XExtDisplayInfo *info = find_display (dpy);
  191. register xDPMSDisableReq *req;
  192. DPMSCheckExtension (dpy, info, 0);
  193. LockDisplay(dpy);
  194. GetReq(DPMSDisable, req);
  195. req->reqType = info->codes->major_opcode;
  196. req->dpmsReqType = X_DPMSDisable;
  197. UnlockDisplay(dpy);
  198. SyncHandle();
  199. return 1;
  200. }
  201. Status
  202. DPMSForceLevel(Display *dpy, CARD16 level)
  203. {
  204. XExtDisplayInfo *info = find_display (dpy);
  205. register xDPMSForceLevelReq *req;
  206. DPMSCheckExtension (dpy, info, 0);
  207. if ((level != DPMSModeOn) &&
  208. (level != DPMSModeStandby) &&
  209. (level != DPMSModeSuspend) &&
  210. (level != DPMSModeOff))
  211. return BadValue;
  212. LockDisplay(dpy);
  213. GetReq(DPMSForceLevel, req);
  214. req->reqType = info->codes->major_opcode;
  215. req->dpmsReqType = X_DPMSForceLevel;
  216. req->level = level;
  217. UnlockDisplay(dpy);
  218. SyncHandle();
  219. return 1;
  220. }
  221. Status
  222. DPMSInfo(Display *dpy, CARD16 *power_level, BOOL *state)
  223. {
  224. XExtDisplayInfo *info = find_display (dpy);
  225. register xDPMSInfoReq *req;
  226. xDPMSInfoReply rep;
  227. DPMSCheckExtension (dpy, info, 0);
  228. LockDisplay(dpy);
  229. GetReq(DPMSInfo, req);
  230. req->reqType = info->codes->major_opcode;
  231. req->dpmsReqType = X_DPMSInfo;
  232. if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
  233. UnlockDisplay(dpy);
  234. SyncHandle();
  235. return False;
  236. }
  237. UnlockDisplay(dpy);
  238. SyncHandle();
  239. *power_level = rep.power_level;
  240. *state = rep.state;
  241. return 1;
  242. }