First import
[xorg_rtime.git] / xorg-server-1.4 / Xext / dpms.c
blobaced40639683c49b7ca75ae4ea8073a1d4d39f74
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 ******************************************************************/
30 * HISTORY
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>
38 #endif
40 #include <X11/X.h>
41 #include <X11/Xproto.h>
42 #include "misc.h"
43 #include "os.h"
44 #include "dixstruct.h"
45 #include "extnsionst.h"
46 #include "opaque.h"
47 #define DPMS_SERVER
48 #include <X11/extensions/dpms.h>
49 #include <X11/extensions/dpmsstr.h>
50 #include "dpmsproc.h"
51 #include "modinit.h"
53 #if 0
54 static unsigned char DPMSCode;
55 #endif
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);
76 void
77 DPMSExtensionInit(INITARGS)
79 #if 0
80 ExtensionEntry *extEntry;
82 if ((extEntry = AddExtension(DPMSExtensionName, 0, 0,
83 ProcDPMSDispatch, SProcDPMSDispatch,
84 DPMSResetProc, StandardMinorOpcode)))
85 DPMSCode = (unsigned char)extEntry->base;
86 #else
87 (void) AddExtension(DPMSExtensionName, 0, 0,
88 ProcDPMSDispatch, SProcDPMSDispatch,
89 DPMSResetProc, StandardMinorOpcode);
90 #endif
93 /*ARGSUSED*/
94 static void
95 DPMSResetProc (extEntry)
96 ExtensionEntry *extEntry;
100 static int
101 ProcDPMSGetVersion(client)
102 register ClientPtr client;
104 /* REQUEST(xDPMSGetVersionReq); */
105 xDPMSGetVersionReply rep;
106 register int n;
108 REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
110 rep.type = X_Reply;
111 rep.length = 0;
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);
124 static int
125 ProcDPMSCapable(register ClientPtr client)
127 /* REQUEST(xDPMSCapableReq); */
128 xDPMSCapableReply rep;
129 register int n;
131 REQUEST_SIZE_MATCH(xDPMSCapableReq);
133 rep.type = X_Reply;
134 rep.length = 0;
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);
145 static int
146 ProcDPMSGetTimeouts(client)
147 register ClientPtr client;
149 /* REQUEST(xDPMSGetTimeoutsReq); */
150 xDPMSGetTimeoutsReply rep;
151 register int n;
153 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
155 rep.type = X_Reply;
156 rep.length = 0;
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);
166 swaps(&rep.off, n);
168 WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), (char *)&rep);
169 return(client->noClientException);
172 static int
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;
183 return BadValue;
185 if ((stuff->suspend != 0)&&(stuff->suspend < stuff->standby))
187 client->errorValue = stuff->suspend;
188 return BadValue;
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);
199 static int
200 ProcDPMSEnable(client)
201 register ClientPtr client;
203 /* REQUEST(xDPMSEnableReq); */
205 REQUEST_SIZE_MATCH(xDPMSEnableReq);
207 if (DPMSCapableFlag)
208 DPMSEnabled = TRUE;
210 return(client->noClientException);
213 static int
214 ProcDPMSDisable(client)
215 register ClientPtr client;
217 /* REQUEST(xDPMSDisableReq); */
219 REQUEST_SIZE_MATCH(xDPMSDisableReq);
221 DPMSSet(DPMSModeOn);
223 DPMSEnabled = FALSE;
225 return(client->noClientException);
228 static int
229 ProcDPMSForceLevel(client)
230 register ClientPtr client;
232 REQUEST(xDPMSForceLevelReq);
234 REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
236 if (!DPMSEnabled)
237 return BadMatch;
239 if (stuff->level == DPMSModeOn) {
240 lastDeviceEventTime.milliseconds =
241 GetTimeInMillis();
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;
251 } else {
252 client->errorValue = stuff->level;
253 return BadValue;
256 DPMSSet(stuff->level);
258 return(client->noClientException);
261 static int
262 ProcDPMSInfo(register ClientPtr client)
264 /* REQUEST(xDPMSInfoReq); */
265 xDPMSInfoReply rep;
266 register int n;
268 REQUEST_SIZE_MATCH(xDPMSInfoReq);
270 rep.type = X_Reply;
271 rep.length = 0;
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);
284 static int
285 ProcDPMSDispatch (client)
286 register ClientPtr client;
288 REQUEST(xReq);
290 switch (stuff->data)
292 case X_DPMSGetVersion:
293 return ProcDPMSGetVersion(client);
294 case X_DPMSCapable:
295 return ProcDPMSCapable(client);
296 case X_DPMSGetTimeouts:
297 return ProcDPMSGetTimeouts(client);
298 case X_DPMSSetTimeouts:
299 return ProcDPMSSetTimeouts(client);
300 case X_DPMSEnable:
301 return ProcDPMSEnable(client);
302 case X_DPMSDisable:
303 return ProcDPMSDisable(client);
304 case X_DPMSForceLevel:
305 return ProcDPMSForceLevel(client);
306 case X_DPMSInfo:
307 return ProcDPMSInfo(client);
308 default:
309 return BadRequest;
313 static int
314 SProcDPMSGetVersion(client)
315 register ClientPtr client;
317 register int n;
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);
327 static int
328 SProcDPMSCapable(register ClientPtr client)
330 REQUEST(xDPMSCapableReq);
331 register int n;
333 swaps(&stuff->length, n);
334 REQUEST_SIZE_MATCH(xDPMSCapableReq);
336 return ProcDPMSCapable(client);
339 static int
340 SProcDPMSGetTimeouts(client)
341 register ClientPtr client;
343 REQUEST(xDPMSGetTimeoutsReq);
344 register int n;
346 swaps(&stuff->length, n);
347 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
349 return ProcDPMSGetTimeouts(client);
352 static int
353 SProcDPMSSetTimeouts(client)
354 register ClientPtr client;
356 REQUEST(xDPMSSetTimeoutsReq);
357 register int n;
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);
368 static int
369 SProcDPMSEnable(client)
370 register ClientPtr client;
372 REQUEST(xDPMSEnableReq);
373 register int n;
375 swaps(&stuff->length, n);
376 REQUEST_SIZE_MATCH(xDPMSEnableReq);
378 return ProcDPMSEnable(client);
381 static int
382 SProcDPMSDisable(client)
383 register ClientPtr client;
385 REQUEST(xDPMSDisableReq);
386 register int n;
388 swaps(&stuff->length, n);
389 REQUEST_SIZE_MATCH(xDPMSDisableReq);
391 return ProcDPMSDisable(client);
394 static int
395 SProcDPMSForceLevel(client)
396 register ClientPtr client;
398 REQUEST(xDPMSForceLevelReq);
399 register int n;
401 swaps(&stuff->length, n);
402 REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
404 swaps(&stuff->level, n);
406 return ProcDPMSForceLevel(client);
409 static int
410 SProcDPMSInfo(client)
411 register ClientPtr client;
413 REQUEST(xDPMSInfoReq);
414 register int n;
416 swaps(&stuff->length, n);
417 REQUEST_SIZE_MATCH(xDPMSInfoReq);
419 return ProcDPMSInfo(client);
422 static int
423 SProcDPMSDispatch (client)
424 register ClientPtr client;
426 REQUEST(xReq);
427 switch (stuff->data)
429 case X_DPMSGetVersion:
430 return SProcDPMSGetVersion(client);
431 case X_DPMSCapable:
432 return SProcDPMSCapable(client);
433 case X_DPMSGetTimeouts:
434 return SProcDPMSGetTimeouts(client);
435 case X_DPMSSetTimeouts:
436 return SProcDPMSSetTimeouts(client);
437 case X_DPMSEnable:
438 return SProcDPMSEnable(client);
439 case X_DPMSDisable:
440 return SProcDPMSDisable(client);
441 case X_DPMSForceLevel:
442 return SProcDPMSForceLevel(client);
443 case X_DPMSInfo:
444 return SProcDPMSInfo(client);
445 default:
446 return BadRequest;