2 * $XConsortium: extutil.h,v 1.15 94/10/07 15:36:33 kaleb Exp $
4 Copyright (c) 1989 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
27 * Author: Jim Fulton, MIT X Consortium
29 * Xlib Extension-Writing Utilities
31 * This package contains utilities for writing the client API for various
32 * protocol extensions. THESE INTERFACES ARE NOT PART OF THE X STANDARD AND
33 * ARE SUBJECT TO CHANGE!
40 * We need to keep a list of open displays since the Xlib display list isn't
41 * public. We also have to per-display info in a separate block since it isn't
42 * stored directly in the Display structure.
44 typedef struct _XExtDisplayInfo {
45 struct _XExtDisplayInfo *next; /* keep a linked list */
46 Display *display; /* which display this is */
47 XExtCodes *codes; /* the extension protocol codes */
48 XPointer data; /* extra data for extension to use */
51 typedef struct _XExtensionInfo {
52 XExtDisplayInfo *head; /* start of list */
53 XExtDisplayInfo *cur; /* most recently used */
54 int ndisplays; /* number of displays */
57 typedef struct _XExtensionHooks {
59 #if NeedNestedPrototypes
60 Display* /* display */,
62 XExtCodes* /* codes */
66 #if NeedNestedPrototypes
67 Display* /* display */,
69 XExtCodes* /* codes */
73 #if NeedNestedPrototypes
74 Display* /* display */,
76 XExtCodes* /* codes */
80 #if NeedNestedPrototypes
81 Display* /* display */,
83 XExtCodes* /* codes */
87 #if NeedNestedPrototypes
88 Display* /* display */,
89 XFontStruct* /* fs */,
90 XExtCodes* /* codes */
94 #if NeedNestedPrototypes
95 Display* /* display */,
96 XFontStruct* /* fs */,
97 XExtCodes* /* codes */
100 int (*close_display)(
101 #if NeedNestedPrototypes
102 Display* /* display */,
103 XExtCodes* /* codes */
106 Bool (*wire_to_event)(
107 #if NeedNestedPrototypes
108 Display* /* display */,
113 Status (*event_to_wire)(
114 #if NeedNestedPrototypes
115 Display* /* display */,
121 #if NeedNestedPrototypes
122 Display* /* display */,
124 XExtCodes* /* codes */,
128 char *(*error_string)(
129 #if NeedNestedPrototypes
130 Display* /* display */,
132 XExtCodes* /* codes */,
139 extern XExtensionInfo *XextCreateExtension(
140 #if NeedFunctionPrototypes
144 extern void XextDestroyExtension(
145 #if NeedFunctionPrototypes
146 XExtensionInfo* /* info */
149 extern XExtDisplayInfo *XextAddDisplay(
150 #if NeedFunctionPrototypes
151 XExtensionInfo* /* extinfo */,
153 char* /* ext_name */,
154 XExtensionHooks* /* hooks */,
159 extern int XextRemoveDisplay(
160 #if NeedFunctionPrototypes
161 XExtensionInfo* /* extinfo */,
165 extern XExtDisplayInfo *XextFindDisplay(
166 #if NeedFunctionPrototypes
167 XExtensionInfo* /* extinfo */,
172 #define XextHasExtension(i) ((i) && ((i)->codes))
173 #define XextCheckExtension(dpy,i,name,val) \
174 if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; }
175 #define XextSimpleCheckExtension(dpy,i,name) \
176 if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; }
180 * helper macros to generate code that is common to all extensions; caller
181 * should prefix it with static if extension source is in one file; this
182 * could be a utility function, but have to stack 6 unused arguments for
183 * something that is called many, many times would be bad.
185 #define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \
186 XExtDisplayInfo *proc (dpy) \
187 register Display *dpy; \
189 XExtDisplayInfo *dpyinfo; \
190 if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \
191 if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \
192 dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \
196 #define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \
197 int proc (dpy, codes) \
201 return XextRemoveDisplay (extinfo, dpy); \
204 #define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \
205 char *proc (dpy, code, codes, buf, n) \
212 code -= codes->first_error; \
213 if (code >= 0 && code < nerr) { \
215 sprintf (tmp, "%s.%d", extname, code); \
216 XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \