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 ******************************************************************/
36 #include <X11/Xlibint.h>
37 #include <X11/extensions/dpms.h>
38 #include <X11/extensions/dpmsproto.h>
39 #include <X11/extensions/Xext.h>
40 #include <X11/extensions/extutil.h>
43 static XExtensionInfo _dpms_info_data;
44 static XExtensionInfo *dpms_info = &_dpms_info_data;
45 static const char *dpms_extension_name = DPMSExtensionName;
47 #define DPMSCheckExtension(dpy,i,val) \
48 XextCheckExtension (dpy, i, dpms_extension_name, val)
50 /*****************************************************************************
52 * private utility routines *
54 *****************************************************************************/
56 static int close_display(Display *dpy, XExtCodes *codes);
57 static /* const */ XExtensionHooks dpms_extension_hooks = {
62 NULL, /* create_font */
64 close_display, /* close_display */
65 NULL, /* wire_to_event */
66 NULL, /* event_to_wire */
68 NULL /* error_string */
71 static XEXT_GENERATE_FIND_DISPLAY (find_display, dpms_info,
73 &dpms_extension_hooks, DPMSNumberEvents,
76 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, dpms_info)
78 /*****************************************************************************
82 *****************************************************************************/
85 DPMSQueryExtension (Display *dpy, int *event_basep, int *error_basep)
87 XExtDisplayInfo *info = find_display (dpy);
89 if (XextHasExtension(info)) {
90 *event_basep = info->codes->first_event;
91 *error_basep = info->codes->first_error;
99 DPMSGetVersion(Display *dpy, int *major_versionp, int *minor_versionp)
101 XExtDisplayInfo *info = find_display (dpy);
102 xDPMSGetVersionReply rep;
103 register xDPMSGetVersionReq *req;
105 DPMSCheckExtension (dpy, info, 0);
108 GetReq (DPMSGetVersion, req);
109 req->reqType = info->codes->major_opcode;
110 req->dpmsReqType = X_DPMSGetVersion;
111 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
116 *major_versionp = rep.majorVersion;
117 *minor_versionp = rep.minorVersion;
124 DPMSCapable(Display *dpy)
126 XExtDisplayInfo *info = find_display (dpy);
127 register xDPMSCapableReq *req;
128 xDPMSCapableReply rep;
130 DPMSCheckExtension (dpy, info, 0);
133 GetReq(DPMSCapable, req);
134 req->reqType = info->codes->major_opcode;
135 req->dpmsReqType = X_DPMSCapable;
137 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
148 DPMSSetTimeouts(Display *dpy, CARD16 standby, CARD16 suspend, CARD16 off)
150 XExtDisplayInfo *info = find_display (dpy);
151 register xDPMSSetTimeoutsReq *req;
153 if ((off != 0)&&(off < suspend))
157 if ((suspend != 0)&&(suspend < standby))
162 DPMSCheckExtension (dpy, info, 0);
164 GetReq(DPMSSetTimeouts, req);
165 req->reqType = info->codes->major_opcode;
166 req->dpmsReqType = X_DPMSSetTimeouts;
167 req->standby = standby;
168 req->suspend = suspend;
177 DPMSGetTimeouts(Display *dpy, CARD16 *standby, CARD16 *suspend, CARD16 *off)
179 XExtDisplayInfo *info = find_display (dpy);
180 register xDPMSGetTimeoutsReq *req;
181 xDPMSGetTimeoutsReply rep;
183 DPMSCheckExtension (dpy, info, 0);
186 GetReq(DPMSGetTimeouts, req);
187 req->reqType = info->codes->major_opcode;
188 req->dpmsReqType = X_DPMSGetTimeouts;
190 if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
197 *standby = rep.standby;
198 *suspend = rep.suspend;
204 DPMSEnable(Display *dpy)
206 XExtDisplayInfo *info = find_display (dpy);
207 register xDPMSEnableReq *req;
209 DPMSCheckExtension (dpy, info, 0);
211 GetReq(DPMSEnable, req);
212 req->reqType = info->codes->major_opcode;
213 req->dpmsReqType = X_DPMSEnable;
221 DPMSDisable(Display *dpy)
223 XExtDisplayInfo *info = find_display (dpy);
224 register xDPMSDisableReq *req;
226 DPMSCheckExtension (dpy, info, 0);
228 GetReq(DPMSDisable, req);
229 req->reqType = info->codes->major_opcode;
230 req->dpmsReqType = X_DPMSDisable;
239 DPMSForceLevel(Display *dpy, CARD16 level)
241 XExtDisplayInfo *info = find_display (dpy);
242 register xDPMSForceLevelReq *req;
244 DPMSCheckExtension (dpy, info, 0);
246 if ((level != DPMSModeOn) &&
247 (level != DPMSModeStandby) &&
248 (level != DPMSModeSuspend) &&
249 (level != DPMSModeOff))
253 GetReq(DPMSForceLevel, req);
254 req->reqType = info->codes->major_opcode;
255 req->dpmsReqType = X_DPMSForceLevel;
264 DPMSInfo(Display *dpy, CARD16 *power_level, BOOL *state)
266 XExtDisplayInfo *info = find_display (dpy);
267 register xDPMSInfoReq *req;
270 DPMSCheckExtension (dpy, info, 0);
273 GetReq(DPMSInfo, req);
274 req->reqType = info->codes->major_opcode;
275 req->dpmsReqType = X_DPMSInfo;
277 if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
284 *power_level = rep.power_level;