2 * $Xorg: extutil.h,v 1.4 2001/02/09 02:03:24 xorgcvs Exp $
4 Copyright 1989, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the 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 THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
26 * Author: Jim Fulton, MIT The Open Group
28 * Xlib Extension-Writing Utilities
30 * This package contains utilities for writing the client API for various
31 * protocol extensions. THESE INTERFACES ARE NOT PART OF THE X STANDARD AND
32 * ARE SUBJECT TO CHANGE!
34 /* $XFree86: xc/include/extensions/extutil.h,v 1.9 2001/12/14 19:53:28 dawes Exp $ */
39 #include "SDL_stdinc.h" /* For portable string functions */
44 * We need to keep a list of open displays since the Xlib display list isn't
45 * public. We also have to per-display info in a separate block since it isn't
46 * stored directly in the Display structure.
48 typedef struct _XExtDisplayInfo {
49 struct _XExtDisplayInfo *next; /* keep a linked list */
50 Display *display; /* which display this is */
51 XExtCodes *codes; /* the extension protocol codes */
52 XPointer data; /* extra data for extension to use */
55 typedef struct _XExtensionInfo {
56 XExtDisplayInfo *head; /* start of list */
57 XExtDisplayInfo *cur; /* most recently used */
58 int ndisplays; /* number of displays */
61 typedef struct _XExtensionHooks {
63 #if NeedNestedPrototypes
64 Display* /* display */,
66 XExtCodes* /* codes */
70 #if NeedNestedPrototypes
71 Display* /* display */,
73 XExtCodes* /* codes */
77 #if NeedNestedPrototypes
78 Display* /* display */,
80 XExtCodes* /* codes */
84 #if NeedNestedPrototypes
85 Display* /* display */,
87 XExtCodes* /* codes */
91 #if NeedNestedPrototypes
92 Display* /* display */,
93 XFontStruct* /* fs */,
94 XExtCodes* /* codes */
98 #if NeedNestedPrototypes
99 Display* /* display */,
100 XFontStruct* /* fs */,
101 XExtCodes* /* codes */
104 int (*close_display)(
105 #if NeedNestedPrototypes
106 Display* /* display */,
107 XExtCodes* /* codes */
110 Bool (*wire_to_event)(
111 #if NeedNestedPrototypes
112 Display* /* display */,
117 Status (*event_to_wire)(
118 #if NeedNestedPrototypes
119 Display* /* display */,
125 #if NeedNestedPrototypes
126 Display* /* display */,
128 XExtCodes* /* codes */,
132 char *(*error_string)(
133 #if NeedNestedPrototypes
134 Display* /* display */,
136 XExtCodes* /* codes */,
143 extern XExtensionInfo *XextCreateExtension(
144 #if NeedFunctionPrototypes
148 extern void XextDestroyExtension(
149 #if NeedFunctionPrototypes
150 XExtensionInfo* /* info */
153 extern XExtDisplayInfo *XextAddDisplay(
154 #if NeedFunctionPrototypes
155 XExtensionInfo* /* extinfo */,
157 char* /* ext_name */,
158 XExtensionHooks* /* hooks */,
163 extern int XextRemoveDisplay(
164 #if NeedFunctionPrototypes
165 XExtensionInfo* /* extinfo */,
169 extern XExtDisplayInfo *XextFindDisplay(
170 #if NeedFunctionPrototypes
171 XExtensionInfo* /* extinfo */,
176 #define XextHasExtension(i) ((i) && ((i)->codes))
177 #define XextCheckExtension(dpy,i,name,val) \
178 if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; }
179 #define XextSimpleCheckExtension(dpy,i,name) \
180 if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; }
184 * helper macros to generate code that is common to all extensions; caller
185 * should prefix it with static if extension source is in one file; this
186 * could be a utility function, but have to stack 6 unused arguments for
187 * something that is called many, many times would be bad.
189 #define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \
190 XExtDisplayInfo *proc (Display *dpy) \
192 XExtDisplayInfo *dpyinfo; \
193 if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \
194 if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \
195 dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \
199 #define XEXT_FIND_DISPLAY_PROTO(proc) \
200 XExtDisplayInfo *proc(Display *dpy)
202 #define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \
203 int proc (Display *dpy, XExtCodes *codes) \
205 return XextRemoveDisplay (extinfo, dpy); \
208 #define XEXT_CLOSE_DISPLAY_PROTO(proc) \
209 int proc(Display *dpy, XExtCodes *codes)
211 #define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \
212 char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \
214 code -= codes->first_error; \
215 if (code >= 0 && code < nerr) { \
217 SDL_snprintf (tmp, SDL_arraysize(tmp), "%s.%d", extname, code); \
218 XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \
224 #define XEXT_ERROR_STRING_PROTO(proc) \
225 char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n)