1 /*****************************************************************
3 Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts.
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
18 BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
19 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
20 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of Digital Equipment Corporation
23 shall not be used in advertising or otherwise to promote the sale, use or other
24 dealings in this Software without prior written authorization from Digital
25 Equipment Corporation.
27 ******************************************************************/
32 * @(#)RCSfile: dpms.c,v Revision: 1.1.4.5 (DEC) Date: 1996/03/04 15:27:00
35 /* $XFree86: xc/programs/Xserver/Xext/dpms.c,v 3.1 1997/01/12 10:40:06 dawes Exp $ */
41 #include "dixstruct.h"
42 #include "extnsionst.h"
48 static unsigned char DPMSCode;
49 static int ProcDPMSDispatch(), SProcDPMSDispatch();
50 static void DPMSResetProc();
51 static int ProcDPMSGetVersion(), SProcDPMSGetVersion();
52 static int ProcDPMSGetTimeouts(), SProcDPMSGetTimeouts();
53 static int ProcDPMSSetTimeouts(), ProcDPMSSetTimeouts();
54 static int ProcDPMSEnable(), ProcDPMSEnable();
55 static int ProcDPMSDisable(), ProcDPMSDisable();
56 static int ProcDPMSForceLevel(), ProcDPMSForceLevel();
61 ExtensionEntry *extEntry, *AddExtension();
63 if (extEntry = AddExtension(DPMSExtensionName, 0, 0,
64 ProcDPMSDispatch, SProcDPMSDispatch,
65 DPMSResetProc, StandardMinorOpcode))
66 DPMSCode = (unsigned char)extEntry->base;
72 DPMSResetProc (extEntry)
73 ExtensionEntry *extEntry;
78 ProcDPMSGetVersion(client)
79 register ClientPtr client;
81 REQUEST(xDPMSGetVersionReq);
82 xDPMSGetVersionReply rep;
85 REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
89 rep.sequenceNumber = client->sequence;
90 rep.majorVersion = DPMSMajorVersion;
91 rep.minorVersion = DPMSMinorVersion;
92 if (client->swapped) {
93 swaps(&rep.sequenceNumber, n);
94 swaps(&rep.majorVersion, n);
95 swaps(&rep.minorVersion, n);
97 WriteToClient(client, sizeof(xDPMSGetVersionReply), (char *)&rep);
98 return(client->noClientException);
102 ProcDPMSCapable(client)
103 register ClientPtr client;
105 REQUEST(xDPMSCapableReq);
106 xDPMSCapableReply rep;
109 REQUEST_SIZE_MATCH(xDPMSCapableReq);
113 rep.sequenceNumber = client->sequence;
114 rep.capable = DPMSCapableFlag;
116 WriteToClient(client, sizeof(xDPMSCapableReply), (char *)&rep);
117 return(client->noClientException);
121 ProcDPMSGetTimeouts(client)
122 register ClientPtr client;
124 REQUEST(xDPMSGetTimeoutsReq);
125 xDPMSGetTimeoutsReply rep;
128 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
132 rep.sequenceNumber = client->sequence;
133 rep.standby = DPMSStandbyTime / MILLI_PER_SECOND;
134 rep.suspend = DPMSSuspendTime / MILLI_PER_SECOND;
135 rep.off = DPMSOffTime / MILLI_PER_SECOND;
137 if (client->swapped) {
138 swaps(&rep.sequenceNumber, n);
139 swaps(&rep.standby, n);
140 swaps(&rep.suspend, n);
143 WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), (char *)&rep);
144 return(client->noClientException);
148 ProcDPMSSetTimeouts(client)
149 register ClientPtr client;
151 REQUEST(xDPMSSetTimeoutsReq);
154 REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
156 if ((stuff->off != 0)&&(stuff->off < stuff->suspend))
158 client->errorValue = stuff->off;
161 if ((stuff->suspend != 0)&&(stuff->suspend < stuff->standby))
163 client->errorValue = stuff->suspend;
167 DPMSStandbyTime = stuff->standby * MILLI_PER_SECOND;
168 DPMSSuspendTime = stuff->suspend * MILLI_PER_SECOND;
169 DPMSOffTime = stuff->off * MILLI_PER_SECOND;
171 return(client->noClientException);
175 ProcDPMSEnable(client)
176 register ClientPtr client;
178 REQUEST(xDPMSEnableReq);
180 REQUEST_SIZE_MATCH(xDPMSEnableReq);
185 return(client->noClientException);
189 ProcDPMSDisable(client)
190 register ClientPtr client;
192 REQUEST(xDPMSDisableReq);
194 REQUEST_SIZE_MATCH(xDPMSDisableReq);
200 return(client->noClientException);
204 ProcDPMSForceLevel(client)
205 register ClientPtr client;
207 REQUEST(xDPMSForceLevelReq);
209 REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
214 if (stuff->level == DPMSModeOn) {
215 lastDeviceEventTime.milliseconds =
217 } else if (stuff->level == DPMSModeStandby) {
218 lastDeviceEventTime.milliseconds =
219 GetTimeInMillis() - DPMSStandbyTime;
220 } else if (stuff->level == DPMSModeSuspend) {
221 lastDeviceEventTime.milliseconds =
222 GetTimeInMillis() - DPMSSuspendTime;
223 } else if (stuff->level == DPMSModeOff) {
224 lastDeviceEventTime.milliseconds =
225 GetTimeInMillis() - DPMSOffTime;
227 client->errorValue = stuff->level;
231 DPMSSet(stuff->level);
233 return(client->noClientException);
238 register ClientPtr client;
240 REQUEST(xDPMSInfoReq);
244 REQUEST_SIZE_MATCH(xDPMSInfoReq);
248 rep.sequenceNumber = client->sequence;
249 rep.power_level = DPMSPowerLevel;
250 rep.state = DPMSEnabled;
252 if (client->swapped) {
253 swaps(&rep.sequenceNumber, n);
254 swaps(&rep.power_level, n);
256 WriteToClient(client, sizeof(xDPMSInfoReply), (char *)&rep);
257 return(client->noClientException);
261 ProcDPMSDispatch (client)
262 register ClientPtr client;
268 case X_DPMSGetVersion:
269 return ProcDPMSGetVersion(client);
271 return ProcDPMSCapable(client);
272 case X_DPMSGetTimeouts:
273 return ProcDPMSGetTimeouts(client);
274 case X_DPMSSetTimeouts:
275 return ProcDPMSSetTimeouts(client);
277 return ProcDPMSEnable(client);
279 return ProcDPMSDisable(client);
280 case X_DPMSForceLevel:
281 return ProcDPMSForceLevel(client);
283 return ProcDPMSInfo(client);
290 SProcDPMSGetVersion(client)
291 register ClientPtr client;
294 REQUEST(xDPMSGetVersionReq);
296 swaps(&stuff->length, n);
297 REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
298 swaps(&stuff->majorVersion, n);
299 swaps(&stuff->minorVersion, n);
300 return ProcDPMSGetVersion(client);
304 SProcDPMSCapable(client)
305 register ClientPtr client;
307 REQUEST(xDPMSCapableReq);
310 swaps(&stuff->length, n);
311 REQUEST_SIZE_MATCH(xDPMSCapableReq);
313 return ProcDPMSCapable(client);
317 SProcDPMSGetTimeouts(client)
318 register ClientPtr client;
320 REQUEST(xDPMSGetTimeoutsReq);
323 swaps(&stuff->length, n);
324 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
326 return ProcDPMSGetTimeouts(client);
330 SProcDPMSSetTimeouts(client)
331 register ClientPtr client;
333 REQUEST(xDPMSSetTimeoutsReq);
336 swaps(&stuff->length, n);
337 REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
339 swaps(&stuff->standby, n);
340 swaps(&stuff->suspend, n);
341 swaps(&stuff->off, n);
342 return ProcDPMSSetTimeouts(client);
346 SProcDPMSEnable(client)
347 register ClientPtr client;
349 REQUEST(xDPMSEnableReq);
352 swaps(&stuff->length, n);
353 REQUEST_SIZE_MATCH(xDPMSEnableReq);
355 return ProcDPMSEnable(client);
359 SProcDPMSDisable(client)
360 register ClientPtr client;
362 REQUEST(xDPMSDisableReq);
365 swaps(&stuff->length, n);
366 REQUEST_SIZE_MATCH(xDPMSDisableReq);
368 return ProcDPMSDisable(client);
372 SProcDPMSForceLevel(client)
373 register ClientPtr client;
375 REQUEST(xDPMSForceLevelReq);
378 swaps(&stuff->length, n);
379 REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
381 swaps(&stuff->level, n);
383 return ProcDPMSForceLevel(client);
387 SProcDPMSInfo(client)
388 register ClientPtr client;
390 REQUEST(xDPMSInfoReq);
393 swaps(&stuff->length, n);
394 REQUEST_SIZE_MATCH(xDPMSInfoReq);
396 return ProcDPMSInfo(client);
400 SProcDPMSDispatch (client)
401 register ClientPtr client;
406 case X_DPMSGetVersion:
407 return SProcDPMSGetVersion(client);
409 return SProcDPMSCapable(client);
410 case X_DPMSGetTimeouts:
411 return SProcDPMSGetTimeouts(client);
412 case X_DPMSSetTimeouts:
413 return SProcDPMSSetTimeouts(client);
415 return SProcDPMSEnable(client);
417 return SProcDPMSDisable(client);
418 case X_DPMSForceLevel:
419 return SProcDPMSForceLevel(client);
421 return SProcDPMSInfo(client);