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
36 #ifdef HAVE_DIX_CONFIG_H
37 #include <dix-config.h>
41 #include <X11/Xproto.h>
44 #include "dixstruct.h"
45 #include "extnsionst.h"
48 #include <X11/extensions/dpms.h>
49 #include <X11/extensions/dpmsstr.h>
54 static unsigned char DPMSCode
;
56 static DISPATCH_PROC(ProcDPMSDispatch
);
57 static DISPATCH_PROC(SProcDPMSDispatch
);
58 static DISPATCH_PROC(ProcDPMSGetVersion
);
59 static DISPATCH_PROC(SProcDPMSGetVersion
);
60 static DISPATCH_PROC(ProcDPMSGetTimeouts
);
61 static DISPATCH_PROC(SProcDPMSGetTimeouts
);
62 static DISPATCH_PROC(ProcDPMSSetTimeouts
);
63 static DISPATCH_PROC(SProcDPMSSetTimeouts
);
64 static DISPATCH_PROC(ProcDPMSEnable
);
65 static DISPATCH_PROC(SProcDPMSEnable
);
66 static DISPATCH_PROC(ProcDPMSDisable
);
67 static DISPATCH_PROC(SProcDPMSDisable
);
68 static DISPATCH_PROC(ProcDPMSForceLevel
);
69 static DISPATCH_PROC(SProcDPMSForceLevel
);
70 static DISPATCH_PROC(ProcDPMSInfo
);
71 static DISPATCH_PROC(SProcDPMSInfo
);
72 static DISPATCH_PROC(ProcDPMSCapable
);
73 static DISPATCH_PROC(SProcDPMSCapable
);
74 static void DPMSResetProc(ExtensionEntry
* extEntry
);
77 DPMSExtensionInit(INITARGS
)
80 ExtensionEntry
*extEntry
;
82 if ((extEntry
= AddExtension(DPMSExtensionName
, 0, 0,
83 ProcDPMSDispatch
, SProcDPMSDispatch
,
84 DPMSResetProc
, StandardMinorOpcode
)))
85 DPMSCode
= (unsigned char)extEntry
->base
;
87 (void) AddExtension(DPMSExtensionName
, 0, 0,
88 ProcDPMSDispatch
, SProcDPMSDispatch
,
89 DPMSResetProc
, StandardMinorOpcode
);
95 DPMSResetProc (extEntry
)
96 ExtensionEntry
*extEntry
;
101 ProcDPMSGetVersion(client
)
102 register ClientPtr client
;
104 /* REQUEST(xDPMSGetVersionReq); */
105 xDPMSGetVersionReply rep
;
108 REQUEST_SIZE_MATCH(xDPMSGetVersionReq
);
112 rep
.sequenceNumber
= client
->sequence
;
113 rep
.majorVersion
= DPMSMajorVersion
;
114 rep
.minorVersion
= DPMSMinorVersion
;
115 if (client
->swapped
) {
116 swaps(&rep
.sequenceNumber
, n
);
117 swaps(&rep
.majorVersion
, n
);
118 swaps(&rep
.minorVersion
, n
);
120 WriteToClient(client
, sizeof(xDPMSGetVersionReply
), (char *)&rep
);
121 return(client
->noClientException
);
125 ProcDPMSCapable(register ClientPtr client
)
127 /* REQUEST(xDPMSCapableReq); */
128 xDPMSCapableReply rep
;
131 REQUEST_SIZE_MATCH(xDPMSCapableReq
);
135 rep
.sequenceNumber
= client
->sequence
;
136 rep
.capable
= DPMSCapableFlag
;
138 if (client
->swapped
) {
139 swaps(&rep
.sequenceNumber
, n
);
141 WriteToClient(client
, sizeof(xDPMSCapableReply
), (char *)&rep
);
142 return(client
->noClientException
);
146 ProcDPMSGetTimeouts(client
)
147 register ClientPtr client
;
149 /* REQUEST(xDPMSGetTimeoutsReq); */
150 xDPMSGetTimeoutsReply rep
;
153 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq
);
157 rep
.sequenceNumber
= client
->sequence
;
158 rep
.standby
= DPMSStandbyTime
/ MILLI_PER_SECOND
;
159 rep
.suspend
= DPMSSuspendTime
/ MILLI_PER_SECOND
;
160 rep
.off
= DPMSOffTime
/ MILLI_PER_SECOND
;
162 if (client
->swapped
) {
163 swaps(&rep
.sequenceNumber
, n
);
164 swaps(&rep
.standby
, n
);
165 swaps(&rep
.suspend
, n
);
168 WriteToClient(client
, sizeof(xDPMSGetTimeoutsReply
), (char *)&rep
);
169 return(client
->noClientException
);
173 ProcDPMSSetTimeouts(client
)
174 register ClientPtr client
;
176 REQUEST(xDPMSSetTimeoutsReq
);
178 REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq
);
180 if ((stuff
->off
!= 0)&&(stuff
->off
< stuff
->suspend
))
182 client
->errorValue
= stuff
->off
;
185 if ((stuff
->suspend
!= 0)&&(stuff
->suspend
< stuff
->standby
))
187 client
->errorValue
= stuff
->suspend
;
191 DPMSStandbyTime
= stuff
->standby
* MILLI_PER_SECOND
;
192 DPMSSuspendTime
= stuff
->suspend
* MILLI_PER_SECOND
;
193 DPMSOffTime
= stuff
->off
* MILLI_PER_SECOND
;
194 SetScreenSaverTimer();
196 return(client
->noClientException
);
200 ProcDPMSEnable(client
)
201 register ClientPtr client
;
203 /* REQUEST(xDPMSEnableReq); */
205 REQUEST_SIZE_MATCH(xDPMSEnableReq
);
210 return(client
->noClientException
);
214 ProcDPMSDisable(client
)
215 register ClientPtr client
;
217 /* REQUEST(xDPMSDisableReq); */
219 REQUEST_SIZE_MATCH(xDPMSDisableReq
);
225 return(client
->noClientException
);
229 ProcDPMSForceLevel(client
)
230 register ClientPtr client
;
232 REQUEST(xDPMSForceLevelReq
);
234 REQUEST_SIZE_MATCH(xDPMSForceLevelReq
);
239 if (stuff
->level
== DPMSModeOn
) {
240 lastDeviceEventTime
.milliseconds
=
242 } else if (stuff
->level
== DPMSModeStandby
) {
243 lastDeviceEventTime
.milliseconds
=
244 GetTimeInMillis() - DPMSStandbyTime
;
245 } else if (stuff
->level
== DPMSModeSuspend
) {
246 lastDeviceEventTime
.milliseconds
=
247 GetTimeInMillis() - DPMSSuspendTime
;
248 } else if (stuff
->level
== DPMSModeOff
) {
249 lastDeviceEventTime
.milliseconds
=
250 GetTimeInMillis() - DPMSOffTime
;
252 client
->errorValue
= stuff
->level
;
256 DPMSSet(stuff
->level
);
258 return(client
->noClientException
);
262 ProcDPMSInfo(register ClientPtr client
)
264 /* REQUEST(xDPMSInfoReq); */
268 REQUEST_SIZE_MATCH(xDPMSInfoReq
);
272 rep
.sequenceNumber
= client
->sequence
;
273 rep
.power_level
= DPMSPowerLevel
;
274 rep
.state
= DPMSEnabled
;
276 if (client
->swapped
) {
277 swaps(&rep
.sequenceNumber
, n
);
278 swaps(&rep
.power_level
, n
);
280 WriteToClient(client
, sizeof(xDPMSInfoReply
), (char *)&rep
);
281 return(client
->noClientException
);
285 ProcDPMSDispatch (client
)
286 register ClientPtr client
;
292 case X_DPMSGetVersion
:
293 return ProcDPMSGetVersion(client
);
295 return ProcDPMSCapable(client
);
296 case X_DPMSGetTimeouts
:
297 return ProcDPMSGetTimeouts(client
);
298 case X_DPMSSetTimeouts
:
299 return ProcDPMSSetTimeouts(client
);
301 return ProcDPMSEnable(client
);
303 return ProcDPMSDisable(client
);
304 case X_DPMSForceLevel
:
305 return ProcDPMSForceLevel(client
);
307 return ProcDPMSInfo(client
);
314 SProcDPMSGetVersion(client
)
315 register ClientPtr client
;
318 REQUEST(xDPMSGetVersionReq
);
320 swaps(&stuff
->length
, n
);
321 REQUEST_SIZE_MATCH(xDPMSGetVersionReq
);
322 swaps(&stuff
->majorVersion
, n
);
323 swaps(&stuff
->minorVersion
, n
);
324 return ProcDPMSGetVersion(client
);
328 SProcDPMSCapable(register ClientPtr client
)
330 REQUEST(xDPMSCapableReq
);
333 swaps(&stuff
->length
, n
);
334 REQUEST_SIZE_MATCH(xDPMSCapableReq
);
336 return ProcDPMSCapable(client
);
340 SProcDPMSGetTimeouts(client
)
341 register ClientPtr client
;
343 REQUEST(xDPMSGetTimeoutsReq
);
346 swaps(&stuff
->length
, n
);
347 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq
);
349 return ProcDPMSGetTimeouts(client
);
353 SProcDPMSSetTimeouts(client
)
354 register ClientPtr client
;
356 REQUEST(xDPMSSetTimeoutsReq
);
359 swaps(&stuff
->length
, n
);
360 REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq
);
362 swaps(&stuff
->standby
, n
);
363 swaps(&stuff
->suspend
, n
);
364 swaps(&stuff
->off
, n
);
365 return ProcDPMSSetTimeouts(client
);
369 SProcDPMSEnable(client
)
370 register ClientPtr client
;
372 REQUEST(xDPMSEnableReq
);
375 swaps(&stuff
->length
, n
);
376 REQUEST_SIZE_MATCH(xDPMSEnableReq
);
378 return ProcDPMSEnable(client
);
382 SProcDPMSDisable(client
)
383 register ClientPtr client
;
385 REQUEST(xDPMSDisableReq
);
388 swaps(&stuff
->length
, n
);
389 REQUEST_SIZE_MATCH(xDPMSDisableReq
);
391 return ProcDPMSDisable(client
);
395 SProcDPMSForceLevel(client
)
396 register ClientPtr client
;
398 REQUEST(xDPMSForceLevelReq
);
401 swaps(&stuff
->length
, n
);
402 REQUEST_SIZE_MATCH(xDPMSForceLevelReq
);
404 swaps(&stuff
->level
, n
);
406 return ProcDPMSForceLevel(client
);
410 SProcDPMSInfo(client
)
411 register ClientPtr client
;
413 REQUEST(xDPMSInfoReq
);
416 swaps(&stuff
->length
, n
);
417 REQUEST_SIZE_MATCH(xDPMSInfoReq
);
419 return ProcDPMSInfo(client
);
423 SProcDPMSDispatch (client
)
424 register ClientPtr client
;
429 case X_DPMSGetVersion
:
430 return SProcDPMSGetVersion(client
);
432 return SProcDPMSCapable(client
);
433 case X_DPMSGetTimeouts
:
434 return SProcDPMSGetTimeouts(client
);
435 case X_DPMSSetTimeouts
:
436 return SProcDPMSSetTimeouts(client
);
438 return SProcDPMSEnable(client
);
440 return SProcDPMSDisable(client
);
441 case X_DPMSForceLevel
:
442 return SProcDPMSForceLevel(client
);
444 return SProcDPMSInfo(client
);