1 /* 2 * 3 Copyright 1989, 1998 The Open Group 4 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 9 documentation. 10 11 The above copyright notice and this permission notice shall be included in 12 all copies or substantial portions of the Software. 13 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. 20 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. 24 * 25 * Author: Jim Fulton, MIT The Open Group 26 * 27 * Xlib Extension-Writing Utilities 28 * 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! 32 */ 33 34 #ifndef _EXTUTIL_H_ 35 #define _EXTUTIL_H_ 36 37 #include <X11/extensions/Xext.h> 38 39 /* 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. 43 */ 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 */ 49 } XExtDisplayInfo; 50 51 typedef struct _XExtensionInfo { 52 XExtDisplayInfo *head; /* start of list */ 53 XExtDisplayInfo *cur; /* most recently used */ 54 int ndisplays; /* number of displays */ 55 } XExtensionInfo; 56 57 typedef struct _XExtensionHooks { 58 int (*create_gc)( 59 Display* /* display */, 60 GC /* gc */, 61 XExtCodes* /* codes */ 62 ); 63 int (*copy_gc)( 64 Display* /* display */, 65 GC /* gc */, 66 XExtCodes* /* codes */ 67 ); 68 int (*flush_gc)( 69 Display* /* display */, 70 GC /* gc */, 71 XExtCodes* /* codes */ 72 ); 73 int (*free_gc)( 74 Display* /* display */, 75 GC /* gc */, 76 XExtCodes* /* codes */ 77 ); 78 int (*create_font)( 79 Display* /* display */, 80 XFontStruct* /* fs */, 81 XExtCodes* /* codes */ 82 ); 83 int (*free_font)( 84 Display* /* display */, 85 XFontStruct* /* fs */, 86 XExtCodes* /* codes */ 87 ); 88 int (*close_display)( 89 Display* /* display */, 90 XExtCodes* /* codes */ 91 ); 92 Bool (*wire_to_event)( 93 Display* /* display */, 94 XEvent* /* re */, 95 xEvent* /* event */ 96 ); 97 Status (*event_to_wire)( 98 Display* /* display */, 99 XEvent* /* re */, 100 xEvent* /* event */ 101 ); 102 int (*error)( 103 Display* /* display */, 104 xError* /* err */, 105 XExtCodes* /* codes */, 106 int* /* ret_code */ 107 ); 108 char *(*error_string)( 109 Display* /* display */, 110 int /* code */, 111 XExtCodes* /* codes */, 112 char* /* buffer */, 113 int /* nbytes */ 114 ); 115 } XExtensionHooks; 116 117 extern XExtensionInfo *XextCreateExtension( 118 void 119 ); 120 extern void XextDestroyExtension( 121 XExtensionInfo* /* info */ 122 ); 123 extern XExtDisplayInfo *XextAddDisplay( 124 XExtensionInfo* /* extinfo */, 125 Display* /* dpy */, 126 _Xconst char* /* ext_name */, 127 XExtensionHooks* /* hooks */, 128 int /* nevents */, 129 XPointer /* data */ 130 ); 131 extern int XextRemoveDisplay( 132 XExtensionInfo* /* extinfo */, 133 Display* /* dpy */ 134 ); 135 extern XExtDisplayInfo *XextFindDisplay( 136 XExtensionInfo* /* extinfo */, 137 Display* /* dpy */ 138 ); 139 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; } 145 146 147 /* 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. 152 */ 153 #define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \ 154 XExtDisplayInfo *proc (Display *dpy) \ 155 { \ 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); \ 160 return dpyinfo; \ 161 } 162 163 #define XEXT_FIND_DISPLAY_PROTO(proc) \ 164 XExtDisplayInfo *proc(Display *dpy) 165 166 #define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \ 167 int proc (Display *dpy, XExtCodes *codes) \ 168 { \ 169 return XextRemoveDisplay (extinfo, dpy); \ 170 } 171 172 #define XEXT_CLOSE_DISPLAY_PROTO(proc) \ 173 int proc(Display *dpy, XExtCodes *codes) 174 175 #define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \ 176 char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \ 177 { \ 178 code -= codes->first_error; \ 179 if (code >= 0 && code < nerr) { \ 180 char tmp[256]; \ 181 sprintf (tmp, "%s.%d", extname, code); \ 182 XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \ 183 return buf; \ 184 } \ 185 return (char *)0; \ 186 } 187 188 #define XEXT_ERROR_STRING_PROTO(proc) \ 189 char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n) 190 #endif 191