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 ******************************************************************/
29 #ifdef HAVE_DIX_CONFIG_H
30 #include <dix-config.h>
31 #endif
33 #include <X11/X.h>
34 #include <X11/Xproto.h>
35 #include "misc.h"
36 #include "os.h"
37 #include "dixstruct.h"
38 #include "extnsionst.h"
39 #include "opaque.h"
40 #include <X11/extensions/dpmsproto.h>
41 #include "dpmsproc.h"
42 #include "modinit.h"
44 static int
45 ProcDPMSGetVersion(ClientPtr client)
46 {
47 /* REQUEST(xDPMSGetVersionReq); */
48 xDPMSGetVersionReply rep;
49 int n;
51 REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
53 rep.type = X_Reply;
54 rep.length = 0;
55 rep.sequenceNumber = client->sequence;
56 rep.majorVersion = DPMSMajorVersion;
57 rep.minorVersion = DPMSMinorVersion;
58 if (client->swapped) {
59 swaps(&rep.sequenceNumber, n);
60 swaps(&rep.majorVersion, n);
61 swaps(&rep.minorVersion, n);
62 }
63 WriteToClient(client, sizeof(xDPMSGetVersionReply), (char *)&rep);
64 return Success;
65 }
67 static int
68 ProcDPMSCapable(ClientPtr client)
69 {
70 /* REQUEST(xDPMSCapableReq); */
71 xDPMSCapableReply rep;
72 int n;
74 REQUEST_SIZE_MATCH(xDPMSCapableReq);
76 rep.type = X_Reply;
77 rep.length = 0;
78 rep.sequenceNumber = client->sequence;
79 rep.capable = DPMSCapableFlag;
81 if (client->swapped) {
82 swaps(&rep.sequenceNumber, n);
83 }
84 WriteToClient(client, sizeof(xDPMSCapableReply), (char *)&rep);
85 return Success;
86 }
88 static int
89 ProcDPMSGetTimeouts(ClientPtr client)
90 {
91 /* REQUEST(xDPMSGetTimeoutsReq); */
92 xDPMSGetTimeoutsReply rep;
93 int n;
95 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
97 rep.type = X_Reply;
98 rep.length = 0;
99 rep.sequenceNumber = client->sequence;
100 rep.standby = DPMSStandbyTime / MILLI_PER_SECOND;
101 rep.suspend = DPMSSuspendTime / MILLI_PER_SECOND;
102 rep.off = DPMSOffTime / MILLI_PER_SECOND;
104 if (client->swapped) {
105 swaps(&rep.sequenceNumber, n);
106 swaps(&rep.standby, n);
107 swaps(&rep.suspend, n);
108 swaps(&rep.off, n);
109 }
110 WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), (char *)&rep);
111 return Success;
112 }
114 static int
115 ProcDPMSSetTimeouts(ClientPtr client)
116 {
117 REQUEST(xDPMSSetTimeoutsReq);
119 REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
121 if ((stuff->off != 0)&&(stuff->off < stuff->suspend))
122 {
123 client->errorValue = stuff->off;
124 return BadValue;
125 }
126 if ((stuff->suspend != 0)&&(stuff->suspend < stuff->standby))
127 {
128 client->errorValue = stuff->suspend;
129 return BadValue;
130 }
132 DPMSStandbyTime = stuff->standby * MILLI_PER_SECOND;
133 DPMSSuspendTime = stuff->suspend * MILLI_PER_SECOND;
134 DPMSOffTime = stuff->off * MILLI_PER_SECOND;
135 SetScreenSaverTimer();
137 return Success;
138 }
140 static int
141 ProcDPMSEnable(ClientPtr client)
142 {
143 Bool was_enabled = DPMSEnabled;
145 REQUEST_SIZE_MATCH(xDPMSEnableReq);
147 if (DPMSCapableFlag) {
148 DPMSEnabled = TRUE;
149 if (!was_enabled)
150 SetScreenSaverTimer();
151 }
153 return Success;
154 }
156 static int
157 ProcDPMSDisable(ClientPtr client)
158 {
159 /* REQUEST(xDPMSDisableReq); */
161 REQUEST_SIZE_MATCH(xDPMSDisableReq);
163 DPMSSet(client, DPMSModeOn);
165 DPMSEnabled = FALSE;
167 return Success;
168 }
170 static int
171 ProcDPMSForceLevel(ClientPtr client)
172 {
173 REQUEST(xDPMSForceLevelReq);
175 REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
177 if (!DPMSEnabled)
178 return BadMatch;
180 if (stuff->level != DPMSModeOn &&
181 stuff->level != DPMSModeStandby &&
182 stuff->level != DPMSModeSuspend &&
183 stuff->level != DPMSModeOff) {
184 client->errorValue = stuff->level;
185 return BadValue;
186 }
188 DPMSSet(client, stuff->level);
190 return Success;
191 }
193 static int
194 ProcDPMSInfo(ClientPtr client)
195 {
196 /* REQUEST(xDPMSInfoReq); */
197 xDPMSInfoReply rep;
198 int n;
200 REQUEST_SIZE_MATCH(xDPMSInfoReq);
202 rep.type = X_Reply;
203 rep.length = 0;
204 rep.sequenceNumber = client->sequence;
205 rep.power_level = DPMSPowerLevel;
206 rep.state = DPMSEnabled;
208 if (client->swapped) {
209 swaps(&rep.sequenceNumber, n);
210 swaps(&rep.power_level, n);
211 }
212 WriteToClient(client, sizeof(xDPMSInfoReply), (char *)&rep);
213 return Success;
214 }
216 static int
217 ProcDPMSDispatch (ClientPtr client)
218 {
219 REQUEST(xReq);
221 switch (stuff->data)
222 {
223 case X_DPMSGetVersion:
224 return ProcDPMSGetVersion(client);
225 case X_DPMSCapable:
226 return ProcDPMSCapable(client);
227 case X_DPMSGetTimeouts:
228 return ProcDPMSGetTimeouts(client);
229 case X_DPMSSetTimeouts:
230 return ProcDPMSSetTimeouts(client);
231 case X_DPMSEnable:
232 return ProcDPMSEnable(client);
233 case X_DPMSDisable:
234 return ProcDPMSDisable(client);
235 case X_DPMSForceLevel:
236 return ProcDPMSForceLevel(client);
237 case X_DPMSInfo:
238 return ProcDPMSInfo(client);
239 default:
240 return BadRequest;
241 }
242 }
244 static int
245 SProcDPMSGetVersion(ClientPtr client)
246 {
247 int n;
248 REQUEST(xDPMSGetVersionReq);
250 swaps(&stuff->length, n);
251 REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
252 swaps(&stuff->majorVersion, n);
253 swaps(&stuff->minorVersion, n);
254 return ProcDPMSGetVersion(client);
255 }
257 static int
258 SProcDPMSCapable(ClientPtr client)
259 {
260 REQUEST(xDPMSCapableReq);
261 int n;
263 swaps(&stuff->length, n);
264 REQUEST_SIZE_MATCH(xDPMSCapableReq);
266 return ProcDPMSCapable(client);
267 }
269 static int
270 SProcDPMSGetTimeouts(ClientPtr client)
271 {
272 REQUEST(xDPMSGetTimeoutsReq);
273 int n;
275 swaps(&stuff->length, n);
276 REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
278 return ProcDPMSGetTimeouts(client);
279 }
281 static int
282 SProcDPMSSetTimeouts(ClientPtr client)
283 {
284 REQUEST(xDPMSSetTimeoutsReq);
285 int n;
287 swaps(&stuff->length, n);
288 REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
290 swaps(&stuff->standby, n);
291 swaps(&stuff->suspend, n);
292 swaps(&stuff->off, n);
293 return ProcDPMSSetTimeouts(client);
294 }
296 static int
297 SProcDPMSEnable(ClientPtr client)
298 {
299 REQUEST(xDPMSEnableReq);
300 int n;
302 swaps(&stuff->length, n);
303 REQUEST_SIZE_MATCH(xDPMSEnableReq);
305 return ProcDPMSEnable(client);
306 }
308 static int
309 SProcDPMSDisable(ClientPtr client)
310 {
311 REQUEST(xDPMSDisableReq);
312 int n;
314 swaps(&stuff->length, n);
315 REQUEST_SIZE_MATCH(xDPMSDisableReq);
317 return ProcDPMSDisable(client);
318 }
320 static int
321 SProcDPMSForceLevel(ClientPtr client)
322 {
323 REQUEST(xDPMSForceLevelReq);
324 int n;
326 swaps(&stuff->length, n);
327 REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
329 swaps(&stuff->level, n);
331 return ProcDPMSForceLevel(client);
332 }
334 static int
335 SProcDPMSInfo(ClientPtr client)
336 {
337 REQUEST(xDPMSInfoReq);
338 int n;
340 swaps(&stuff->length, n);
341 REQUEST_SIZE_MATCH(xDPMSInfoReq);
343 return ProcDPMSInfo(client);
344 }
346 static int
347 SProcDPMSDispatch (ClientPtr client)
348 {
349 REQUEST(xReq);
350 switch (stuff->data)
351 {
352 case X_DPMSGetVersion:
353 return SProcDPMSGetVersion(client);
354 case X_DPMSCapable:
355 return SProcDPMSCapable(client);
356 case X_DPMSGetTimeouts:
357 return SProcDPMSGetTimeouts(client);
358 case X_DPMSSetTimeouts:
359 return SProcDPMSSetTimeouts(client);
360 case X_DPMSEnable:
361 return SProcDPMSEnable(client);
362 case X_DPMSDisable:
363 return SProcDPMSDisable(client);
364 case X_DPMSForceLevel:
365 return SProcDPMSForceLevel(client);
366 case X_DPMSInfo:
367 return SProcDPMSInfo(client);
368 default:
369 return BadRequest;
370 }
371 }
373 void
374 DPMSExtensionInit(INITARGS)
375 {
376 AddExtension(DPMSExtensionName, 0, 0,
377 ProcDPMSDispatch, SProcDPMSDispatch,
378 NULL, StandardMinorOpcode);
379 }