Initial commit
[xorg_rtime.git] / libXext-1.0.2 / src / DPMS.c
blob35b21b4adb6676e779c63aaa187f021f3ac9b6e8
1 /* $Xorg: DPMS.c,v 1.3 2000/08/17 19:45:50 cpqbld Exp $ */
2 /*****************************************************************
4 Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts.
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software.
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
19 BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
21 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of Digital Equipment Corporation
24 shall not be used in advertising or otherwise to promote the sale, use or other
25 dealings in this Software without prior written authorization from Digital
26 Equipment Corporation.
28 ******************************************************************/
29 /* $XFree86: xc/lib/Xext/DPMS.c,v 3.5 2002/10/16 00:37:27 dawes Exp $ */
32 * HISTORY
35 #define NEED_REPLIES
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39 #include <X11/Xlibint.h>
40 #include <X11/extensions/dpms.h>
41 #include <X11/extensions/dpmsstr.h>
42 #include <X11/extensions/Xext.h>
43 #include <X11/extensions/extutil.h>
44 #include <stdio.h>
46 static XExtensionInfo _dpms_info_data;
47 static XExtensionInfo *dpms_info = &_dpms_info_data;
48 static char *dpms_extension_name = DPMSExtensionName;
50 #define DPMSCheckExtension(dpy,i,val) \
51 XextCheckExtension (dpy, i, dpms_extension_name, val)
53 /*****************************************************************************
54 * *
55 * private utility routines *
56 * *
57 *****************************************************************************/
59 static int close_display(Display *dpy, XExtCodes *codes);
60 static /* const */ XExtensionHooks dpms_extension_hooks = {
61 NULL, /* create_gc */
62 NULL, /* copy_gc */
63 NULL, /* flush_gc */
64 NULL, /* free_gc */
65 NULL, /* create_font */
66 NULL, /* free_font */
67 close_display, /* close_display */
68 NULL, /* wire_to_event */
69 NULL, /* event_to_wire */
70 NULL, /* error */
71 NULL /* error_string */
74 static XEXT_GENERATE_FIND_DISPLAY (find_display, dpms_info,
75 dpms_extension_name,
76 &dpms_extension_hooks, DPMSNumberEvents,
77 NULL)
79 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, dpms_info)
81 /*****************************************************************************
82 * *
83 * public routines *
84 * *
85 *****************************************************************************/
87 Bool
88 DPMSQueryExtension (Display *dpy, int *event_basep, int *error_basep)
90 XExtDisplayInfo *info = find_display (dpy);
92 if (XextHasExtension(info)) {
93 *event_basep = info->codes->first_event;
94 *error_basep = info->codes->first_error;
95 return True;
96 } else {
97 return False;
101 Status
102 DPMSGetVersion(Display *dpy, int *major_versionp, int *minor_versionp)
104 XExtDisplayInfo *info = find_display (dpy);
105 xDPMSGetVersionReply rep;
106 register xDPMSGetVersionReq *req;
108 DPMSCheckExtension (dpy, info, 0);
110 LockDisplay (dpy);
111 GetReq (DPMSGetVersion, req);
112 req->reqType = info->codes->major_opcode;
113 req->dpmsReqType = X_DPMSGetVersion;
114 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
115 UnlockDisplay (dpy);
116 SyncHandle ();
117 return 0;
119 *major_versionp = rep.majorVersion;
120 *minor_versionp = rep.minorVersion;
121 UnlockDisplay (dpy);
122 SyncHandle ();
123 return 1;
126 Bool
127 DPMSCapable(Display *dpy)
129 XExtDisplayInfo *info = find_display (dpy);
130 register xDPMSCapableReq *req;
131 xDPMSCapableReply rep;
133 DPMSCheckExtension (dpy, info, 0);
135 LockDisplay(dpy);
136 GetReq(DPMSCapable, req);
137 req->reqType = info->codes->major_opcode;
138 req->dpmsReqType = X_DPMSCapable;
140 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
141 UnlockDisplay(dpy);
142 SyncHandle();
143 return False;
145 UnlockDisplay(dpy);
146 SyncHandle();
147 return rep.capable;
150 Status
151 DPMSSetTimeouts(Display *dpy, CARD16 standby, CARD16 suspend, CARD16 off)
153 XExtDisplayInfo *info = find_display (dpy);
154 register xDPMSSetTimeoutsReq *req;
156 if ((off != 0)&&(off < suspend))
158 return BadValue;
160 if ((suspend != 0)&&(suspend < standby))
162 return BadValue;
165 DPMSCheckExtension (dpy, info, 0);
166 LockDisplay(dpy);
167 GetReq(DPMSSetTimeouts, req);
168 req->reqType = info->codes->major_opcode;
169 req->dpmsReqType = X_DPMSSetTimeouts;
170 req->standby = standby;
171 req->suspend = suspend;
172 req->off = off;
174 UnlockDisplay(dpy);
175 SyncHandle();
176 return 1;
179 Bool
180 DPMSGetTimeouts(Display *dpy, CARD16 *standby, CARD16 *suspend, CARD16 *off)
182 XExtDisplayInfo *info = find_display (dpy);
183 register xDPMSGetTimeoutsReq *req;
184 xDPMSGetTimeoutsReply rep;
186 DPMSCheckExtension (dpy, info, 0);
188 LockDisplay(dpy);
189 GetReq(DPMSGetTimeouts, req);
190 req->reqType = info->codes->major_opcode;
191 req->dpmsReqType = X_DPMSGetTimeouts;
193 if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
194 UnlockDisplay(dpy);
195 SyncHandle();
196 return False;
198 UnlockDisplay(dpy);
199 SyncHandle();
200 *standby = rep.standby;
201 *suspend = rep.suspend;
202 *off = rep.off;
203 return 1;
206 Status
207 DPMSEnable(Display *dpy)
209 XExtDisplayInfo *info = find_display (dpy);
210 register xDPMSEnableReq *req;
212 DPMSCheckExtension (dpy, info, 0);
213 LockDisplay(dpy);
214 GetReq(DPMSEnable, req);
215 req->reqType = info->codes->major_opcode;
216 req->dpmsReqType = X_DPMSEnable;
218 UnlockDisplay(dpy);
219 SyncHandle();
220 return 1;
223 Status
224 DPMSDisable(Display *dpy)
226 XExtDisplayInfo *info = find_display (dpy);
227 register xDPMSDisableReq *req;
229 DPMSCheckExtension (dpy, info, 0);
230 LockDisplay(dpy);
231 GetReq(DPMSDisable, req);
232 req->reqType = info->codes->major_opcode;
233 req->dpmsReqType = X_DPMSDisable;
235 UnlockDisplay(dpy);
236 SyncHandle();
237 return 1;
241 Status
242 DPMSForceLevel(Display *dpy, CARD16 level)
244 XExtDisplayInfo *info = find_display (dpy);
245 register xDPMSForceLevelReq *req;
247 DPMSCheckExtension (dpy, info, 0);
249 if ((level != DPMSModeOn) &&
250 (level != DPMSModeStandby) &&
251 (level != DPMSModeSuspend) &&
252 (level != DPMSModeOff))
253 return BadValue;
255 LockDisplay(dpy);
256 GetReq(DPMSForceLevel, req);
257 req->reqType = info->codes->major_opcode;
258 req->dpmsReqType = X_DPMSForceLevel;
259 req->level = level;
261 UnlockDisplay(dpy);
262 SyncHandle();
263 return 1;
266 Status
267 DPMSInfo(Display *dpy, CARD16 *power_level, BOOL *state)
269 XExtDisplayInfo *info = find_display (dpy);
270 register xDPMSInfoReq *req;
271 xDPMSInfoReply rep;
273 DPMSCheckExtension (dpy, info, 0);
275 LockDisplay(dpy);
276 GetReq(DPMSInfo, req);
277 req->reqType = info->codes->major_opcode;
278 req->dpmsReqType = X_DPMSInfo;
280 if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
281 UnlockDisplay(dpy);
282 SyncHandle();
283 return False;
285 UnlockDisplay(dpy);
286 SyncHandle();
287 *power_level = rep.power_level;
288 *state = rep.state;
289 return 1;