3 Copyright 1989, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the 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 THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 * Author: Jim Fulton, MIT The Open Group
27 * Xlib Extension-Writing Utilities
29 * This package contains utilities for writing the client API for various
30 * protocol extensions. THESE INTERFACES ARE NOT PART OF THE X STANDARD AND
31 * ARE SUBJECT TO CHANGE!
37 #include <X11/extensions/Xext.h>
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 Display* /* display */,
61 XExtCodes* /* codes */
64 Display* /* display */,
66 XExtCodes* /* codes */
69 Display* /* display */,
71 XExtCodes* /* codes */
74 Display* /* display */,
76 XExtCodes* /* codes */
79 Display* /* display */,
80 XFontStruct* /* fs */,
81 XExtCodes* /* codes */
84 Display* /* display */,
85 XFontStruct* /* fs */,
86 XExtCodes* /* codes */
89 Display* /* display */,
90 XExtCodes* /* codes */
92 Bool (*wire_to_event)(
93 Display* /* display */,
97 Status (*event_to_wire)(
98 Display* /* display */,
103 Display* /* display */,
105 XExtCodes* /* codes */,
108 char *(*error_string)(
109 Display* /* display */,
111 XExtCodes* /* codes */,
117 extern XExtensionInfo *XextCreateExtension(
120 extern void XextDestroyExtension(
121 XExtensionInfo* /* info */
123 extern XExtDisplayInfo *XextAddDisplay(
124 XExtensionInfo* /* extinfo */,
126 char* /* ext_name */,
127 XExtensionHooks* /* hooks */,
131 extern int XextRemoveDisplay(
132 XExtensionInfo* /* extinfo */,
135 extern XExtDisplayInfo *XextFindDisplay(
136 XExtensionInfo* /* extinfo */,
140 #define XextHasExtension(i) ((i) && ((i)->codes))
141 #define XextCheckExtension(dpy,i,name,val) \
142 if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; }
143 #define XextSimpleCheckExtension(dpy,i,name) \
144 if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; }
148 * helper macros to generate code that is common to all extensions; caller
149 * should prefix it with static if extension source is in one file; this
150 * could be a utility function, but have to stack 6 unused arguments for
151 * something that is called many, many times would be bad.
153 #define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \
154 XExtDisplayInfo *proc (Display *dpy) \
156 XExtDisplayInfo *dpyinfo; \
157 if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \
158 if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \
159 dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \
163 #define XEXT_FIND_DISPLAY_PROTO(proc) \
164 XExtDisplayInfo *proc(Display *dpy)
166 #define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \
167 int proc (Display *dpy, XExtCodes *codes) \
169 return XextRemoveDisplay (extinfo, dpy); \
172 #define XEXT_CLOSE_DISPLAY_PROTO(proc) \
173 int proc(Display *dpy, XExtCodes *codes)
175 #define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \
176 char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \
178 code -= codes->first_error; \
179 if (code >= 0 && code < nerr) { \
181 sprintf (tmp, "%s.%d", extname, code); \
182 XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \
188 #define XEXT_ERROR_STRING_PROTO(proc) \
189 char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n)