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
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 */
51 #include <X11/Xlibint.h>
52 #include <X11/extensions/interactive.h>
53 #include <X11/extensions/Xext.h>
54 #include <X11/extensions/XInteractive.h>
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)
67 typedef struct _IAExtDisplayInfo
{
70 struct _IAExtDisplayInfo
*next
;
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); */ \
86 #endif /* IA_USE_EXTUTIL */
88 /*****************************************************************************
90 * private utility routines *
92 *****************************************************************************/
95 static int close_display();
96 static char *error_string();
97 static /* const */ XExtensionHooks ia_extension_hooks
= {
102 NULL
, /* create_font */
103 NULL
, /* free_font */
104 close_display
, /* close_display */
105 NULL
, /* wire_to_event */
106 NULL
, /* event_to_wire */
108 error_string
, /* error_string */
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
)
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
) {
131 if (di
->display
== dpy
) {
133 prev
->next
= di
->next
;
135 iaExtDisplayList
= di
->next
;
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
) {
151 snprintf (tmp
, sizeof(tmp
), "%s.%d", ia_extension_name
, err
);
152 XGetErrorDatabaseText (dpy
, "XProtoError", tmp
, ia_error_list
[err
],
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
) {
168 /* Did not find on list, add new entry */
169 di
= Xcalloc(1, sizeof(IAExtDisplayInfo
));
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
);
183 #define find_display ia_find_display
184 #endif /* IA_USE_EXTUTIL */
186 /*****************************************************************************
188 * public Interactive Extension routines *
190 *****************************************************************************/
193 XSolarisIAQueryExtension(
197 XExtDisplayInfo
*info
= find_display(dpy
);
199 if (XextHasExtension(info
)) {
208 XSolarisIAQueryVersion(
214 XExtDisplayInfo
*info
= find_display(dpy
);
215 xIAQueryVersionReply rep
;
216 xIAQueryVersionReq
*req
;
218 IACheckExtension(dpy
, info
, False
);
221 GetReq(IAQueryVersion
, req
);
222 req
->reqType
= info
->codes
->major_opcode
;
223 req
->IAReqType
= X_IAQueryVersion
;
224 if (!_XReply(dpy
, (xReply
*)(&rep
), 0, xFalse
)) {
229 *majorVersion
= rep
.majorVersion
;
230 *minorVersion
= rep
.minorVersion
;
238 XSolarisIAGetProcessInfo(
240 unsigned char **Pinfo
,
245 XExtDisplayInfo
*info
= find_display(dpy
);
246 xIAGetProcessInfoReq
*req
;
247 xIAGetProcessInfoReply rep
;
250 IACheckExtension(dpy
, info
, False
);
255 GetReq(IAGetProcessInfo
, req
);
256 req
->reqType
= info
->codes
->major_opcode
;
257 req
->connectionAttrType
= X_IAGetProcessInfo
;
259 if (!_XReply(dpy
, (xReply
*)(&rep
), 0, xFalse
)) {
265 *Pinfo
= Xcalloc(rep
.count
, sizeof(ConnectionPidRec
));
266 if (*Pinfo
== NULL
) {
267 _XEatDataWords(dpy
, rep
.length
);
270 return False
; /* not Success */
272 length
= rep
.count
<< 2;
273 _XRead32(dpy
, (long *)(*Pinfo
), length
);
281 XSolarisIASetProcessInfo(
283 unsigned char *Pinfo
,
288 XExtDisplayInfo
*info
= find_display(dpy
);
289 xIASetProcessInfoReq
*req
;
290 unsigned long length
;
292 IACheckExtension(dpy
, info
, False
);
295 GetReq(IASetProcessInfo
, req
);
296 req
->reqType
= info
->codes
->major_opcode
;
297 req
->connectionAttrType
= X_IASetProcessInfo
;
299 req
->length
+= count
;
300 req
->uid
= (CARD32
)getuid();
301 if (flags
& INTERACTIVE_INFO
) {
303 Data32(dpy
, (long *)Pinfo
, length
);
305 if (flags
& INTERACTIVE_SETTING
) {
307 Data32(dpy
, (long *)Pinfo
, length
);