PageRenderTime 62ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/Xext/dpms.c

https://gitlab.com/Manizuca/xserver
C | 363 lines | 269 code | 62 blank | 32 comment | 21 complexity | a5bf702d7294c3a83794c0a40ad2942d MD5 | raw file
  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. #ifdef HAVE_DIX_CONFIG_H
  23. #include <dix-config.h>
  24. #endif
  25. #include <X11/X.h>
  26. #include <X11/Xproto.h>
  27. #include "misc.h"
  28. #include "os.h"
  29. #include "dixstruct.h"
  30. #include "extnsionst.h"
  31. #include "opaque.h"
  32. #include <X11/extensions/dpmsproto.h>
  33. #include "dpmsproc.h"
  34. #include "extinit.h"
  35. static int
  36. ProcDPMSGetVersion(ClientPtr client)
  37. {
  38. /* REQUEST(xDPMSGetVersionReq); */
  39. xDPMSGetVersionReply rep = {
  40. .type = X_Reply,
  41. .sequenceNumber = client->sequence,
  42. .length = 0,
  43. .majorVersion = DPMSMajorVersion,
  44. .minorVersion = DPMSMinorVersion
  45. };
  46. REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
  47. if (client->swapped) {
  48. swaps(&rep.sequenceNumber);
  49. swaps(&rep.majorVersion);
  50. swaps(&rep.minorVersion);
  51. }
  52. WriteToClient(client, sizeof(xDPMSGetVersionReply), &rep);
  53. return Success;
  54. }
  55. static int
  56. ProcDPMSCapable(ClientPtr client)
  57. {
  58. /* REQUEST(xDPMSCapableReq); */
  59. xDPMSCapableReply rep = {
  60. .type = X_Reply,
  61. .sequenceNumber = client->sequence,
  62. .length = 0,
  63. .capable = DPMSCapableFlag
  64. };
  65. REQUEST_SIZE_MATCH(xDPMSCapableReq);
  66. if (client->swapped) {
  67. swaps(&rep.sequenceNumber);
  68. }
  69. WriteToClient(client, sizeof(xDPMSCapableReply), &rep);
  70. return Success;
  71. }
  72. static int
  73. ProcDPMSGetTimeouts(ClientPtr client)
  74. {
  75. /* REQUEST(xDPMSGetTimeoutsReq); */
  76. xDPMSGetTimeoutsReply rep = {
  77. .type = X_Reply,
  78. .sequenceNumber = client->sequence,
  79. .length = 0,
  80. .standby = DPMSStandbyTime / MILLI_PER_SECOND,
  81. .suspend = DPMSSuspendTime / MILLI_PER_SECOND,
  82. .off = DPMSOffTime / MILLI_PER_SECOND
  83. };
  84. REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
  85. if (client->swapped) {
  86. swaps(&rep.sequenceNumber);
  87. swaps(&rep.standby);
  88. swaps(&rep.suspend);
  89. swaps(&rep.off);
  90. }
  91. WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), &rep);
  92. return Success;
  93. }
  94. static int
  95. ProcDPMSSetTimeouts(ClientPtr client)
  96. {
  97. REQUEST(xDPMSSetTimeoutsReq);
  98. REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
  99. if ((stuff->off != 0) && (stuff->off < stuff->suspend)) {
  100. client->errorValue = stuff->off;
  101. return BadValue;
  102. }
  103. if ((stuff->suspend != 0) && (stuff->suspend < stuff->standby)) {
  104. client->errorValue = stuff->suspend;
  105. return BadValue;
  106. }
  107. DPMSStandbyTime = stuff->standby * MILLI_PER_SECOND;
  108. DPMSSuspendTime = stuff->suspend * MILLI_PER_SECOND;
  109. DPMSOffTime = stuff->off * MILLI_PER_SECOND;
  110. SetScreenSaverTimer();
  111. return Success;
  112. }
  113. static int
  114. ProcDPMSEnable(ClientPtr client)
  115. {
  116. Bool was_enabled = DPMSEnabled;
  117. REQUEST_SIZE_MATCH(xDPMSEnableReq);
  118. if (DPMSCapableFlag) {
  119. DPMSEnabled = TRUE;
  120. if (!was_enabled)
  121. SetScreenSaverTimer();
  122. }
  123. return Success;
  124. }
  125. static int
  126. ProcDPMSDisable(ClientPtr client)
  127. {
  128. /* REQUEST(xDPMSDisableReq); */
  129. REQUEST_SIZE_MATCH(xDPMSDisableReq);
  130. DPMSSet(client, DPMSModeOn);
  131. DPMSEnabled = FALSE;
  132. return Success;
  133. }
  134. static int
  135. ProcDPMSForceLevel(ClientPtr client)
  136. {
  137. REQUEST(xDPMSForceLevelReq);
  138. REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
  139. if (!DPMSEnabled)
  140. return BadMatch;
  141. if (stuff->level != DPMSModeOn &&
  142. stuff->level != DPMSModeStandby &&
  143. stuff->level != DPMSModeSuspend && stuff->level != DPMSModeOff) {
  144. client->errorValue = stuff->level;
  145. return BadValue;
  146. }
  147. DPMSSet(client, stuff->level);
  148. return Success;
  149. }
  150. static int
  151. ProcDPMSInfo(ClientPtr client)
  152. {
  153. /* REQUEST(xDPMSInfoReq); */
  154. xDPMSInfoReply rep = {
  155. .type = X_Reply,
  156. .sequenceNumber = client->sequence,
  157. .length = 0,
  158. .power_level = DPMSPowerLevel,
  159. .state = DPMSEnabled
  160. };
  161. REQUEST_SIZE_MATCH(xDPMSInfoReq);
  162. if (client->swapped) {
  163. swaps(&rep.sequenceNumber);
  164. swaps(&rep.power_level);
  165. }
  166. WriteToClient(client, sizeof(xDPMSInfoReply), &rep);
  167. return Success;
  168. }
  169. static int
  170. ProcDPMSDispatch(ClientPtr client)
  171. {
  172. REQUEST(xReq);
  173. switch (stuff->data) {
  174. case X_DPMSGetVersion:
  175. return ProcDPMSGetVersion(client);
  176. case X_DPMSCapable:
  177. return ProcDPMSCapable(client);
  178. case X_DPMSGetTimeouts:
  179. return ProcDPMSGetTimeouts(client);
  180. case X_DPMSSetTimeouts:
  181. return ProcDPMSSetTimeouts(client);
  182. case X_DPMSEnable:
  183. return ProcDPMSEnable(client);
  184. case X_DPMSDisable:
  185. return ProcDPMSDisable(client);
  186. case X_DPMSForceLevel:
  187. return ProcDPMSForceLevel(client);
  188. case X_DPMSInfo:
  189. return ProcDPMSInfo(client);
  190. default:
  191. return BadRequest;
  192. }
  193. }
  194. static int
  195. SProcDPMSGetVersion(ClientPtr client)
  196. {
  197. REQUEST(xDPMSGetVersionReq);
  198. swaps(&stuff->length);
  199. REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
  200. swaps(&stuff->majorVersion);
  201. swaps(&stuff->minorVersion);
  202. return ProcDPMSGetVersion(client);
  203. }
  204. static int
  205. SProcDPMSCapable(ClientPtr client)
  206. {
  207. REQUEST(xDPMSCapableReq);
  208. swaps(&stuff->length);
  209. REQUEST_SIZE_MATCH(xDPMSCapableReq);
  210. return ProcDPMSCapable(client);
  211. }
  212. static int
  213. SProcDPMSGetTimeouts(ClientPtr client)
  214. {
  215. REQUEST(xDPMSGetTimeoutsReq);
  216. swaps(&stuff->length);
  217. REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
  218. return ProcDPMSGetTimeouts(client);
  219. }
  220. static int
  221. SProcDPMSSetTimeouts(ClientPtr client)
  222. {
  223. REQUEST(xDPMSSetTimeoutsReq);
  224. swaps(&stuff->length);
  225. REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
  226. swaps(&stuff->standby);
  227. swaps(&stuff->suspend);
  228. swaps(&stuff->off);
  229. return ProcDPMSSetTimeouts(client);
  230. }
  231. static int
  232. SProcDPMSEnable(ClientPtr client)
  233. {
  234. REQUEST(xDPMSEnableReq);
  235. swaps(&stuff->length);
  236. REQUEST_SIZE_MATCH(xDPMSEnableReq);
  237. return ProcDPMSEnable(client);
  238. }
  239. static int
  240. SProcDPMSDisable(ClientPtr client)
  241. {
  242. REQUEST(xDPMSDisableReq);
  243. swaps(&stuff->length);
  244. REQUEST_SIZE_MATCH(xDPMSDisableReq);
  245. return ProcDPMSDisable(client);
  246. }
  247. static int
  248. SProcDPMSForceLevel(ClientPtr client)
  249. {
  250. REQUEST(xDPMSForceLevelReq);
  251. swaps(&stuff->length);
  252. REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
  253. swaps(&stuff->level);
  254. return ProcDPMSForceLevel(client);
  255. }
  256. static int
  257. SProcDPMSInfo(ClientPtr client)
  258. {
  259. REQUEST(xDPMSInfoReq);
  260. swaps(&stuff->length);
  261. REQUEST_SIZE_MATCH(xDPMSInfoReq);
  262. return ProcDPMSInfo(client);
  263. }
  264. static int
  265. SProcDPMSDispatch(ClientPtr client)
  266. {
  267. REQUEST(xReq);
  268. switch (stuff->data) {
  269. case X_DPMSGetVersion:
  270. return SProcDPMSGetVersion(client);
  271. case X_DPMSCapable:
  272. return SProcDPMSCapable(client);
  273. case X_DPMSGetTimeouts:
  274. return SProcDPMSGetTimeouts(client);
  275. case X_DPMSSetTimeouts:
  276. return SProcDPMSSetTimeouts(client);
  277. case X_DPMSEnable:
  278. return SProcDPMSEnable(client);
  279. case X_DPMSDisable:
  280. return SProcDPMSDisable(client);
  281. case X_DPMSForceLevel:
  282. return SProcDPMSForceLevel(client);
  283. case X_DPMSInfo:
  284. return SProcDPMSInfo(client);
  285. default:
  286. return BadRequest;
  287. }
  288. }
  289. void
  290. DPMSExtensionInit(void)
  291. {
  292. AddExtension(DPMSExtensionName, 0, 0,
  293. ProcDPMSDispatch, SProcDPMSDispatch,
  294. NULL, StandardMinorOpcode);
  295. }