component(developer/golang-123): Add Component
[oi-userland.git] / components / x11 / libX11 / srcs / src / XInteractive.c
blob9aabdfdd2863e5a32c28a23b9d859bd1133d26d3
1 /*
2 * Copyright (c) 1993, 2013, 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.
27 Client side XIA extension code.
29 One can XSolarisIASetProceesInfo or XIASolarisGetProceesInfo.
30 Currently only passing process ids is supported.
32 Of course QueryVersion and QueryExtension are supported.
34 No support for error messages is involved. Yet. If this
35 interface becomes public this will need to be rewhacked
38 /* THIS IS NOT AN X CONSORTIUM STANDARD */
40 #define NEED_EVENTS
41 #define NEED_REPLIES
43 #if !defined(lint)
44 #ifdef HAVE_CONFIG_H
45 #include <config.h>
46 #endif
47 #endif
49 #include <unistd.h>
50 #include <stdio.h>
51 #include <X11/Xlibint.h>
52 #include <X11/extensions/interactive.h>
53 #include <X11/extensions/Xext.h>
54 #include <X11/extensions/XInteractive.h>
56 #ifdef IA_USE_EXTUTIL
57 #include <X11/extensions/extutil.h>
59 static XExtensionInfo _ia_info_data;
60 static XExtensionInfo *ia_info = &_ia_info_data;
62 static /* const */ char *ia_extension_name = IANAME;
64 #define IACheckExtension(dpy,i,val) \
65 XextCheckExtension (dpy, i, ia_extension_name, val)
66 #else
67 typedef struct _IAExtDisplayInfo {
68 Display *display;
69 XExtCodes *codes;
70 struct _IAExtDisplayInfo *next;
71 } IAExtDisplayInfo;
73 static IAExtDisplayInfo *iaExtDisplayList = NULL;
74 static const char *ia_extension_name = IANAME;
76 #define XExtDisplayInfo IAExtDisplayInfo
78 #define XextHasExtension(i) (((i) != NULL) && ((i)->codes != NULL))
80 #define IACheckExtension(dpy,i,val) \
81 if (!XextHasExtension(i)) { \
82 /* XMissingExtension (dpy, ia_extension_name); */ \
83 return val; \
86 #endif /* IA_USE_EXTUTIL */
88 /*****************************************************************************
89 * *
90 * private utility routines *
91 * *
92 *****************************************************************************/
94 #ifdef IA_USE_EXTUTIL
95 static int close_display();
96 static char *error_string();
97 static /* const */ XExtensionHooks ia_extension_hooks = {
98 NULL, /* create_gc */
99 NULL, /* copy_gc */
100 NULL, /* flush_gc */
101 NULL, /* free_gc */
102 NULL, /* create_font */
103 NULL, /* free_font */
104 close_display, /* close_display */
105 NULL, /* wire_to_event */
106 NULL, /* event_to_wire */
107 NULL, /* error */
108 error_string, /* error_string */
110 #endif
112 static const char *ia_error_list[] = {
113 "BadPid", /* Bad process id */
116 #ifdef IA_USE_EXTUTIL
117 static XEXT_GENERATE_FIND_DISPLAY (find_display, ia_info, ia_extension_name,
118 &ia_extension_hooks, IANumberEvents, NULL)
120 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, ia_info)
122 static XEXT_GENERATE_ERROR_STRING (error_string, ia_extension_name,
123 IANumberErrors, ia_error_list)
124 #else
125 static int ia_close_display(Display *dpy, XExtCodes *codes)
127 IAExtDisplayInfo *di, *prev, *next;
129 for (di = iaExtDisplayList, prev = NULL; di != NULL; di = next) {
130 next = di->next;
131 if (di->display == dpy) {
132 if (prev != NULL) {
133 prev->next = di->next;
134 } else {
135 iaExtDisplayList = di->next;
137 Xfree(di);
138 } else {
139 prev = di;
142 return Success;
145 static char *ia_error_string (Display *dpy, int err, XExtCodes *codes,
146 char *buf, int nbytes)
148 err -= codes->first_error;
149 if (err >= 0 && err < IANumberErrors) {
150 char tmp[256];
151 snprintf (tmp, sizeof(tmp), "%s.%d", ia_extension_name, err);
152 XGetErrorDatabaseText (dpy, "XProtoError", tmp, ia_error_list[err],
153 buf, nbytes);
154 return buf;
156 return NULL;
159 static IAExtDisplayInfo *ia_find_display(Display *dpy)
161 IAExtDisplayInfo *di;
163 for (di = iaExtDisplayList ; di != NULL; di = di->next) {
164 if (di->display == dpy) {
165 return di;
168 /* Did not find on list, add new entry */
169 di = Xcalloc(1, sizeof(IAExtDisplayInfo));
170 if (di == NULL)
171 return NULL;
172 di->display = dpy;
173 di->codes = XInitExtension(dpy, ia_extension_name);
174 di->next = iaExtDisplayList;
175 iaExtDisplayList = di;
176 if (di->codes) { /* if the server has the extension */
177 XESetCloseDisplay(dpy, di->codes->extension, ia_close_display);
178 XESetErrorString(dpy, di->codes->extension, ia_error_string);
180 return di;
183 #define find_display ia_find_display
184 #endif /* IA_USE_EXTUTIL */
186 /*****************************************************************************
188 * public Interactive Extension routines *
190 *****************************************************************************/
192 Bool
193 XSolarisIAQueryExtension(
194 Display *dpy
197 XExtDisplayInfo *info = find_display(dpy);
199 if (XextHasExtension(info)) {
200 return True;
201 } else {
202 return False;
207 Bool
208 XSolarisIAQueryVersion(
209 Display *dpy,
210 int *majorVersion,
211 int *minorVersion
214 XExtDisplayInfo *info = find_display(dpy);
215 xIAQueryVersionReply rep;
216 xIAQueryVersionReq *req;
218 IACheckExtension(dpy, info, False);
220 LockDisplay(dpy);
221 GetReq(IAQueryVersion, req);
222 req->reqType = info->codes->major_opcode;
223 req->IAReqType = X_IAQueryVersion;
224 if (!_XReply(dpy, (xReply *)(&rep), 0, xFalse)) {
225 UnlockDisplay(dpy);
226 SyncHandle();
227 return False;
229 *majorVersion = rep.majorVersion;
230 *minorVersion = rep.minorVersion;
231 UnlockDisplay(dpy);
232 SyncHandle();
233 return True;
237 Bool
238 XSolarisIAGetProcessInfo(
239 Display *dpy,
240 unsigned char **Pinfo,
241 CARD32 flags,
242 int *count
245 XExtDisplayInfo *info = find_display(dpy);
246 xIAGetProcessInfoReq *req;
247 xIAGetProcessInfoReply rep;
248 long length = 0;
250 IACheckExtension(dpy, info, False);
252 *Pinfo = NULL;
254 LockDisplay(dpy);
255 GetReq(IAGetProcessInfo, req);
256 req->reqType = info->codes->major_opcode;
257 req->connectionAttrType = X_IAGetProcessInfo;
258 req->flags = flags;
259 if (!_XReply(dpy, (xReply *)(&rep), 0, xFalse)) {
260 UnlockDisplay(dpy);
261 SyncHandle();
262 return False;
264 *count = rep.count;
265 *Pinfo = Xcalloc(rep.count, sizeof(ConnectionPidRec));
266 if (*Pinfo == NULL) {
267 _XEatDataWords(dpy, rep.length);
268 UnlockDisplay(dpy);
269 SyncHandle();
270 return False; /* not Success */
272 length = rep.count << 2;
273 _XRead32(dpy, (long *)(*Pinfo), length);
274 UnlockDisplay(dpy);
275 SyncHandle();
276 return True;
280 Bool
281 XSolarisIASetProcessInfo(
282 Display *dpy,
283 unsigned char *Pinfo,
284 CARD32 flags,
285 CARD32 count
288 XExtDisplayInfo *info = find_display(dpy);
289 xIASetProcessInfoReq *req;
290 unsigned long length;
292 IACheckExtension(dpy, info, False);
294 LockDisplay(dpy);
295 GetReq(IASetProcessInfo, req);
296 req->reqType = info->codes->major_opcode;
297 req->connectionAttrType = X_IASetProcessInfo;
298 req->flags = flags;
299 req->length += count;
300 req->uid = (CARD32)getuid();
301 if (flags & INTERACTIVE_INFO) {
302 length = count << 2;
303 Data32(dpy, (long *)Pinfo, length);
305 if (flags & INTERACTIVE_SETTING) {
306 length = count << 2;
307 Data32(dpy, (long *)Pinfo, length);
309 UnlockDisplay(dpy);
310 SyncHandle();
311 return True;