]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/Xext/dpms.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / Xext / dpms.c
1 /*****************************************************************
2
3 Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts.
4
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.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
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.
21
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.
26
27 ******************************************************************/
28
29 /*
30  * HISTORY
31  *
32  * @(#)RCSfile: dpms.c,v Revision: 1.1.4.5  (DEC) Date: 1996/03/04 15:27:00
33  */
34
35 /* $XFree86: xc/programs/Xserver/Xext/dpms.c,v 3.1 1997/01/12 10:40:06 dawes Exp $ */
36
37 #include "X.h"
38 #include "Xproto.h"
39 #include "misc.h"
40 #include "os.h"
41 #include "dixstruct.h"
42 #include "extnsionst.h"
43 #include "opaque.h"
44 #include "dpms.h"
45 #include "dpmsstr.h"
46 #include <stdio.h>
47
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();
57
58 void
59 DPMSExtensionInit()
60 {
61     ExtensionEntry *extEntry, *AddExtension();
62     
63     if (extEntry = AddExtension(DPMSExtensionName, 0, 0,
64                                 ProcDPMSDispatch, SProcDPMSDispatch,
65                                 DPMSResetProc, StandardMinorOpcode))
66         DPMSCode = (unsigned char)extEntry->base;
67     return;
68 }
69
70 /*ARGSUSED*/
71 static void
72 DPMSResetProc (extEntry)
73     ExtensionEntry      *extEntry;
74 {
75 }
76
77 static int
78 ProcDPMSGetVersion(client)
79     register ClientPtr client;
80 {
81     REQUEST(xDPMSGetVersionReq);
82     xDPMSGetVersionReply rep;
83     register int n;
84
85     REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
86
87     rep.type = X_Reply;
88     rep.length = 0;
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);
96     }
97     WriteToClient(client, sizeof(xDPMSGetVersionReply), (char *)&rep);
98     return(client->noClientException);
99 }
100
101 static int
102 ProcDPMSCapable(client)
103     register ClientPtr client;
104 {
105     REQUEST(xDPMSCapableReq);
106     xDPMSCapableReply rep;
107     register int n;
108
109     REQUEST_SIZE_MATCH(xDPMSCapableReq);
110
111     rep.type = X_Reply;
112     rep.length = 0;
113     rep.sequenceNumber = client->sequence;
114     rep.capable = DPMSCapableFlag;
115
116     WriteToClient(client, sizeof(xDPMSCapableReply), (char *)&rep);
117     return(client->noClientException);
118 }
119
120 static int
121 ProcDPMSGetTimeouts(client)
122     register ClientPtr client;
123 {
124     REQUEST(xDPMSGetTimeoutsReq);
125     xDPMSGetTimeoutsReply rep;
126     register int n;
127
128     REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
129
130     rep.type = X_Reply;
131     rep.length = 0;
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;
136
137     if (client->swapped) {
138         swaps(&rep.sequenceNumber, n);
139         swaps(&rep.standby, n);
140         swaps(&rep.suspend, n);
141         swaps(&rep.off, n);
142     }
143     WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), (char *)&rep);
144     return(client->noClientException);
145 }
146
147 static int
148 ProcDPMSSetTimeouts(client)
149     register ClientPtr client;
150 {
151     REQUEST(xDPMSSetTimeoutsReq);
152     register int n;
153
154     REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
155
156     if ((stuff->off != 0)&&(stuff->off < stuff->suspend)) 
157     {
158         client->errorValue = stuff->off;
159         return BadValue;
160     }
161     if ((stuff->suspend != 0)&&(stuff->suspend < stuff->standby))
162     {
163         client->errorValue = stuff->suspend;
164         return BadValue;
165     }  
166         
167     DPMSStandbyTime = stuff->standby * MILLI_PER_SECOND;
168     DPMSSuspendTime = stuff->suspend * MILLI_PER_SECOND;
169     DPMSOffTime = stuff->off * MILLI_PER_SECOND;
170
171     return(client->noClientException);
172 }
173
174 static int
175 ProcDPMSEnable(client)
176     register ClientPtr client;
177 {
178     REQUEST(xDPMSEnableReq);
179
180     REQUEST_SIZE_MATCH(xDPMSEnableReq);
181
182     if (DPMSCapableFlag)
183         DPMSEnabled = TRUE;
184
185     return(client->noClientException);
186 }
187
188 static int
189 ProcDPMSDisable(client)
190     register ClientPtr client;
191 {
192     REQUEST(xDPMSDisableReq);
193
194     REQUEST_SIZE_MATCH(xDPMSDisableReq);
195
196     DPMSSet(DPMSModeOn);
197
198     DPMSEnabled = FALSE;
199
200     return(client->noClientException);
201 }
202
203 static int
204 ProcDPMSForceLevel(client)
205     register ClientPtr client;
206 {
207     REQUEST(xDPMSForceLevelReq);
208
209     REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
210
211     if (!DPMSEnabled)
212         return BadMatch;
213
214     if (stuff->level == DPMSModeOn) {
215       lastDeviceEventTime.milliseconds =
216           GetTimeInMillis();
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;
226     } else {
227         client->errorValue = stuff->level;
228         return BadValue;
229     }
230
231     DPMSSet(stuff->level);
232
233     return(client->noClientException);
234 }
235
236 static int
237 ProcDPMSInfo(client)
238     register ClientPtr client;
239 {
240     REQUEST(xDPMSInfoReq);
241     xDPMSInfoReply rep;
242     register int n;
243
244     REQUEST_SIZE_MATCH(xDPMSInfoReq);
245
246     rep.type = X_Reply;
247     rep.length = 0;
248     rep.sequenceNumber = client->sequence;
249     rep.power_level = DPMSPowerLevel;
250     rep.state = DPMSEnabled;
251
252     if (client->swapped) {
253         swaps(&rep.sequenceNumber, n);
254         swaps(&rep.power_level, n);
255     }
256     WriteToClient(client, sizeof(xDPMSInfoReply), (char *)&rep);
257     return(client->noClientException);
258 }
259
260 static int
261 ProcDPMSDispatch (client)
262     register ClientPtr  client;
263 {
264     REQUEST(xReq);
265
266     switch (stuff->data)
267     {
268     case X_DPMSGetVersion:
269         return ProcDPMSGetVersion(client);
270     case X_DPMSCapable:
271         return ProcDPMSCapable(client);
272     case X_DPMSGetTimeouts:
273         return ProcDPMSGetTimeouts(client);
274     case X_DPMSSetTimeouts:
275         return ProcDPMSSetTimeouts(client);
276     case X_DPMSEnable:
277         return ProcDPMSEnable(client);
278     case X_DPMSDisable:
279         return ProcDPMSDisable(client);
280     case X_DPMSForceLevel:
281         return ProcDPMSForceLevel(client);
282     case X_DPMSInfo:
283         return ProcDPMSInfo(client);
284     default:
285         return BadRequest;
286     }
287 }
288
289 static int
290 SProcDPMSGetVersion(client)
291     register ClientPtr  client;
292 {
293     register int n;
294     REQUEST(xDPMSGetVersionReq);
295
296     swaps(&stuff->length, n);
297     REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
298     swaps(&stuff->majorVersion, n);
299     swaps(&stuff->minorVersion, n);
300     return ProcDPMSGetVersion(client);
301 }
302
303 static int
304 SProcDPMSCapable(client)
305     register ClientPtr client;
306 {
307     REQUEST(xDPMSCapableReq);
308     register int n;
309
310     swaps(&stuff->length, n);
311     REQUEST_SIZE_MATCH(xDPMSCapableReq);
312
313     return ProcDPMSCapable(client);
314 }
315
316 static int
317 SProcDPMSGetTimeouts(client)
318     register ClientPtr client;
319 {
320     REQUEST(xDPMSGetTimeoutsReq);
321     register int n;
322
323     swaps(&stuff->length, n);
324     REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
325
326     return ProcDPMSGetTimeouts(client);
327 }
328
329 static int
330 SProcDPMSSetTimeouts(client)
331     register ClientPtr client;
332 {
333     REQUEST(xDPMSSetTimeoutsReq);
334     register int n;
335
336     swaps(&stuff->length, n);
337     REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
338
339     swaps(&stuff->standby, n);
340     swaps(&stuff->suspend, n);
341     swaps(&stuff->off, n);
342     return ProcDPMSSetTimeouts(client);
343 }
344
345 static int
346 SProcDPMSEnable(client)
347     register ClientPtr client;
348 {
349     REQUEST(xDPMSEnableReq);
350     register int n;
351
352     swaps(&stuff->length, n);
353     REQUEST_SIZE_MATCH(xDPMSEnableReq);
354
355     return ProcDPMSEnable(client);
356 }
357
358 static int
359 SProcDPMSDisable(client)
360     register ClientPtr client;
361 {
362     REQUEST(xDPMSDisableReq);
363     register int n;
364
365     swaps(&stuff->length, n);
366     REQUEST_SIZE_MATCH(xDPMSDisableReq);
367
368     return ProcDPMSDisable(client);
369 }
370
371 static int
372 SProcDPMSForceLevel(client)
373     register ClientPtr client;
374 {
375     REQUEST(xDPMSForceLevelReq);
376     register int n;
377
378     swaps(&stuff->length, n);
379     REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
380
381     swaps(&stuff->level, n);
382
383     return ProcDPMSForceLevel(client);
384 }
385
386 static int
387 SProcDPMSInfo(client)
388     register ClientPtr client;
389 {
390     REQUEST(xDPMSInfoReq);
391     register int n;
392
393     swaps(&stuff->length, n);
394     REQUEST_SIZE_MATCH(xDPMSInfoReq);
395
396     return ProcDPMSInfo(client);
397 }
398
399 static int
400 SProcDPMSDispatch (client)
401     register ClientPtr  client;
402 {
403     REQUEST(xReq);
404     switch (stuff->data)
405     {
406     case X_DPMSGetVersion:
407         return SProcDPMSGetVersion(client);
408     case X_DPMSCapable:
409         return SProcDPMSCapable(client);
410     case X_DPMSGetTimeouts:
411         return SProcDPMSGetTimeouts(client);
412     case X_DPMSSetTimeouts:
413         return SProcDPMSSetTimeouts(client);
414     case X_DPMSEnable:
415         return SProcDPMSEnable(client);
416     case X_DPMSDisable:
417         return SProcDPMSDisable(client);
418     case X_DPMSForceLevel:
419         return SProcDPMSForceLevel(client);
420     case X_DPMSInfo:
421         return SProcDPMSInfo(client);
422     default:
423         return BadRequest;
424     }
425 }