1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * This file is available under and governed by the GNU General Public
  27  * License version 2 only, as published by the Free Software Foundation.
  28  * However, the following notice accompanied the original version of this
  29  * file:
  30  *
  31  * $Xorg: extutil.h,v 1.3 2000/08/18 04:05:45 coskrey Exp $
  32  *
  33 Copyright 1989, 1998  The Open Group
  34 
  35 All Rights Reserved.
  36 
  37 The above copyright notice and this permission notice shall be included in
  38 all copies or substantial portions of the Software.
  39 
  40 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  41 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  42 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  43 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  44 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  45 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  46 
  47 Except as contained in this notice, the name of The Open Group shall not be
  48 used in advertising or otherwise to promote the sale, use or other dealings
  49 in this Software without prior written authorization from The Open Group.
  50  *
  51  * Author:  Jim Fulton, MIT The Open Group
  52  *
  53  *                     Xlib Extension-Writing Utilities
  54  *
  55  * This package contains utilities for writing the client API for various
  56  * protocol extensions.  THESE INTERFACES ARE NOT PART OF THE X STANDARD AND
  57  * ARE SUBJECT TO CHANGE!
  58  */
  59 /* $XFree86: xc/include/extensions/extutil.h,v 1.5 2001/01/17 17:53:20 dawes Exp $ */
  60 
  61 #if defined(__linux__) || defined(MACOSX)
  62 
  63 #ifndef _EXTUTIL_H_
  64 #define _EXTUTIL_H_
  65 
  66 /*
  67  * We need to keep a list of open displays since the Xlib display list isn't
  68  * public.  We also have to per-display info in a separate block since it isn't
  69  * stored directly in the Display structure.
  70  */
  71 typedef struct _XExtDisplayInfo {
  72     struct _XExtDisplayInfo *next;      /* keep a linked list */
  73     Display *display;                   /* which display this is */
  74     XExtCodes *codes;                   /* the extension protocol codes */
  75     XPointer data;                      /* extra data for extension to use */
  76 } XExtDisplayInfo;
  77 
  78 typedef struct _XExtensionInfo {
  79     XExtDisplayInfo *head;              /* start of list */
  80     XExtDisplayInfo *cur;               /* most recently used */
  81     int ndisplays;                      /* number of displays */
  82 } XExtensionInfo;
  83 
  84 typedef struct _XExtensionHooks {
  85     int (*create_gc)(
  86 #if NeedNestedPrototypes
  87               Display*                  /* display */,
  88               GC                        /* gc */,
  89               XExtCodes*                /* codes */
  90 #endif
  91 );
  92     int (*copy_gc)(
  93 #if NeedNestedPrototypes
  94               Display*                  /* display */,
  95               GC                        /* gc */,
  96               XExtCodes*                /* codes */
  97 #endif
  98 );
  99     int (*flush_gc)(
 100 #if NeedNestedPrototypes
 101               Display*                  /* display */,
 102               GC                        /* gc */,
 103               XExtCodes*                /* codes */
 104 #endif
 105 );
 106     int (*free_gc)(
 107 #if NeedNestedPrototypes
 108               Display*                  /* display */,
 109               GC                        /* gc */,
 110               XExtCodes*                /* codes */
 111 #endif
 112 );
 113     int (*create_font)(
 114 #if NeedNestedPrototypes
 115               Display*                  /* display */,
 116               XFontStruct*              /* fs */,
 117               XExtCodes*                /* codes */
 118 #endif
 119 );
 120     int (*free_font)(
 121 #if NeedNestedPrototypes
 122               Display*                  /* display */,
 123               XFontStruct*              /* fs */,
 124               XExtCodes*                /* codes */
 125 #endif
 126 );
 127     int (*close_display)(
 128 #if NeedNestedPrototypes
 129               Display*                  /* display */,
 130               XExtCodes*                /* codes */
 131 #endif
 132 );
 133     Bool (*wire_to_event)(
 134 #if NeedNestedPrototypes
 135                Display*                 /* display */,
 136                XEvent*                  /* re */,
 137                xEvent*                  /* event */
 138 #endif
 139 );
 140     Status (*event_to_wire)(
 141 #if NeedNestedPrototypes
 142               Display*                  /* display */,
 143               XEvent*                   /* re */,
 144               xEvent*                   /* event */
 145 #endif
 146 );
 147     int (*error)(
 148 #if NeedNestedPrototypes
 149               Display*                  /* display */,
 150               xError*                   /* err */,
 151               XExtCodes*                /* codes */,
 152               int*                      /* ret_code */
 153 #endif
 154 );
 155     char *(*error_string)(
 156 #if NeedNestedPrototypes
 157                 Display*                /* display */,
 158                 int                     /* code */,
 159                 XExtCodes*              /* codes */,
 160                 char*                   /* buffer */,
 161                 int                     /* nbytes */
 162 #endif
 163 );
 164 } XExtensionHooks;
 165 
 166 extern XExtensionInfo *XextCreateExtension(
 167 #if NeedFunctionPrototypes
 168     void
 169 #endif
 170 );
 171 extern void XextDestroyExtension(
 172 #if NeedFunctionPrototypes
 173     XExtensionInfo*     /* info */
 174 #endif
 175 );
 176 extern XExtDisplayInfo *XextAddDisplay(
 177 #if NeedFunctionPrototypes
 178     XExtensionInfo*     /* extinfo */,
 179     Display*            /* dpy */,
 180     char*               /* ext_name */,
 181     XExtensionHooks*    /* hooks */,
 182     int                 /* nevents */,
 183     XPointer            /* data */
 184 #endif
 185 );
 186 extern int XextRemoveDisplay(
 187 #if NeedFunctionPrototypes
 188     XExtensionInfo*     /* extinfo */,
 189     Display*            /* dpy */
 190 #endif
 191 );
 192 extern XExtDisplayInfo *XextFindDisplay(
 193 #if NeedFunctionPrototypes
 194     XExtensionInfo*     /* extinfo */,
 195     Display*            /* dpy */
 196 #endif
 197 );
 198 
 199 #define XextHasExtension(i) ((i) && ((i)->codes))
 200 #define XextCheckExtension(dpy,i,name,val) \
 201   if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; }
 202 #define XextSimpleCheckExtension(dpy,i,name) \
 203   if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; }
 204 
 205 
 206 /*
 207  * helper macros to generate code that is common to all extensions; caller
 208  * should prefix it with static if extension source is in one file; this
 209  * could be a utility function, but have to stack 6 unused arguments for
 210  * something that is called many, many times would be bad.
 211  */
 212 #define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \
 213 XExtDisplayInfo *proc (Display *dpy) \
 214 { \
 215     XExtDisplayInfo *dpyinfo; \
 216     if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \
 217     if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \
 218       dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \
 219     return dpyinfo; \
 220 }
 221 
 222 #define XEXT_FIND_DISPLAY_PROTO(proc) \
 223         XExtDisplayInfo *proc(Display *dpy)
 224 
 225 #define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \
 226 int proc (Display *dpy, XExtCodes *codes) \
 227 { \
 228     return XextRemoveDisplay (extinfo, dpy); \
 229 }
 230 
 231 #define XEXT_CLOSE_DISPLAY_PROTO(proc) \
 232         int proc(Display *dpy, XExtCodes *codes)
 233 
 234 #define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \
 235 char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \
 236 {  \
 237     code -= codes->first_error;  \
 238     if (code >= 0 && code < nerr) { \
 239         char tmp[256]; \
 240         sprintf (tmp, "%s.%d", extname, code); \
 241         XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \
 242         return buf; \
 243     } \
 244     return (char *)0; \
 245 }
 246 
 247 #define XEXT_ERROR_STRING_PROTO(proc) \
 248         char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n)
 249 #endif
 250 
 251 #endif /* __linux__ || MACOSX */