Debian Codegraph @

src/DPMS.c

raw
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
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
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>
41 #include <stdio.h>
42
43 static XExtensionInfo _dpms_info_data;
44 static XExtensionInfo *dpms_info = &_dpms_info_data;
45 static const char *dpms_extension_name = DPMSExtensionName;
46
47 #define DPMSCheckExtension(dpy,i,val) \
48 XextCheckExtension (dpy, i, dpms_extension_name, val)
49
50 /*****************************************************************************
51 * *
52 * private utility routines *
53 * *
54 *****************************************************************************/
55
56 static int close_display(Display *dpy, XExtCodes *codes);
57 static /* const */ XExtensionHooks dpms_extension_hooks = {
58 NULL, /* create_gc */
59 NULL, /* copy_gc */
60 NULL, /* flush_gc */
61 NULL, /* free_gc */
62 NULL, /* create_font */
63 NULL, /* free_font */
64 close_display, /* close_display */
65 NULL, /* wire_to_event */
66 NULL, /* event_to_wire */
67 NULL, /* error */
68 NULL /* error_string */
69 };
70
71 static XEXT_GENERATE_FIND_DISPLAY (find_display, dpms_info,
72 dpms_extension_name,
73 &dpms_extension_hooks, DPMSNumberEvents,
74 NULL)
75
76 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, dpms_info)
77
78 /*****************************************************************************
79 * *
80 * public routines *
81 * *
82 *****************************************************************************/
83
84 Bool
85 DPMSQueryExtension (Display *dpy, int *event_basep, int *error_basep)
86 {
87 XExtDisplayInfo *info = find_display (dpy);
88
89 if (XextHasExtension(info)) {
90 *event_basep = info->codes->first_event;
91 *error_basep = info->codes->first_error;
92 return True;
93 } else {
94 return False;
95 }
96 }
97
98 Status
99 DPMSGetVersion(Display *dpy, int *major_versionp, int *minor_versionp)
100 {
101 XExtDisplayInfo *info = find_display (dpy);
102 xDPMSGetVersionReply rep;
103 register xDPMSGetVersionReq *req;
104
105 DPMSCheckExtension (dpy, info, 0);
106
107 LockDisplay (dpy);
108 GetReq (DPMSGetVersion, req);
109 req->reqType = info->codes->major_opcode;
110 req->dpmsReqType = X_DPMSGetVersion;
111 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
112 UnlockDisplay (dpy);
113 SyncHandle ();
114 return 0;
115 }
116 *major_versionp = rep.majorVersion;
117 *minor_versionp = rep.minorVersion;
118 UnlockDisplay (dpy);
119 SyncHandle ();
120 return 1;
121 }
122
123 Bool
124 DPMSCapable(Display *dpy)
125 {
126 XExtDisplayInfo *info = find_display (dpy);
127 register xDPMSCapableReq *req;
128 xDPMSCapableReply rep;
129
130 DPMSCheckExtension (dpy, info, 0);
131
132 LockDisplay(dpy);
133 GetReq(DPMSCapable, req);
134 req->reqType = info->codes->major_opcode;
135 req->dpmsReqType = X_DPMSCapable;
136
137 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
138 UnlockDisplay(dpy);
139 SyncHandle();
140 return False;
141 }
142 UnlockDisplay(dpy);
143 SyncHandle();
144 return rep.capable;
145 }
146
147 Status
148 DPMSSetTimeouts(Display *dpy, CARD16 standby, CARD16 suspend, CARD16 off)
149 {
150 XExtDisplayInfo *info = find_display (dpy);
151 register xDPMSSetTimeoutsReq *req;
152
153 if ((off != 0)&&(off < suspend))
154 {
155 return BadValue;
156 }
157 if ((suspend != 0)&&(suspend < standby))
158 {
159 return BadValue;
160 }
161
162 DPMSCheckExtension (dpy, info, 0);
163 LockDisplay(dpy);
164 GetReq(DPMSSetTimeouts, req);
165 req->reqType = info->codes->major_opcode;
166 req->dpmsReqType = X_DPMSSetTimeouts;
167 req->standby = standby;
168 req->suspend = suspend;
169 req->off = off;
170
171 UnlockDisplay(dpy);
172 SyncHandle();
173 return 1;
174 }
175
176 Bool
177 DPMSGetTimeouts(Display *dpy, CARD16 *standby, CARD16 *suspend, CARD16 *off)
178 {
179 XExtDisplayInfo *info = find_display (dpy);
180 register xDPMSGetTimeoutsReq *req;
181 xDPMSGetTimeoutsReply rep;
182
183 DPMSCheckExtension (dpy, info, 0);
184
185 LockDisplay(dpy);
186 GetReq(DPMSGetTimeouts, req);
187 req->reqType = info->codes->major_opcode;
188 req->dpmsReqType = X_DPMSGetTimeouts;
189
190 if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
191 UnlockDisplay(dpy);
192 SyncHandle();
193 return False;
194 }
195 UnlockDisplay(dpy);
196 SyncHandle();
197 *standby = rep.standby;
198 *suspend = rep.suspend;
199 *off = rep.off;
200 return 1;
201 }
202
203 Status
204 DPMSEnable(Display *dpy)
205 {
206 XExtDisplayInfo *info = find_display (dpy);
207 register xDPMSEnableReq *req;
208
209 DPMSCheckExtension (dpy, info, 0);
210 LockDisplay(dpy);
211 GetReq(DPMSEnable, req);
212 req->reqType = info->codes->major_opcode;
213 req->dpmsReqType = X_DPMSEnable;
214
215 UnlockDisplay(dpy);
216 SyncHandle();
217 return 1;
218 }
219
220 Status
221 DPMSDisable(Display *dpy)
222 {
223 XExtDisplayInfo *info = find_display (dpy);
224 register xDPMSDisableReq *req;
225
226 DPMSCheckExtension (dpy, info, 0);
227 LockDisplay(dpy);
228 GetReq(DPMSDisable, req);
229 req->reqType = info->codes->major_opcode;
230 req->dpmsReqType = X_DPMSDisable;
231
232 UnlockDisplay(dpy);
233 SyncHandle();
234 return 1;
235 }
236
237
238 Status
239 DPMSForceLevel(Display *dpy, CARD16 level)
240 {
241 XExtDisplayInfo *info = find_display (dpy);
242 register xDPMSForceLevelReq *req;
243
244 DPMSCheckExtension (dpy, info, 0);
245
246 if ((level != DPMSModeOn) &&
247 (level != DPMSModeStandby) &&
248 (level != DPMSModeSuspend) &&
249 (level != DPMSModeOff))
250 return BadValue;
251
252 LockDisplay(dpy);
253 GetReq(DPMSForceLevel, req);
254 req->reqType = info->codes->major_opcode;
255 req->dpmsReqType = X_DPMSForceLevel;
256 req->level = level;
257
258 UnlockDisplay(dpy);
259 SyncHandle();
260 return 1;
261 }
262
263 Status
264 DPMSInfo(Display *dpy, CARD16 *power_level, BOOL *state)
265 {
266 XExtDisplayInfo *info = find_display (dpy);
267 register xDPMSInfoReq *req;
268 xDPMSInfoReply rep;
269
270 DPMSCheckExtension (dpy, info, 0);
271
272 LockDisplay(dpy);
273 GetReq(DPMSInfo, req);
274 req->reqType = info->codes->major_opcode;
275 req->dpmsReqType = X_DPMSInfo;
276
277 if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
278 UnlockDisplay(dpy);
279 SyncHandle();
280 return False;
281 }
282 UnlockDisplay(dpy);
283 SyncHandle();
284 *power_level = rep.power_level;
285 *state = rep.state;
286 return 1;
287 }
288
289
290