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 $ */
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>
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 /*****************************************************************************
55 * private utility routines *
57 *****************************************************************************/
59 static int close_display(Display
*dpy
, XExtCodes
*codes
);
60 static /* const */ XExtensionHooks dpms_extension_hooks
= {
65 NULL
, /* create_font */
67 close_display
, /* close_display */
68 NULL
, /* wire_to_event */
69 NULL
, /* event_to_wire */
71 NULL
/* error_string */
74 static XEXT_GENERATE_FIND_DISPLAY (find_display
, dpms_info
,
76 &dpms_extension_hooks
, DPMSNumberEvents
,
79 static XEXT_GENERATE_CLOSE_DISPLAY (close_display
, dpms_info
)
81 /*****************************************************************************
85 *****************************************************************************/
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
;
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);
111 GetReq (DPMSGetVersion
, req
);
112 req
->reqType
= info
->codes
->major_opcode
;
113 req
->dpmsReqType
= X_DPMSGetVersion
;
114 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xTrue
)) {
119 *major_versionp
= rep
.majorVersion
;
120 *minor_versionp
= rep
.minorVersion
;
127 DPMSCapable(Display
*dpy
)
129 XExtDisplayInfo
*info
= find_display (dpy
);
130 register xDPMSCapableReq
*req
;
131 xDPMSCapableReply rep
;
133 DPMSCheckExtension (dpy
, info
, 0);
136 GetReq(DPMSCapable
, req
);
137 req
->reqType
= info
->codes
->major_opcode
;
138 req
->dpmsReqType
= X_DPMSCapable
;
140 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xFalse
)) {
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
))
160 if ((suspend
!= 0)&&(suspend
< standby
))
165 DPMSCheckExtension (dpy
, info
, 0);
167 GetReq(DPMSSetTimeouts
, req
);
168 req
->reqType
= info
->codes
->major_opcode
;
169 req
->dpmsReqType
= X_DPMSSetTimeouts
;
170 req
->standby
= standby
;
171 req
->suspend
= suspend
;
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);
189 GetReq(DPMSGetTimeouts
, req
);
190 req
->reqType
= info
->codes
->major_opcode
;
191 req
->dpmsReqType
= X_DPMSGetTimeouts
;
193 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xTrue
)) {
200 *standby
= rep
.standby
;
201 *suspend
= rep
.suspend
;
207 DPMSEnable(Display
*dpy
)
209 XExtDisplayInfo
*info
= find_display (dpy
);
210 register xDPMSEnableReq
*req
;
212 DPMSCheckExtension (dpy
, info
, 0);
214 GetReq(DPMSEnable
, req
);
215 req
->reqType
= info
->codes
->major_opcode
;
216 req
->dpmsReqType
= X_DPMSEnable
;
224 DPMSDisable(Display
*dpy
)
226 XExtDisplayInfo
*info
= find_display (dpy
);
227 register xDPMSDisableReq
*req
;
229 DPMSCheckExtension (dpy
, info
, 0);
231 GetReq(DPMSDisable
, req
);
232 req
->reqType
= info
->codes
->major_opcode
;
233 req
->dpmsReqType
= X_DPMSDisable
;
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
))
256 GetReq(DPMSForceLevel
, req
);
257 req
->reqType
= info
->codes
->major_opcode
;
258 req
->dpmsReqType
= X_DPMSForceLevel
;
267 DPMSInfo(Display
*dpy
, CARD16
*power_level
, BOOL
*state
)
269 XExtDisplayInfo
*info
= find_display (dpy
);
270 register xDPMSInfoReq
*req
;
273 DPMSCheckExtension (dpy
, info
, 0);
276 GetReq(DPMSInfo
, req
);
277 req
->reqType
= info
->codes
->major_opcode
;
278 req
->dpmsReqType
= X_DPMSInfo
;
280 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xTrue
)) {
287 *power_level
= rep
.power_level
;