pulseaudio: fix dependencies for openssl-3
[oi-userland.git] / components / x11 / libXext / srcs / src / XGrabWin.c
blob3a08505f343c1db04189b379e90dda69d3ecff2b
1 /* Copyright (c) 1990, 2015, Oracle and/or its affiliates. All rights reserved.
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * 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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
23 /*-
24 *-----------------------------------------------------------------------
25 * XGrabWin.c - X11 Client Side interface to Window Grabber.
27 * This code uses the standard R3 extension mechanism for sending the grab or
28 * ungrab window requests. If the extension isn't present, it uses the un-used
29 * protocol if the server is from Sun.
31 * The global state is only relevant to one display. Multiple displays
32 * will have to be implemented via arrays of global data.
33 *-----------------------------------------------------------------------
35 #define NEED_REPLIES
36 #define NEED_EVENTS
38 #include <string.h>
39 #include <unistd.h>
41 #include <X11/Xlibint.h> /* from usr.lib/libX11 */
42 #include <X11/Xproto.h> /* from usr.lib/libX11/include */
43 #include <X11/extensions/dgast.h>
45 #include <sys/socket.h>
46 #include <netinet/in.h>
47 #include <sys/types.h>
48 /* Unused requests */
49 #define X_GrabWindow 125 /* should be in Xproto.h */
50 #define X_UnGrabWindow 126 /* just before X_NoOperation */
52 #define BadCookie 0
54 static int X_WxExtensionCode;
56 static int WxError (Display *dpy,int mc);
58 static enum {
59 NOT_INITIALIZED,
60 USE_EXTENSION,
61 USE_EXTRA_PROTOCOL,
62 NOT_LOCAL_HOST
63 } WxInitialized = NOT_INITIALIZED;
65 static void
66 Initialize(Display *dpy)
68 int tmp;
70 if (dpy->display_name[0] != ':') {
71 char hostname[64];
73 gethostname(hostname,64);
74 if (strncmp("unix",dpy->display_name,4) &&
75 strncmp("localhost",dpy->display_name,9) &&
76 strncmp(hostname,dpy->display_name,strlen(hostname))) {
77 WxInitialized = NOT_LOCAL_HOST;
78 return;
82 if (XQueryExtension(dpy, "SunWindowGrabber",&X_WxExtensionCode,
83 &tmp, &tmp))
84 WxInitialized = USE_EXTENSION;
85 else if (!strcmp(dpy->vendor,"X11/NeWS - Sun Microsystems Inc."))
86 WxInitialized = USE_EXTRA_PROTOCOL;
89 int
90 XGrabWindow(
91 Display *dpy,
92 Window win)
94 xResourceReq *req;
95 xGenericReply rep;
97 if (WxInitialized == NOT_INITIALIZED)
98 Initialize(dpy);
100 switch (WxInitialized) {
101 case USE_EXTENSION:
102 LockDisplay(dpy);
103 GetResReq(WxExtensionCode, win, req);
104 req->pad = X_WxGrab;
105 (void) _XReply(dpy, (xReply *) &rep, 0, xFalse);
106 UnlockDisplay(dpy);
107 SyncHandle();
108 return rep.data00;
109 case USE_EXTRA_PROTOCOL:
110 LockDisplay(dpy);
111 GetResReq(GrabWindow, win, req);
112 (void) _XReply(dpy, (xReply *) &rep, 0, xFalse);
113 UnlockDisplay(dpy);
114 SyncHandle();
115 return (rep.data00); /* GrabToken */
116 case NOT_INITIALIZED:
117 WxError(dpy,X_WxGrab);
118 case NOT_LOCAL_HOST:
119 return BadCookie;
121 return BadImplementation;
125 XUnGrabWindow(
126 Display *dpy,
127 Window win)
129 xResourceReq *req;
130 xGenericReply rep;
132 if (WxInitialized == NOT_INITIALIZED)
133 Initialize(dpy);
135 switch (WxInitialized) {
136 case USE_EXTENSION:
137 LockDisplay(dpy);
138 GetResReq(WxExtensionCode, win, req);
139 req->pad = X_WxUnGrab;
140 (void) _XReply(dpy, (xReply *) &rep, 0, xFalse);
141 UnlockDisplay(dpy);
142 SyncHandle();
143 return rep.data00; /* Status */
144 case USE_EXTRA_PROTOCOL:
145 LockDisplay(dpy);
146 GetResReq(UnGrabWindow, win, req);
147 (void) _XReply(dpy, (xReply *) &rep, 0, xFalse);
148 UnlockDisplay(dpy);
149 SyncHandle();
150 return (rep.data00); /* Status */
151 case NOT_INITIALIZED:
152 WxError(dpy,X_WxUnGrab);
153 case NOT_LOCAL_HOST:
154 return BadCookie;
156 return BadImplementation;
160 int
161 XGrabColormap(
162 Display *dpy,
163 Colormap cmap)
165 xResourceReq *req;
166 xGenericReply rep;
168 if (WxInitialized == NOT_INITIALIZED)
169 Initialize(dpy);
171 switch (WxInitialized) {
172 case USE_EXTENSION:
173 LockDisplay(dpy);
174 GetResReq(WxExtensionCode, cmap, req);
175 req->pad = X_WxGrabColormap;
176 (void) _XReply(dpy, (xReply *) &rep, 0, xFalse);
177 UnlockDisplay(dpy);
178 SyncHandle();
179 return rep.data00;
180 case USE_EXTRA_PROTOCOL:
181 case NOT_INITIALIZED:
182 WxError(dpy,X_WxGrabColormap);
183 case NOT_LOCAL_HOST:
184 return BadCookie;
186 return BadImplementation;
190 XUnGrabColormap(
191 Display *dpy,
192 Colormap cmap)
194 xResourceReq *req;
195 xGenericReply rep;
197 if (WxInitialized == NOT_INITIALIZED)
198 Initialize(dpy);
200 switch (WxInitialized) {
201 case USE_EXTENSION:
202 LockDisplay(dpy);
203 GetResReq(WxExtensionCode, cmap, req);
204 req->pad = X_WxUnGrabColormap;
205 (void) _XReply(dpy, (xReply *) &rep, 0, xFalse);
206 UnlockDisplay(dpy);
207 SyncHandle();
208 return rep.data00; /* Status */
209 case USE_EXTRA_PROTOCOL:
210 case NOT_INITIALIZED:
211 WxError(dpy,X_WxGrabColormap);
212 case NOT_LOCAL_HOST:
213 return BadCookie;
215 return BadImplementation;
219 int
220 XGrabRetainedWindow(
221 Display *dpy,
222 Window win)
224 xResourceReq *req;
225 xGenericReply rep;
227 if (WxInitialized == NOT_INITIALIZED)
228 Initialize(dpy);
230 switch (WxInitialized) {
231 case USE_EXTENSION:
232 LockDisplay(dpy);
233 GetResReq(WxExtensionCode, win, req);
234 req->pad = X_WxGrabRetained;
235 (void) _XReply(dpy, (xReply *) &rep, 0, xFalse);
236 UnlockDisplay(dpy);
237 SyncHandle();
238 return rep.data00;
239 case USE_EXTRA_PROTOCOL:
240 case NOT_INITIALIZED:
241 WxError(dpy,X_WxGrabRetained);
242 case NOT_LOCAL_HOST:
243 return BadCookie;
245 return BadImplementation;
249 XUnGrabRetainedWindow(
250 Display *dpy,
251 Window win)
253 xResourceReq *req;
254 xGenericReply rep;
256 if (WxInitialized == NOT_INITIALIZED)
257 Initialize(dpy);
259 switch (WxInitialized) {
260 case USE_EXTENSION:
261 LockDisplay(dpy);
262 GetResReq(WxExtensionCode, win, req);
263 req->pad = X_WxUnGrabRetained;
264 (void) _XReply(dpy, (xReply *) &rep, 0, xFalse);
265 UnlockDisplay(dpy);
266 SyncHandle();
267 return rep.data00; /* Status */
268 case USE_EXTRA_PROTOCOL:
269 case NOT_INITIALIZED:
270 WxError(dpy,X_WxUnGrabRetained);
271 case NOT_LOCAL_HOST:
272 return BadCookie;
274 return BadImplementation;
279 XGetRetainedPath(
280 Display *dpy,
281 Window win,
282 char *path)
284 xResourceReq *req;
285 xOWGXRtndPathReply rep;
287 if (WxInitialized == NOT_INITIALIZED)
288 Initialize(dpy);
290 switch (WxInitialized) {
291 case USE_EXTENSION:
292 LockDisplay(dpy);
293 GetResReq(WxExtensionCode, win, req);
294 req->pad = X_WxGetRetainedPath;
295 (void) _XReply(dpy, (xReply *) &rep,
296 (SIZEOF(xOWGXRtndPathReply) - SIZEOF(xReply)) >> 2, xFalse);
297 UnlockDisplay(dpy);
298 SyncHandle();
299 strcpy(path, rep.path);
300 return Success;
301 case USE_EXTRA_PROTOCOL:
302 case NOT_INITIALIZED:
303 WxError(dpy,X_WxGetRetainedPath);
304 case NOT_LOCAL_HOST:
305 return BadCookie;
307 return BadImplementation;
314 static int
315 WxError (
316 Display *dpy,
317 int mc)
319 XErrorEvent event;
321 event.display = dpy;
322 event.type = X_Error;
323 event.error_code = BadImplementation;
324 event.request_code = 0xff; /* Means that we were requesting an extension*/
325 event.minor_code = mc;
326 event.serial = dpy->request;
327 if (_XErrorFunction != NULL) {
328 return ((*_XErrorFunction)(dpy, &event));
330 exit(1);
331 /*NOTREACHED*/