swi-prolog: update to 9.2.9
[oi-userland.git] / components / x11 / libXext / srcs / src / FBPM.c
blob1aca37b68aed3e731011433ed6645366411c0674
1 /*
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * 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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 #define NEED_REPLIES
26 #include <X11/Xlibint.h>
27 #include <X11/extensions/fbpm.h>
28 #include <X11/extensions/fbpmstr.h>
29 #include <X11/extensions/Xext.h>
30 #include <X11/extensions/extutil.h>
31 #include <stdio.h>
33 static XExtensionInfo _fbpm_info_data;
34 static XExtensionInfo *fbpm_info = &_fbpm_info_data;
35 static char *fbpm_extension_name = FBPMExtensionName;
37 #define FBPMCheckExtension(dpy,i,val) \
38 XextCheckExtension (dpy, i, fbpm_extension_name, val)
40 /*****************************************************************************
41 * *
42 * private utility routines *
43 * *
44 *****************************************************************************/
46 static int close_display(Display *dpy, XExtCodes *codes);
47 static /* const */ XExtensionHooks fbpm_extension_hooks = {
48 NULL, /* create_gc */
49 NULL, /* copy_gc */
50 NULL, /* flush_gc */
51 NULL, /* free_gc */
52 NULL, /* create_font */
53 NULL, /* free_font */
54 close_display, /* close_display */
55 NULL, /* wire_to_event */
56 NULL, /* event_to_wire */
57 NULL, /* error */
58 NULL /* error_string */
61 static XEXT_GENERATE_FIND_DISPLAY (find_display, fbpm_info,
62 fbpm_extension_name,
63 &fbpm_extension_hooks, FBPMNumberEvents,
64 NULL)
66 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, fbpm_info)
68 /*****************************************************************************
69 * *
70 * public routines *
71 * *
72 *****************************************************************************/
74 Bool FBPMQueryExtension (
75 Display *dpy,
76 int *event_basep,
77 int *error_basep)
79 XExtDisplayInfo *info = find_display (dpy);
81 if (XextHasExtension(info)) {
82 *event_basep = info->codes->first_event;
83 *error_basep = info->codes->first_error;
84 return True;
85 } else {
86 return False;
90 Status FBPMGetVersion(
91 Display *dpy,
92 int *major_versionp,
93 int *minor_versionp)
95 XExtDisplayInfo *info = find_display (dpy);
96 xFBPMGetVersionReply rep;
97 register xFBPMGetVersionReq *req;
99 FBPMCheckExtension (dpy, info, 0);
101 LockDisplay (dpy);
102 GetReq (FBPMGetVersion, req);
103 req->reqType = info->codes->major_opcode;
104 req->fbpmReqType = X_FBPMGetVersion;
105 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
106 UnlockDisplay (dpy);
107 SyncHandle ();
108 return 0;
110 *major_versionp = rep.majorVersion;
111 *minor_versionp = rep.minorVersion;
112 UnlockDisplay (dpy);
113 SyncHandle ();
114 return 1;
117 Bool FBPMCapable(
118 Display *dpy)
120 XExtDisplayInfo *info = find_display (dpy);
121 register xFBPMCapableReq *req;
122 xFBPMCapableReply rep;
124 FBPMCheckExtension (dpy, info, 0);
126 LockDisplay(dpy);
127 GetReq(FBPMCapable, req);
128 req->reqType = info->codes->major_opcode;
129 req->fbpmReqType = X_FBPMCapable;
131 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
132 UnlockDisplay(dpy);
133 SyncHandle();
134 return False;
136 UnlockDisplay(dpy);
137 SyncHandle();
138 return rep.capable;
142 Bool FBPMEnable(
143 Display *dpy,
144 int state)
146 XExtDisplayInfo *info = find_display (dpy);
147 register xFBPMEnableReq *req;
149 FBPMCheckExtension (dpy, info, 0);
150 LockDisplay(dpy);
151 GetReq(FBPMEnable, req);
152 req->reqType = info->codes->major_opcode;
153 req->fbpmReqType = X_FBPMEnable;
154 req->level = state;
156 UnlockDisplay(dpy);
157 SyncHandle();
158 return True;
161 Status FBPMDisable(
162 Display *dpy)
164 XExtDisplayInfo *info = find_display (dpy);
165 register xFBPMDisableReq *req;
167 FBPMCheckExtension (dpy, info, 0);
168 LockDisplay(dpy);
169 GetReq(FBPMDisable, req);
170 req->reqType = info->codes->major_opcode;
171 req->fbpmReqType = X_FBPMDisable;
173 UnlockDisplay(dpy);
174 SyncHandle();
175 return 1;
177 Status FBPMForceLevel(
178 Display *dpy,
179 CARD16 level)
181 XExtDisplayInfo *info = find_display (dpy);
182 register xFBPMForceLevelReq *req;
184 FBPMCheckExtension (dpy, info, 0);
186 if ((level != FBPMModeOn) &&
187 (level != FBPMModeStandby) &&
188 (level != FBPMModeSuspend) &&
189 (level != FBPMModeOff))
190 return BadValue;
192 LockDisplay(dpy);
193 GetReq(FBPMForceLevel, req);
194 req->reqType = info->codes->major_opcode;
195 req->fbpmReqType = X_FBPMForceLevel;
196 req->level = level;
198 UnlockDisplay(dpy);
199 SyncHandle();
200 return 1;
203 Status FBPMInfo(
204 Display *dpy,
205 CARD16 *state,
206 BOOL *onoff)
208 XExtDisplayInfo *info = find_display (dpy);
209 register xFBPMInfoReq *req;
210 xFBPMInfoReply rep;
212 FBPMCheckExtension (dpy, info, 0);
214 LockDisplay(dpy);
215 GetReq(FBPMInfo, req);
216 req->reqType = info->codes->major_opcode;
217 req->fbpmReqType = X_FBPMInfo;
219 if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
220 UnlockDisplay(dpy);
221 SyncHandle();
222 return 0;
224 UnlockDisplay(dpy);
225 SyncHandle();
226 *state = rep.power_level;
227 *onoff = rep.state;
228 return 1;