PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/libXext-1.3.1/src/DPMS.c

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