1 /* 2 * $Xorg: extutil.h,v 1.4 2001/02/09 02:03:24 xorgcvs Exp $ 3 * 4 Copyright 1989, 1998 The Open Group 5 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 10 documentation. 11 12 The above copyright notice and this permission notice shall be included in 13 all copies or substantial portions of the Software. 14 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. 21 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. 25 * 26 * Author: Jim Fulton, MIT The Open Group 27 * 28 * Xlib Extension-Writing Utilities 29 * 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! 33 */ 34 /* $XFree86: xc/include/extensions/extutil.h,v 1.9 2001/12/14 19:53:28 dawes Exp $ */ 35 36 #ifndef _EXTUTIL_H_ 37 #define _EXTUTIL_H_ 38 39 #include <X11/extensions/Xext.h> 40 41 /* 42 * We need to keep a list of open displays since the Xlib display list isn't 43 * public. We also have to per-display info in a separate block since it isn't 44 * stored directly in the Display structure. 45 */ 46 typedef struct _XExtDisplayInfo { 47 struct _XExtDisplayInfo *next; /* keep a linked list */ 48 Display *display; /* which display this is */ 49 XExtCodes *codes; /* the extension protocol codes */ 50 XPointer data; /* extra data for extension to use */ 51 } XExtDisplayInfo; 52 53 typedef struct _XExtensionInfo { 54 XExtDisplayInfo *head; /* start of list */ 55 XExtDisplayInfo *cur; /* most recently used */ 56 int ndisplays; /* number of displays */ 57 } XExtensionInfo; 58 59 typedef struct _XExtensionHooks { 60 int (*create_gc)( 61 Display* /* display */, 62 GC /* gc */, 63 XExtCodes* /* codes */ 64 ); 65 int (*copy_gc)( 66 Display* /* display */, 67 GC /* gc */, 68 XExtCodes* /* codes */ 69 ); 70 int (*flush_gc)( 71 Display* /* display */, 72 GC /* gc */, 73 XExtCodes* /* codes */ 74 ); 75 int (*free_gc)( 76 Display* /* display */, 77 GC /* gc */, 78 XExtCodes* /* codes */ 79 ); 80 int (*create_font)( 81 Display* /* display */, 82 XFontStruct* /* fs */, 83 XExtCodes* /* codes */ 84 ); 85 int (*free_font)( 86 Display* /* display */, 87 XFontStruct* /* fs */, 88 XExtCodes* /* codes */ 89 ); 90 int (*close_display)( 91 Display* /* display */, 92 XExtCodes* /* codes */ 93 ); 94 Bool (*wire_to_event)( 95 Display* /* display */, 96 XEvent* /* re */, 97 xEvent* /* event */ 98 ); 99 Status (*event_to_wire)( 100 Display* /* display */, 101 XEvent* /* re */, 102 xEvent* /* event */ 103 ); 104 int (*error)( 105 Display* /* display */, 106 xError* /* err */, 107 XExtCodes* /* codes */, 108 int* /* ret_code */ 109 ); 110 char *(*error_string)( 111 Display* /* display */, 112 int /* code */, 113 XExtCodes* /* codes */, 114 char* /* buffer */, 115 int /* nbytes */ 116 ); 117 } XExtensionHooks; 118 119 extern XExtensionInfo *XextCreateExtension( 120 void 121 ); 122 extern void XextDestroyExtension( 123 XExtensionInfo* /* info */ 124 ); 125 extern XExtDisplayInfo *XextAddDisplay( 126 XExtensionInfo* /* extinfo */, 127 Display* /* dpy */, 128 char* /* ext_name */, 129 XExtensionHooks* /* hooks */, 130 int /* nevents */, 131 XPointer /* data */ 132 ); 133 extern int XextRemoveDisplay( 134 XExtensionInfo* /* extinfo */, 135 Display* /* dpy */ 136 ); 137 extern XExtDisplayInfo *XextFindDisplay( 138 XExtensionInfo* /* extinfo */, 139 Display* /* dpy */ 140 ); 141 142 #define XextHasExtension(i) ((i) && ((i)->codes)) 143 #define XextCheckExtension(dpy,i,name,val) \ 144 if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; } 145 #define XextSimpleCheckExtension(dpy,i,name) \ 146 if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; } 147 148 149 /* 150 * helper macros to generate code that is common to all extensions; caller 151 * should prefix it with static if extension source is in one file; this 152 * could be a utility function, but have to stack 6 unused arguments for 153 * something that is called many, many times would be bad. 154 */ 155 #define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \ 156 XExtDisplayInfo *proc (Display *dpy) \ 157 { \ 158 XExtDisplayInfo *dpyinfo; \ 159 if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \ 160 if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \ 161 dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \ 162 return dpyinfo; \ 163 } 164 165 #define XEXT_FIND_DISPLAY_PROTO(proc) \ 166 XExtDisplayInfo *proc(Display *dpy) 167 168 #define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \ 169 int proc (Display *dpy, XExtCodes *codes) \ 170 { \ 171 return XextRemoveDisplay (extinfo, dpy); \ 172 } 173 174 #define XEXT_CLOSE_DISPLAY_PROTO(proc) \ 175 int proc(Display *dpy, XExtCodes *codes) 176 177 #define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \ 178 char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \ 179 { \ 180 code -= codes->first_error; \ 181 if (code >= 0 && code < nerr) { \ 182 char tmp[256]; \ 183 sprintf (tmp, "%s.%d", extname, code); \ 184 XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \ 185 return buf; \ 186 } \ 187 return (char *)0; \ 188 } 189 190 #define XEXT_ERROR_STRING_PROTO(proc) \ 191 char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n) 192 #endif 193