Home | History | Annotate | Line # | Download | only in X11
      1 
      2 /*
      3 
      4 Copyright 1984, 1985, 1987, 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
     13 in all copies or substantial portions of the Software.
     14 
     15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     16 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     18 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
     19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     21 OTHER DEALINGS IN THE SOFTWARE.
     22 
     23 Except as contained in this notice, the name of The Open Group shall
     24 not be used in advertising or otherwise to promote the sale, use or
     25 other dealings in this Software without prior written authorization
     26 from The Open Group.
     27 
     28 */
     29 
     30 #ifndef _X11_XLIBINT_H_
     31 #define _X11_XLIBINT_H_ 1
     32 
     33 /*
     34  *	Xlibint.h - Header definition and support file for the internal
     35  *	support routines used by the C subroutine interface
     36  *	library (Xlib) to the X Window System.
     37  *
     38  *	Warning, there be dragons here....
     39  */
     40 
     41 #include <stdint.h>
     42 #include <X11/Xlib.h>
     43 #include <X11/Xproto.h>		/* to declare xEvent */
     44 #include <X11/XlibConf.h>	/* for configured options like XTHREADS */
     45 
     46 #ifdef XTHREADS
     47 #include <X11/Xthreads.h>
     48 #ifdef _WIN32
     49 #undef CreateWindow
     50 #endif
     51 #endif
     52 
     53 /* The Xlib structs are full of implicit padding to properly align members.
     54    We can't clean that up without breaking ABI, so tell clang not to bother
     55    complaining about it. */
     56 #ifdef __clang__
     57 #pragma clang diagnostic push
     58 #pragma clang diagnostic ignored "-Wpadded"
     59 #endif
     60 
     61 #ifdef WIN32
     62 #define _XFlush _XFlushIt
     63 #endif
     64 
     65 struct _XGC
     66 {
     67     XExtData *ext_data;	/* hook for extension to hang data */
     68     GContext gid;	/* protocol ID for graphics context */
     69     Bool rects;		/* boolean: TRUE if clipmask is list of rectangles */
     70     Bool dashes;	/* boolean: TRUE if dash-list is really a list */
     71     unsigned long dirty;/* cache dirty bits */
     72     XGCValues values;	/* shadow structure of values */
     73 };
     74 
     75 struct _XDisplay
     76 {
     77 	XExtData *ext_data;	/* hook for extension to hang data */
     78 	struct _XFreeFuncs *free_funcs; /* internal free functions */
     79 	int fd;			/* Network socket. */
     80 	int conn_checker;         /* ugly thing used by _XEventsQueued */
     81 	int proto_major_version;/* maj. version of server's X protocol */
     82 	int proto_minor_version;/* minor version of server's X protocol */
     83 	char *vendor;		/* vendor of the server hardware */
     84         XID resource_base;	/* resource ID base */
     85 	XID resource_mask;	/* resource ID mask bits */
     86 	XID resource_id;	/* allocator current ID */
     87 	int resource_shift;	/* allocator shift to correct bits */
     88 	XID (*resource_alloc)(	/* allocator function */
     89 		struct _XDisplay*
     90 		);
     91 	int byte_order;		/* screen byte order, LSBFirst, MSBFirst */
     92 	int bitmap_unit;	/* padding and data requirements */
     93 	int bitmap_pad;		/* padding requirements on bitmaps */
     94 	int bitmap_bit_order;	/* LeastSignificant or MostSignificant */
     95 	int nformats;		/* number of pixmap formats in list */
     96 	ScreenFormat *pixmap_format;	/* pixmap format list */
     97 	int vnumber;		/* Xlib's X protocol version number. */
     98 	int release;		/* release of the server */
     99 	struct _XSQEvent *head, *tail;	/* Input event queue. */
    100 	int qlen;		/* Length of input event queue */
    101 	unsigned long last_request_read; /* seq number of last event read */
    102 	unsigned long request;	/* sequence number of last request. */
    103 	char *last_req;		/* beginning of last request, or dummy */
    104 	char *buffer;		/* Output buffer starting address. */
    105 	char *bufptr;		/* Output buffer index pointer. */
    106 	char *bufmax;		/* Output buffer maximum+1 address. */
    107 	unsigned max_request_size; /* maximum number 32 bit words in request*/
    108 	struct _XrmHashBucketRec *db;
    109 	int (*synchandler)(	/* Synchronization handler */
    110 		struct _XDisplay*
    111 		);
    112 	char *display_name;	/* "host:display" string used on this connect*/
    113 	int default_screen;	/* default screen for operations */
    114 	int nscreens;		/* number of screens on this server*/
    115 	Screen *screens;	/* pointer to list of screens */
    116 	unsigned long motion_buffer;	/* size of motion buffer */
    117 	volatile unsigned long flags;	   /* internal connection flags */
    118 	int min_keycode;	/* minimum defined keycode */
    119 	int max_keycode;	/* maximum defined keycode */
    120 	KeySym *keysyms;	/* This server's keysyms */
    121 	XModifierKeymap *modifiermap;	/* This server's modifier keymap */
    122 	int keysyms_per_keycode;/* number of rows */
    123 	char *xdefaults;	/* contents of defaults from server */
    124 	char *scratch_buffer;	/* place to hang scratch buffer */
    125 	unsigned long scratch_length;	/* length of scratch buffer */
    126 	int ext_number;		/* extension number on this display */
    127 	struct _XExten *ext_procs; /* extensions initialized on this display */
    128 	/*
    129 	 * the following can be fixed size, as the protocol defines how
    130 	 * much address space is available.
    131 	 * While this could be done using the extension vector, there
    132 	 * may be MANY events processed, so a search through the extension
    133 	 * list to find the right procedure for each event might be
    134 	 * expensive if many extensions are being used.
    135 	 */
    136 	Bool (*event_vec[128])(	/* vector for wire to event */
    137 		Display *	/* dpy */,
    138 		XEvent *	/* re */,
    139 		xEvent *	/* event */
    140 		);
    141 	Status (*wire_vec[128])( /* vector for event to wire */
    142 		Display *	/* dpy */,
    143 		XEvent *	/* re */,
    144 		xEvent *	/* event */
    145 		);
    146 	KeySym lock_meaning;	   /* for XLookupString */
    147 	struct _XLockInfo *lock;   /* multi-thread state, display lock */
    148 	struct _XInternalAsync *async_handlers; /* for internal async */
    149 	unsigned long bigreq_size; /* max size of big requests */
    150 	struct _XLockPtrs *lock_fns; /* pointers to threads functions */
    151 	void (*idlist_alloc)(	   /* XID list allocator function */
    152 		Display *	/* dpy */,
    153 		XID *		/* ids */,
    154 		int		/* count */
    155 		);
    156 	/* things above this line should not move, for binary compatibility */
    157 	struct _XKeytrans *key_bindings; /* for XLookupString */
    158 	Font cursor_font;	   /* for XCreateFontCursor */
    159 	struct _XDisplayAtoms *atoms; /* for XInternAtom */
    160 	unsigned int mode_switch;  /* keyboard group modifiers */
    161 	unsigned int num_lock;  /* keyboard numlock modifiers */
    162 	struct _XContextDB *context_db; /* context database */
    163 	Bool (**error_vec)(	/* vector for wire to error */
    164 		Display     *	/* display */,
    165 		XErrorEvent *	/* he */,
    166 		xError      *	/* we */
    167 		);
    168 	/*
    169 	 * Xcms information
    170 	 */
    171 	struct {
    172 	   XPointer defaultCCCs;  /* pointer to an array of default XcmsCCC */
    173 	   XPointer clientCmaps;  /* pointer to linked list of XcmsCmapRec */
    174 	   XPointer perVisualIntensityMaps;
    175 				  /* linked list of XcmsIntensityMap */
    176 	} cms;
    177 	struct _XIMFilter *im_filters;
    178 	struct _XSQEvent *qfree; /* unallocated event queue elements */
    179 	unsigned long next_event_serial_num; /* inserted into next queue elt */
    180 	struct _XExten *flushes; /* Flush hooks */
    181 	struct _XConnectionInfo *im_fd_info; /* _XRegisterInternalConnection */
    182 	int im_fd_length;	/* number of im_fd_info */
    183 	struct _XConnWatchInfo *conn_watchers; /* XAddConnectionWatch */
    184 	int watcher_count;	/* number of conn_watchers */
    185 	XPointer filedes;	/* struct pollfd cache for _XWaitForReadable */
    186 	int (*savedsynchandler)( /* user synchandler when Xlib usurps */
    187 		Display *	/* dpy */
    188 		);
    189 	XID resource_max;	/* allocator max ID */
    190 	int xcmisc_opcode;	/* major opcode for XC-MISC */
    191 	struct _XkbInfoRec *xkb_info; /* XKB info */
    192 	struct _XtransConnInfo *trans_conn; /* transport connection object */
    193 	struct _X11XCBPrivate *xcb; /* XCB glue private data */
    194 
    195 	/* Generic event cookie handling */
    196 	unsigned int next_cookie; /* next event cookie */
    197 	/* vector for wire to generic event, index is (extension - 128) */
    198 	Bool (*generic_event_vec[128])(
    199 		Display *	/* dpy */,
    200 		XGenericEventCookie *	/* Xlib event */,
    201 		xEvent *	/* wire event */);
    202 	/* vector for event copy, index is (extension - 128) */
    203 	Bool (*generic_event_copy_vec[128])(
    204 		Display *	/* dpy */,
    205 		XGenericEventCookie *	/* in */,
    206 		XGenericEventCookie *   /* out*/);
    207 	void *cookiejar;  /* cookie events returned but not claimed */
    208 #ifndef LONG64
    209 	unsigned long last_request_read_upper32bit;
    210 	unsigned long request_upper32bit;
    211 #endif
    212 
    213 	struct _XErrorThreadInfo *error_threads;
    214 
    215 	XIOErrorExitHandler exit_handler;
    216 	void *exit_handler_data;
    217 	CARD32 in_ifevent;
    218 #ifdef XTHREADS
    219 	xthread_t ifevent_thread;
    220 #endif
    221 };
    222 
    223 #define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
    224 
    225 /*
    226  * access "last_request_read" and "request" with 64bit
    227  * warning: the value argument of the SET-macros must not
    228  * have any side-effects because it may get called twice.
    229  */
    230 #ifndef LONG64
    231 /* accessors for 32-bit unsigned long */
    232 
    233 #define X_DPY_GET_REQUEST(dpy) \
    234     ( \
    235         ((uint64_t)(((struct _XDisplay*)dpy)->request)) \
    236 	+ (((uint64_t)(((struct _XDisplay*)dpy)->request_upper32bit)) << 32) \
    237     )
    238 
    239 #define X_DPY_SET_REQUEST(dpy, value) \
    240     ( \
    241         (((struct _XDisplay*)dpy)->request = \
    242             (value) & 0xFFFFFFFFUL), \
    243         (((struct _XDisplay*)dpy)->request_upper32bit = \
    244             ((uint64_t)(value)) >> 32), \
    245 	(void)0 /* don't use the result */ \
    246     )
    247 
    248 #define X_DPY_GET_LAST_REQUEST_READ(dpy) \
    249     ( \
    250         ((uint64_t)(((struct _XDisplay*)dpy)->last_request_read)) \
    251         + ( \
    252             ((uint64_t)( \
    253                 ((struct _XDisplay*)dpy)->last_request_read_upper32bit \
    254             )) << 32 \
    255         ) \
    256     )
    257 
    258 #define X_DPY_SET_LAST_REQUEST_READ(dpy, value) \
    259     ( \
    260         (((struct _XDisplay*)dpy)->last_request_read = \
    261             (value) & 0xFFFFFFFFUL), \
    262         (((struct _XDisplay*)dpy)->last_request_read_upper32bit = \
    263             ((uint64_t)(value)) >> 32), \
    264 	(void)0 /* don't use the result */ \
    265     )
    266 
    267 /*
    268  * widen a 32-bit sequence number to a 64 sequence number.
    269  * This macro makes the following assumptions:
    270  * - ulseq refers to a sequence that has already been sent
    271  * - ulseq means the most recent possible sequence number
    272  *   with these lower 32 bits.
    273  *
    274  * The following optimization is used:
    275  * The comparison result is taken a 0 or 1 to avoid a branch.
    276  */
    277 #define X_DPY_WIDEN_UNSIGNED_LONG_SEQ(dpy, ulseq) \
    278     ( \
    279         ((uint64_t)ulseq) \
    280         + \
    281         (( \
    282             ((uint64_t)(((struct _XDisplay*)dpy)->request_upper32bit)) \
    283             - (uint64_t)( \
    284                 (ulseq) > (((struct _XDisplay*)dpy)->request) \
    285 	    ) \
    286         ) << 32) \
    287     )
    288 
    289 #define X_DPY_REQUEST_INCREMENT(dpy) \
    290     ( \
    291         ((struct _XDisplay*)dpy)->request++, \
    292         ( \
    293             (((struct _XDisplay*)dpy)->request == 0) ? ( \
    294                 ((struct _XDisplay*)dpy)->request_upper32bit++ \
    295 	    ) : 0 \
    296         ), \
    297 	(void)0 /* don't use the result */ \
    298     )
    299 
    300 
    301 #define X_DPY_REQUEST_DECREMENT(dpy) \
    302     ( \
    303 	( \
    304             (((struct _XDisplay*)dpy)->request == 0) ? (\
    305                 ((struct _XDisplay*)dpy)->request--, /* wrap */ \
    306                 ((struct _XDisplay*)dpy)->request_upper32bit-- \
    307             ) : ( \
    308                 ((struct _XDisplay*)dpy)->request-- \
    309             ) \
    310 	), \
    311 	(void)0 /* don't use the result */ \
    312     )
    313 
    314 #else
    315 /* accessors for 64-bit unsigned long */
    316 #define X_DPY_GET_REQUEST(dpy) \
    317     (((struct _XDisplay*)dpy)->request)
    318 #define X_DPY_SET_REQUEST(dpy, value) \
    319     ((struct _XDisplay*)dpy)->request = (value)
    320 
    321 #define X_DPY_GET_LAST_REQUEST_READ(dpy) \
    322     (((struct _XDisplay*)dpy)->last_request_read)
    323 #define X_DPY_SET_LAST_REQUEST_READ(dpy, value) \
    324     ((struct _XDisplay*)dpy)->last_request_read = (value)
    325 
    326 #define X_DPY_WIDEN_UNSIGNED_LONG_SEQ(dpy, ulseq) ulseq
    327 
    328 #define X_DPY_REQUEST_INCREMENT(dpy) ((struct _XDisplay*)dpy)->request++
    329 #define X_DPY_REQUEST_DECREMENT(dpy) ((struct _XDisplay*)dpy)->request--
    330 #endif
    331 
    332 
    333 #ifndef _XEVENT_
    334 /*
    335  * _QEvent datatype for use in input queueing.
    336  */
    337 typedef struct _XSQEvent
    338 {
    339     struct _XSQEvent *next;
    340     XEvent event;
    341     unsigned long qserial_num;	/* so multi-threaded code can find new ones */
    342 } _XQEvent;
    343 #endif
    344 
    345 #include <X11/Xproto.h>
    346 #include <errno.h>
    347 #define _XBCOPYFUNC _Xbcopy
    348 #include <X11/Xfuncs.h>
    349 #include <X11/Xosdefs.h>
    350 
    351 /* Utek leaves kernel macros around in include files (bleah) */
    352 #ifdef dirty
    353 #undef dirty
    354 #endif
    355 
    356 #include <stdlib.h>
    357 #include <string.h>
    358 
    359 #include <X11/Xfuncproto.h>
    360 
    361 _XFUNCPROTOBEGIN
    362 
    363 /*
    364  * The following definitions can be used for locking requests in multi-threaded
    365  * address spaces.
    366  */
    367 #ifdef XTHREADS
    368 /* Author: Stephen Gildea, MIT X Consortium
    369  *
    370  * declarations for C Threads locking
    371  */
    372 
    373 typedef struct _LockInfoRec *LockInfoPtr;
    374 
    375 /* interfaces for locking.c */
    376 struct _XLockPtrs {
    377     /* used by all, including extensions; do not move */
    378     void (*lock_display)(
    379 		Display *dpy
    380 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
    381 		, char *file
    382 		, int line
    383 #endif
    384 	);
    385     void (*unlock_display)(
    386 		Display *dpy
    387 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
    388 		, char *file
    389 		, int line
    390 #endif
    391 	);
    392 };
    393 
    394 #if defined(WIN32) && !defined(_XLIBINT_)
    395 #define _XCreateMutex_fn (*_XCreateMutex_fn_p)
    396 #define _XFreeMutex_fn (*_XFreeMutex_fn_p)
    397 #define _XLockMutex_fn (*_XLockMutex_fn_p)
    398 #define _XUnlockMutex_fn (*_XUnlockMutex_fn_p)
    399 #define _Xglobal_lock (*_Xglobal_lock_p)
    400 #endif
    401 
    402 /* in XlibInt.c */
    403 extern void (*_XCreateMutex_fn)(
    404     LockInfoPtr /* lock */
    405 );
    406 extern void (*_XFreeMutex_fn)(
    407     LockInfoPtr /* lock */
    408 );
    409 extern void (*_XLockMutex_fn)(
    410     LockInfoPtr	/* lock */
    411 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
    412     , char * /* file */
    413     , int /* line */
    414 #endif
    415 );
    416 extern void (*_XUnlockMutex_fn)(
    417     LockInfoPtr	/* lock */
    418 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
    419     , char * /* file */
    420     , int /* line */
    421 #endif
    422 );
    423 
    424 extern LockInfoPtr _Xglobal_lock;
    425 
    426 #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
    427 #define LockDisplay(d)	     if ((d)->lock_fns) (*(d)->lock_fns->lock_display)((d),__FILE__,__LINE__)
    428 #define UnlockDisplay(d)     if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)((d),__FILE__,__LINE__)
    429 #define _XLockMutex(lock)		if (_XLockMutex_fn) (*_XLockMutex_fn)(lock,__FILE__,__LINE__)
    430 #define _XUnlockMutex(lock)	if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock,__FILE__,__LINE__)
    431 #else
    432 /* used everywhere, so must be fast if not using threads */
    433 #define LockDisplay(d)	     if ((d)->lock_fns) (*(d)->lock_fns->lock_display)(d)
    434 #define UnlockDisplay(d)     if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)(d)
    435 #define _XLockMutex(lock)		if (_XLockMutex_fn) (*_XLockMutex_fn)(lock)
    436 #define _XUnlockMutex(lock)	if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock)
    437 #endif
    438 #define _XCreateMutex(lock)	if (_XCreateMutex_fn) (*_XCreateMutex_fn)(lock)
    439 #define _XFreeMutex(lock)	if (_XFreeMutex_fn) (*_XFreeMutex_fn)(lock)
    440 
    441 #else /* XTHREADS */
    442 #define LockDisplay(dis)
    443 #define _XLockMutex(lock)
    444 #define _XUnlockMutex(lock)
    445 #define UnlockDisplay(dis)
    446 #define _XCreateMutex(lock)
    447 #define _XFreeMutex(lock)
    448 #endif
    449 
    450 #define Xfree(ptr) free((ptr))
    451 
    452 /*
    453  * Note that some machines do not return a valid pointer for malloc(0), in
    454  * which case we provide an alternate under the control of the
    455  * define MALLOC_0_RETURNS_NULL.  This is necessary because some
    456  * Xlib code expects malloc(0) to return a valid pointer to storage.
    457  */
    458 #if defined(MALLOC_0_RETURNS_NULL) || defined(__clang_analyzer__)
    459 
    460 # define Xmalloc(size) malloc((size_t)((size) == 0 ? 1 : (size)))
    461 # define Xrealloc(ptr, size) realloc((ptr), (size_t)((size) == 0 ? 1 : (size)))
    462 # define Xcalloc(nelem, elsize) calloc((size_t)((nelem) == 0 ? 1 : (nelem)), (size_t)(elsize))
    463 
    464 #else
    465 
    466 # define Xmalloc(size) malloc((size_t)(size))
    467 # define Xrealloc(ptr, size) realloc((ptr), (size_t)(size))
    468 # define Xcalloc(nelem, elsize) calloc((size_t)(nelem), (size_t)(elsize))
    469 
    470 #endif
    471 
    472 #include <stddef.h>
    473 
    474 #define LOCKED 1
    475 #define UNLOCKED 0
    476 
    477 #ifndef BUFSIZE
    478 #define BUFSIZE 2048			/* X output buffer size. */
    479 #endif
    480 #ifndef PTSPERBATCH
    481 #define PTSPERBATCH 1024		/* point batching */
    482 #endif
    483 #ifndef WLNSPERBATCH
    484 #define WLNSPERBATCH 50			/* wide line batching */
    485 #endif
    486 #ifndef ZLNSPERBATCH
    487 #define ZLNSPERBATCH 1024		/* thin line batching */
    488 #endif
    489 #ifndef WRCTSPERBATCH
    490 #define WRCTSPERBATCH 10		/* wide line rectangle batching */
    491 #endif
    492 #ifndef ZRCTSPERBATCH
    493 #define ZRCTSPERBATCH 256		/* thin line rectangle batching */
    494 #endif
    495 #ifndef FRCTSPERBATCH
    496 #define FRCTSPERBATCH 256		/* filled rectangle batching */
    497 #endif
    498 #ifndef FARCSPERBATCH
    499 #define FARCSPERBATCH 256		/* filled arc batching */
    500 #endif
    501 #ifndef CURSORFONT
    502 #define CURSORFONT "cursor"		/* standard cursor fonts */
    503 #endif
    504 
    505 /*
    506  * Display flags
    507  */
    508 #define XlibDisplayIOError	(1L << 0)
    509 #define XlibDisplayClosing	(1L << 1)
    510 #define XlibDisplayNoXkb	(1L << 2)
    511 #define XlibDisplayPrivSync	(1L << 3)
    512 #define XlibDisplayProcConni	(1L << 4) /* in _XProcessInternalConnection */
    513 #define XlibDisplayReadEvents	(1L << 5) /* in _XReadEvents */
    514 #define XlibDisplayReply	(1L << 5) /* in _XReply */
    515 #define XlibDisplayWriting	(1L << 6) /* in _XFlushInt, _XSend */
    516 #define XlibDisplayDfltRMDB     (1L << 7) /* mark if RM db from XGetDefault */
    517 
    518 /*
    519  * X Protocol packetizing macros.
    520  */
    521 
    522 /* Leftover from CRAY support - was defined empty on all non-Cray systems */
    523 #define WORD64ALIGN
    524 
    525 /**
    526  * Return a len-sized request buffer for the request type. This function may
    527  * flush the output queue.
    528  *
    529  * @param dpy The display connection
    530  * @param type The request type
    531  * @param len Length of the request in bytes
    532  *
    533  * @returns A pointer to the request buffer with a few default values
    534  * initialized.
    535  */
    536 extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len);
    537 
    538 /* GetReqSized is the same as GetReq but allows the caller to specify the
    539  * size in bytes. 'sz' must be a multiple of 4! */
    540 
    541 #define GetReqSized(name, sz, req) \
    542 	req = (x##name##Req *) _XGetRequest(dpy, X_##name, sz)
    543 
    544 /*
    545  * GetReq - Get the next available X request packet in the buffer and
    546  * return it.
    547  *
    548  * "name" is the name of the request, e.g. CreatePixmap, OpenFont, etc.
    549  * "req" is the name of the request pointer.
    550  *
    551  */
    552 
    553 #define GetReq(name, req) \
    554 	GetReqSized(name, SIZEOF(x##name##Req), req)
    555 
    556 /* GetReqExtra is the same as GetReq, but allocates "n" additional
    557    bytes after the request. "n" must be a multiple of 4!  */
    558 
    559 #define GetReqExtra(name, n, req) \
    560         GetReqSized(name, SIZEOF(x##name##Req) + n, req)
    561 
    562 /*
    563  * GetResReq is for those requests that have a resource ID
    564  * (Window, Pixmap, GContext, etc.) as their single argument.
    565  * "rid" is the name of the resource.
    566  */
    567 
    568 #define GetResReq(name, rid, req) \
    569 	req = (xResourceReq *) _XGetRequest(dpy, X_##name, SIZEOF(xResourceReq)); \
    570 	if (req) req->id = (rid)
    571 
    572 /*
    573  * GetEmptyReq is for those requests that have no arguments
    574  * at all.
    575  */
    576 
    577 #define GetEmptyReq(name, req) \
    578 	req = (xReq *) _XGetRequest(dpy, X_##name, SIZEOF(xReq))
    579 
    580 /*
    581  * MakeBigReq sets the CARD16 "req->length" to 0 and inserts a new CARD32
    582  * length, after req->length, before the data in the request.  The new length
    583  * includes the "n" extra 32-bit words.
    584  *
    585  * Do not use MakeBigReq if there is no data already in the request.
    586  * req->length must already be >= 2.
    587  */
    588 #ifdef LONG64
    589 #define MakeBigReq(req,n) \
    590     { \
    591     CARD64 _BRdat; \
    592     CARD32 _BRlen = (CARD32) (req->length - 1); \
    593     req->length = 0; \
    594     _BRdat = ((CARD32 *)req)[_BRlen]; \
    595     memmove(((char *)req) + 8, ((char *)req) + 4, (_BRlen - 1) << 2); \
    596     ((CARD32 *)req)[1] = _BRlen + (CARD32) (n) + 2; \
    597     Data32(dpy, &_BRdat, 4); \
    598     }
    599 #else
    600 #define MakeBigReq(req,n) \
    601     { \
    602     CARD32 _BRdat; \
    603     CARD32 _BRlen = req->length - 1; \
    604     req->length = 0; \
    605     _BRdat = ((CARD32 *)req)[_BRlen]; \
    606     memmove(((char *)req) + 8, ((char *)req) + 4, (_BRlen - 1) << 2); \
    607     ((CARD32 *)req)[1] = _BRlen + (CARD32) (n) + 2; \
    608     Data32(dpy, &_BRdat, 4); \
    609     }
    610 #endif
    611 
    612 /*
    613  * SetReqLen increases the count of 32-bit words in the request by "n",
    614  * or by "badlen" if "n" is too large.
    615  *
    616  * Do not use SetReqLen if "req" does not already have data after the
    617  * xReq header.  req->length must already be >= 2.
    618  */
    619 #ifndef __clang_analyzer__
    620 #define SetReqLen(req,n,badlen) \
    621     if ((req->length + n) > (unsigned)65535) { \
    622 	if (dpy->bigreq_size) { \
    623 	    MakeBigReq(req,n) \
    624 	} else { \
    625 	    n = badlen; \
    626 	    req->length = (CARD16) (req->length + n); \
    627 	} \
    628     } else \
    629 	req->length = (CARD16) (req->length + n)
    630 #else
    631 #define SetReqLen(req,n,badlen) \
    632     req->length += n
    633 #endif
    634 
    635 #define SyncHandle() \
    636 	if (dpy->synchandler) (*dpy->synchandler)(dpy)
    637 
    638 extern void _XFlushGCCache(Display *dpy, GC gc);
    639 #define FlushGC(dpy, gc) \
    640 	if ((gc)->dirty) _XFlushGCCache((dpy), (gc))
    641 /*
    642  * Data - Place data in the buffer and pad the end to provide
    643  * 32 bit word alignment.  Transmit if the buffer fills.
    644  *
    645  * "dpy" is a pointer to a Display.
    646  * "data" is a pointer to a data buffer.
    647  * "len" is the length of the data buffer.
    648  */
    649 #ifndef DataRoutineIsProcedure
    650 #define Data(dpy, data, len) do {\
    651 	if (dpy->bufptr + (len) <= dpy->bufmax) {\
    652 		memcpy(dpy->bufptr, data, (size_t)(len));\
    653 		dpy->bufptr += ((size_t)((len) + 3) & (size_t)~3);\
    654 	} else\
    655 		_XSend(dpy, (_Xconst char*)(data), (long)(len));\
    656 } while (0)
    657 #endif /* DataRoutineIsProcedure */
    658 
    659 
    660 /* Allocate bytes from the buffer.  No padding is done, so if
    661  * the length is not a multiple of 4, the caller must be
    662  * careful to leave the buffer aligned after sending the
    663  * current request.
    664  *
    665  * "type" is the type of the pointer being assigned to.
    666  * "ptr" is the pointer being assigned to.
    667  * "n" is the number of bytes to allocate.
    668  *
    669  * Example:
    670  *    xTextElt *elt;
    671  *    BufAlloc (xTextElt *, elt, nbytes)
    672  */
    673 
    674 #define BufAlloc(type, ptr, n) do {      \
    675     if (dpy->bufptr + (n) > dpy->bufmax) \
    676         _XFlush (dpy); \
    677     ptr = (type) dpy->bufptr; \
    678     memset(ptr, '\0', (size_t)(n)); \
    679     dpy->bufptr += (n); \
    680 } while (0)
    681 
    682 #define Data16(dpy, data, len) Data((dpy), (_Xconst char *)(data), (len))
    683 #define _XRead16Pad(dpy, data, len) _XReadPad((dpy), (char *)(data), (len))
    684 #define _XRead16(dpy, data, len) _XRead((dpy), (char *)(data), (len))
    685 #ifdef LONG64
    686 #define Data32(dpy, data, len) _XData32(dpy, (_Xconst long *)(data), (unsigned)(len))
    687 extern int _XData32(
    688 	     Display *dpy,
    689 	     _Xconst long *data,
    690 	     unsigned len
    691 );
    692 extern void _XRead32(
    693 	     Display *dpy,
    694 	     long *data,
    695 	     long len
    696 );
    697 #else
    698 #define Data32(dpy, data, len) Data((dpy), (_Xconst char *)(data), (long)(len))
    699 #define _XRead32(dpy, data, len) _XRead((dpy), (char *)(data), (len))
    700 #endif
    701 
    702 #define PackData16(dpy,data,len) Data16 (dpy, data, len)
    703 #define PackData32(dpy,data,len) Data32 (dpy, data, len)
    704 
    705 /* Xlib manual is bogus */
    706 #define PackData(dpy,data,len) PackData16 (dpy, data, len)
    707 
    708 #define min(a,b) (((a) < (b)) ? (a) : (b))
    709 #define max(a,b) (((a) > (b)) ? (a) : (b))
    710 
    711 #define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
    712 			     (((cs)->rbearing|(cs)->lbearing| \
    713 			       (cs)->ascent|(cs)->descent) == 0))
    714 
    715 /*
    716  * CI_GET_CHAR_INFO_1D - return the charinfo struct for the indicated 8bit
    717  * character.  If the character is in the column and exists, then return the
    718  * appropriate metrics (note that fonts with common per-character metrics will
    719  * return min_bounds).  If none of these hold true, try again with the default
    720  * char.
    721  */
    722 #define CI_GET_CHAR_INFO_1D(fs,col,def,cs) \
    723 do { \
    724     cs = def; \
    725     if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
    726 	if (fs->per_char == NULL) { \
    727 	    cs = &fs->min_bounds; \
    728 	} else { \
    729 	    cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
    730 	    if (CI_NONEXISTCHAR(cs)) cs = def; \
    731 	} \
    732     } \
    733 } while (0)
    734 
    735 #define CI_GET_DEFAULT_INFO_1D(fs,cs) \
    736   CI_GET_CHAR_INFO_1D (fs, fs->default_char, NULL, cs)
    737 
    738 
    739 
    740 /*
    741  * CI_GET_CHAR_INFO_2D - return the charinfo struct for the indicated row and
    742  * column.  This is used for fonts that have more than row zero.
    743  */
    744 #define CI_GET_CHAR_INFO_2D(fs,row,col,def,cs) \
    745 do { \
    746     cs = def; \
    747     if (row >= fs->min_byte1 && row <= fs->max_byte1 && \
    748 	col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
    749 	if (fs->per_char == NULL) { \
    750 	    cs = &fs->min_bounds; \
    751 	} else { \
    752 	    cs = &fs->per_char[((row - fs->min_byte1) * \
    753 			        (fs->max_char_or_byte2 - \
    754 				 fs->min_char_or_byte2 + 1)) + \
    755 			       (col - fs->min_char_or_byte2)]; \
    756 	    if (CI_NONEXISTCHAR(cs)) cs = def; \
    757         } \
    758     } \
    759 } while (0)
    760 
    761 #define CI_GET_DEFAULT_INFO_2D(fs,cs) \
    762 do { \
    763     unsigned int r = (fs->default_char >> 8); \
    764     unsigned int c = (fs->default_char & 0xff); \
    765     CI_GET_CHAR_INFO_2D (fs, r, c, NULL, cs); \
    766 } while (0)
    767 
    768 
    769 /* srcvar must be a variable for large architecture version */
    770 #define OneDataCard32(dpy,dstaddr,srcvar) \
    771     do { *(CARD32 *)(dstaddr) = (srcvar); } while (0)
    772 
    773 
    774 typedef struct _XInternalAsync {
    775     struct _XInternalAsync *next;
    776     /*
    777      * handler arguments:
    778      * rep is the generic reply that caused this handler
    779      * to be invoked.  It must also be passed to _XGetAsyncReply.
    780      * buf and len are opaque values that must be passed to
    781      * _XGetAsyncReply or _XGetAsyncData.
    782      * data is the closure stored in this struct.
    783      * The handler returns True iff it handled this reply.
    784      */
    785     Bool (*handler)(
    786 		    Display*	/* dpy */,
    787 		    xReply*	/* rep */,
    788 		    char*	/* buf */,
    789 		    int		/* len */,
    790 		    XPointer	/* data */
    791 		    );
    792     XPointer data;
    793 } _XAsyncHandler;
    794 
    795 /*
    796  * This struct is part of the ABI and is defined by value
    797  * in user-code. This means that we cannot make
    798  * the sequence-numbers 64bit.
    799  */
    800 typedef struct _XAsyncEState {
    801     unsigned long min_sequence_number;
    802     unsigned long max_sequence_number;
    803     unsigned char error_code;
    804     unsigned char major_opcode;
    805     unsigned short minor_opcode;
    806     unsigned char last_error_received;
    807     int error_count;
    808 } _XAsyncErrorState;
    809 
    810 extern void _XDeqAsyncHandler(Display *dpy, _XAsyncHandler *handler);
    811 #define DeqAsyncHandler(dpy,handler) do { \
    812     if (dpy->async_handlers == (handler)) \
    813 	dpy->async_handlers = (handler)->next; \
    814     else \
    815 	_XDeqAsyncHandler(dpy, handler); \
    816     } while (0)
    817 
    818 typedef void (*FreeFuncType) (
    819     Display*	/* display */
    820 );
    821 
    822 typedef int (*FreeModmapType) (
    823     XModifierKeymap*	/* modmap */
    824 );
    825 
    826 /*
    827  * This structure is private to the library.
    828  */
    829 typedef struct _XFreeFuncs {
    830     FreeFuncType atoms;		/* _XFreeAtomTable */
    831     FreeModmapType modifiermap;	/* XFreeModifiermap */
    832     FreeFuncType key_bindings;	/* _XFreeKeyBindings */
    833     FreeFuncType context_db;	/* _XFreeContextDB */
    834     FreeFuncType defaultCCCs;	/* _XcmsFreeDefaultCCCs */
    835     FreeFuncType clientCmaps;	/* _XcmsFreeClientCmaps */
    836     FreeFuncType intensityMaps;	/* _XcmsFreeIntensityMaps */
    837     FreeFuncType im_filters;	/* _XFreeIMFilters */
    838     FreeFuncType xkb;		/* _XkbFreeInfo */
    839 } _XFreeFuncRec;
    840 
    841 /* types for InitExt.c */
    842 typedef int (*CreateGCType) (
    843     Display*	/* display */,
    844     GC		/* gc */,
    845     XExtCodes*	/* codes */
    846 );
    847 
    848 typedef int (*CopyGCType)(
    849     Display*	/* display */,
    850     GC		/* gc */,
    851     XExtCodes*	/* codes */
    852 );
    853 
    854 typedef int (*FlushGCType) (
    855     Display*	/* display */,
    856     GC		/* gc */,
    857     XExtCodes*	/* codes */
    858 );
    859 
    860 typedef int (*FreeGCType) (
    861     Display*	/* display */,
    862     GC		/* gc */,
    863     XExtCodes*	/* codes */
    864 );
    865 
    866 typedef int (*CreateFontType) (
    867     Display*	/* display */,
    868     XFontStruct* /* fs */,
    869     XExtCodes*	/* codes */
    870 );
    871 
    872 typedef int (*FreeFontType) (
    873     Display*	/* display */,
    874     XFontStruct* /* fs */,
    875     XExtCodes*	/* codes */
    876 );
    877 
    878 typedef int (*CloseDisplayType) (
    879     Display*	/* display */,
    880     XExtCodes*	/* codes */
    881 );
    882 
    883 typedef int (*ErrorType) (
    884     Display*	/* display */,
    885     xError*	/* err */,
    886     XExtCodes*	/* codes */,
    887     int*	/* ret_code */
    888 );
    889 
    890 typedef char* (*ErrorStringType) (
    891     Display*	/* display */,
    892     int		/* code */,
    893     XExtCodes*	/* codes */,
    894     char*	/* buffer */,
    895     int		/* nbytes */
    896 );
    897 
    898 typedef void (*PrintErrorType)(
    899     Display*	/* display */,
    900     XErrorEvent* /* ev */,
    901     void*	/* fp */
    902 );
    903 
    904 typedef void (*BeforeFlushType)(
    905     Display*	/* display */,
    906     XExtCodes*	/* codes */,
    907     _Xconst char* /* data */,
    908     long	/* len */
    909 );
    910 
    911 /*
    912  * This structure is private to the library.
    913  */
    914 typedef struct _XExten {		/* private to extension mechanism */
    915 	struct _XExten *next;		/* next in list */
    916 	XExtCodes codes;		/* public information, all extension told */
    917 	CreateGCType create_GC;		/* routine to call when GC created */
    918 	CopyGCType copy_GC;		/* routine to call when GC copied */
    919 	FlushGCType flush_GC;		/* routine to call when GC flushed */
    920 	FreeGCType free_GC;		/* routine to call when GC freed */
    921 	CreateFontType create_Font;	/* routine to call when Font created */
    922 	FreeFontType free_Font;		/* routine to call when Font freed */
    923 	CloseDisplayType close_display;	/* routine to call when connection closed */
    924 	ErrorType error;		/* who to call when an error occurs */
    925 	ErrorStringType error_string;	/* routine to supply error string */
    926 	char *name;			/* name of this extension */
    927 	PrintErrorType error_values;	/* routine to supply error values */
    928 	BeforeFlushType before_flush;	/* routine to call when sending data */
    929 	struct _XExten *next_flush;	/* next in list of those with flushes */
    930 } _XExtension;
    931 
    932 /* extension hooks */
    933 
    934 #ifdef DataRoutineIsProcedure
    935 extern void Data(Display *dpy, char *data, long len);
    936 #endif
    937 extern int _XError(
    938     Display*	/* dpy */,
    939     xError*	/* rep */
    940 );
    941 extern int _XIOError(
    942     Display*	/* dpy */
    943 );
    944 extern int (*_XIOErrorFunction)(
    945     Display*	/* dpy */
    946 );
    947 extern int (*_XErrorFunction)(
    948     Display*		/* dpy */,
    949     XErrorEvent*	/* error_event */
    950 );
    951 extern void _XEatData(
    952     Display*		/* dpy */,
    953     unsigned long	/* n */
    954 ) _X_COLD;
    955 extern void _XEatDataWords(
    956     Display*		/* dpy */,
    957     unsigned long	/* n */
    958 ) _X_COLD;
    959 #if defined(__SUNPRO_C) /* Studio compiler alternative to "cold" attribute */
    960 # pragma rarely_called(_XEatData, _XEatDataWords)
    961 #endif
    962 extern char *_XAllocScratch(
    963     Display*		/* dpy */,
    964     unsigned long	/* nbytes */
    965 );
    966 extern char *_XAllocTemp(
    967     Display*		/* dpy */,
    968     unsigned long	/* nbytes */
    969 );
    970 extern void _XFreeTemp(
    971     Display*		/* dpy */,
    972     char*		/* buf */,
    973     unsigned long	/* nbytes */
    974 );
    975 extern Visual *_XVIDtoVisual(
    976     Display*	/* dpy */,
    977     VisualID	/* id */
    978 );
    979 extern unsigned long _XSetLastRequestRead(
    980     Display*		/* dpy */,
    981     xGenericReply*	/* rep */
    982 );
    983 extern int _XGetHostname(
    984     char*	/* buf */,
    985     int		/* maxlen */
    986 );
    987 extern Screen *_XScreenOfWindow(
    988     Display*	/* dpy */,
    989     Window	/* w */
    990 );
    991 extern Bool _XAsyncErrorHandler(
    992     Display*	/* dpy */,
    993     xReply*	/* rep */,
    994     char*	/* buf */,
    995     int		/* len */,
    996     XPointer	/* data */
    997 );
    998 extern char *_XGetAsyncReply(
    999     Display*	/* dpy */,
   1000     char*	/* replbuf */,
   1001     xReply*	/* rep */,
   1002     char*	/* buf */,
   1003     int		/* len */,
   1004     int		/* extra */,
   1005     Bool	/* discard */
   1006 );
   1007 extern void _XGetAsyncData(
   1008     Display*	/* dpy */,
   1009     char *	/* data */,
   1010     char *	/* buf */,
   1011     int		/* len */,
   1012     int		/* skip */,
   1013     int		/* datalen */,
   1014     int		/* discardtotal */
   1015 );
   1016 extern void _XFlush(
   1017     Display*	/* dpy */
   1018 );
   1019 extern int _XEventsQueued(
   1020     Display*	/* dpy */,
   1021     int 	/* mode */
   1022 );
   1023 extern void _XReadEvents(
   1024     Display*	/* dpy */
   1025 );
   1026 extern int _XRead(
   1027     Display*	/* dpy */,
   1028     char*	/* data */,
   1029     long	/* size */
   1030 );
   1031 extern void _XReadPad(
   1032     Display*	/* dpy */,
   1033     char*	/* data */,
   1034     long	/* size */
   1035 );
   1036 extern void _XSend(
   1037     Display*		/* dpy */,
   1038     _Xconst char*	/* data */,
   1039     long		/* size */
   1040 );
   1041 extern Status _XReply(
   1042     Display*	/* dpy */,
   1043     xReply*	/* rep */,
   1044     int		/* extra */,
   1045     Bool	/* discard */
   1046 );
   1047 extern void _XEnq(
   1048     Display*	/* dpy */,
   1049     xEvent*	/* event */
   1050 );
   1051 extern void _XDeq(
   1052     Display*	/* dpy */,
   1053     _XQEvent*	/* prev */,
   1054     _XQEvent*	/* qelt */
   1055 );
   1056 
   1057 extern Bool _XUnknownWireEvent(
   1058     Display*	/* dpy */,
   1059     XEvent*	/* re */,
   1060     xEvent*	/* event */
   1061 );
   1062 
   1063 extern Bool _XUnknownWireEventCookie(
   1064     Display*	/* dpy */,
   1065     XGenericEventCookie*	/* re */,
   1066     xEvent*	/* event */
   1067 );
   1068 
   1069 extern Bool _XUnknownCopyEventCookie(
   1070     Display*	/* dpy */,
   1071     XGenericEventCookie*	/* in */,
   1072     XGenericEventCookie*	/* out */
   1073 );
   1074 
   1075 extern Status _XUnknownNativeEvent(
   1076     Display*	/* dpy */,
   1077     XEvent*	/* re */,
   1078     xEvent*	/* event */
   1079 );
   1080 
   1081 extern Bool _XWireToEvent(Display *dpy, XEvent *re, xEvent *event);
   1082 extern Bool _XDefaultWireError(Display *display, XErrorEvent *he, xError *we);
   1083 extern Bool _XPollfdCacheInit(Display *dpy);
   1084 extern void _XPollfdCacheAdd(Display *dpy, int fd);
   1085 extern void _XPollfdCacheDel(Display *dpy, int fd);
   1086 extern XID _XAllocID(Display *dpy);
   1087 extern void _XAllocIDs(Display *dpy, XID *ids, int count);
   1088 
   1089 extern int _XFreeExtData(
   1090     XExtData*	/* extension */
   1091 );
   1092 
   1093 extern int (*XESetCreateGC(
   1094     Display*		/* display */,
   1095     int			/* extension */,
   1096     int (*) (
   1097 	      Display*			/* display */,
   1098 	      GC			/* gc */,
   1099 	      XExtCodes*		/* codes */
   1100 	    )		/* proc */
   1101 ))(
   1102     Display*, GC, XExtCodes*
   1103 );
   1104 
   1105 extern int (*XESetCopyGC(
   1106     Display*		/* display */,
   1107     int			/* extension */,
   1108     int (*) (
   1109 	      Display*			/* display */,
   1110               GC			/* gc */,
   1111               XExtCodes*		/* codes */
   1112             )		/* proc */
   1113 ))(
   1114     Display*, GC, XExtCodes*
   1115 );
   1116 
   1117 extern int (*XESetFlushGC(
   1118     Display*		/* display */,
   1119     int			/* extension */,
   1120     int (*) (
   1121 	      Display*			/* display */,
   1122               GC			/* gc */,
   1123               XExtCodes*		/* codes */
   1124             )		/* proc */
   1125 ))(
   1126     Display*, GC, XExtCodes*
   1127 );
   1128 
   1129 extern int (*XESetFreeGC(
   1130     Display*		/* display */,
   1131     int			/* extension */,
   1132     int (*) (
   1133 	      Display*			/* display */,
   1134               GC			/* gc */,
   1135               XExtCodes*		/* codes */
   1136             )		/* proc */
   1137 ))(
   1138     Display*, GC, XExtCodes*
   1139 );
   1140 
   1141 extern int (*XESetCreateFont(
   1142     Display*		/* display */,
   1143     int			/* extension */,
   1144     int (*) (
   1145 	      Display*			/* display */,
   1146               XFontStruct*		/* fs */,
   1147               XExtCodes*		/* codes */
   1148             )		/* proc */
   1149 ))(
   1150     Display*, XFontStruct*, XExtCodes*
   1151 );
   1152 
   1153 extern int (*XESetFreeFont(
   1154     Display*		/* display */,
   1155     int			/* extension */,
   1156     int (*) (
   1157 	      Display*			/* display */,
   1158               XFontStruct*		/* fs */,
   1159               XExtCodes*		/* codes */
   1160             )		/* proc */
   1161 ))(
   1162     Display*, XFontStruct*, XExtCodes*
   1163 );
   1164 
   1165 extern int (*XESetCloseDisplay(
   1166     Display*		/* display */,
   1167     int			/* extension */,
   1168     int (*) (
   1169 	      Display*			/* display */,
   1170               XExtCodes*		/* codes */
   1171             )		/* proc */
   1172 ))(
   1173     Display*, XExtCodes*
   1174 );
   1175 
   1176 extern int (*XESetError(
   1177     Display*		/* display */,
   1178     int			/* extension */,
   1179     int (*) (
   1180 	      Display*			/* display */,
   1181               xError*			/* err */,
   1182               XExtCodes*		/* codes */,
   1183               int*			/* ret_code */
   1184             )		/* proc */
   1185 ))(
   1186     Display*, xError*, XExtCodes*, int*
   1187 );
   1188 
   1189 extern char* (*XESetErrorString(
   1190     Display*		/* display */,
   1191     int			/* extension */,
   1192     char* (*) (
   1193 	        Display*		/* display */,
   1194                 int			/* code */,
   1195                 XExtCodes*		/* codes */,
   1196                 char*			/* buffer */,
   1197                 int			/* nbytes */
   1198               )		/* proc */
   1199 ))(
   1200     Display*, int, XExtCodes*, char*, int
   1201 );
   1202 
   1203 extern void (*XESetPrintErrorValues (
   1204     Display*		/* display */,
   1205     int			/* extension */,
   1206     void (*)(
   1207 	      Display*			/* display */,
   1208 	      XErrorEvent*		/* ev */,
   1209 	      void*			/* fp */
   1210 	     )		/* proc */
   1211 ))(
   1212     Display*, XErrorEvent*, void*
   1213 );
   1214 
   1215 extern Bool (*XESetWireToEvent(
   1216     Display*		/* display */,
   1217     int			/* event_number */,
   1218     Bool (*) (
   1219 	       Display*			/* display */,
   1220                XEvent*			/* re */,
   1221                xEvent*			/* event */
   1222              )		/* proc */
   1223 ))(
   1224     Display*, XEvent*, xEvent*
   1225 );
   1226 
   1227 extern Bool (*XESetWireToEventCookie(
   1228     Display*		/* display */,
   1229     int			/* extension */,
   1230     Bool (*) (
   1231 	       Display*			/* display */,
   1232                XGenericEventCookie*	/* re */,
   1233                xEvent*			/* event */
   1234              )		/* proc */
   1235 ))(
   1236     Display*, XGenericEventCookie*, xEvent*
   1237 );
   1238 
   1239 extern Bool (*XESetCopyEventCookie(
   1240     Display*		/* display */,
   1241     int			/* extension */,
   1242     Bool (*) (
   1243 	       Display*			/* display */,
   1244                XGenericEventCookie*	/* in */,
   1245                XGenericEventCookie*	/* out */
   1246              )		/* proc */
   1247 ))(
   1248     Display*, XGenericEventCookie*, XGenericEventCookie*
   1249 );
   1250 
   1251 
   1252 extern Status (*XESetEventToWire(
   1253     Display*		/* display */,
   1254     int			/* event_number */,
   1255     Status (*) (
   1256 	      Display*			/* display */,
   1257               XEvent*			/* re */,
   1258               xEvent*			/* event */
   1259             )		/* proc */
   1260 ))(
   1261     Display*, XEvent*, xEvent*
   1262 );
   1263 
   1264 extern Bool (*XESetWireToError(
   1265     Display*		/* display */,
   1266     int			/* error_number */,
   1267     Bool (*) (
   1268 	       Display*			/* display */,
   1269 	       XErrorEvent*		/* he */,
   1270 	       xError*			/* we */
   1271             )		/* proc */
   1272 ))(
   1273     Display*, XErrorEvent*, xError*
   1274 );
   1275 
   1276 extern void (*XESetBeforeFlush(
   1277     Display*		/* display */,
   1278     int			/* error_number */,
   1279     void (*) (
   1280 	       Display*			/* display */,
   1281 	       XExtCodes*		/* codes */,
   1282 	       _Xconst char*		/* data */,
   1283 	       long			/* len */
   1284             )		/* proc */
   1285 ))(
   1286     Display*, XExtCodes*, _Xconst char*, long
   1287 );
   1288 
   1289 /* internal connections for IMs */
   1290 
   1291 typedef void (*_XInternalConnectionProc)(
   1292     Display*			/* dpy */,
   1293     int				/* fd */,
   1294     XPointer			/* call_data */
   1295 );
   1296 
   1297 
   1298 extern Status _XRegisterInternalConnection(
   1299     Display*			/* dpy */,
   1300     int				/* fd */,
   1301     _XInternalConnectionProc	/* callback */,
   1302     XPointer			/* call_data */
   1303 );
   1304 
   1305 extern void _XUnregisterInternalConnection(
   1306     Display*			/* dpy */,
   1307     int				/* fd */
   1308 );
   1309 
   1310 extern void _XProcessInternalConnection(
   1311     Display*			/* dpy */,
   1312     struct _XConnectionInfo*	/* conn_info */
   1313 );
   1314 
   1315 /* Display structure has pointers to these */
   1316 
   1317 struct _XConnectionInfo {	/* info from _XRegisterInternalConnection */
   1318     int fd;
   1319     _XInternalConnectionProc read_callback;
   1320     XPointer call_data;
   1321     XPointer *watch_data;	/* set/used by XConnectionWatchProc */
   1322     struct _XConnectionInfo *next;
   1323 };
   1324 
   1325 struct _XConnWatchInfo {	/* info from XAddConnectionWatch */
   1326     XConnectionWatchProc fn;
   1327     XPointer client_data;
   1328     struct _XConnWatchInfo *next;
   1329 };
   1330 
   1331 extern int _XTextHeight(
   1332     XFontStruct*	/* font_struct */,
   1333     _Xconst char*	/* string */,
   1334     int			/* count */
   1335 );
   1336 
   1337 extern int _XTextHeight16(
   1338     XFontStruct*	/* font_struct */,
   1339     _Xconst XChar2b*	/* string */,
   1340     int			/* count */
   1341 );
   1342 
   1343 #if defined(WIN32)
   1344 
   1345 extern int _XOpenFile(
   1346     _Xconst char*	/* path */,
   1347     int			/* flags */
   1348 );
   1349 
   1350 extern int _XOpenFileMode(
   1351     _Xconst char*	/* path */,
   1352     int			/* flags */,
   1353     mode_t              /* mode */
   1354 );
   1355 
   1356 extern void* _XFopenFile(
   1357     _Xconst char*	/* path */,
   1358     _Xconst char*	/* mode */
   1359 );
   1360 
   1361 extern int _XAccessFile(
   1362     _Xconst char*	/* path */
   1363 );
   1364 #else
   1365 #define _XOpenFile(path,flags) open(path,flags)
   1366 #define _XOpenFileMode(path,flags,mode) open(path,flags,mode)
   1367 #define _XFopenFile(path,mode) fopen(path,mode)
   1368 #endif
   1369 
   1370 /* EvToWire.c */
   1371 extern Status _XEventToWire(Display *dpy, XEvent *re, xEvent *event);
   1372 
   1373 extern int _XF86LoadQueryLocaleFont(
   1374     Display*		/* dpy */,
   1375     _Xconst char*	/* name*/,
   1376     XFontStruct**	/* xfp*/,
   1377     Font*		/* fidp */
   1378 );
   1379 
   1380 extern void _XProcessWindowAttributes (
   1381     Display *dpy,
   1382     xChangeWindowAttributesReq *req,
   1383     unsigned long valuemask,
   1384     XSetWindowAttributes *attributes);
   1385 
   1386 extern int _XDefaultError(
   1387         Display *dpy,
   1388         XErrorEvent *event);
   1389 
   1390 extern int _XDefaultIOError(
   1391         Display *dpy);
   1392 
   1393 extern void _XDefaultIOErrorExit(
   1394     Display *dpy,
   1395     void *user_data);
   1396 
   1397 extern void _XSetClipRectangles (
   1398     Display *dpy,
   1399     GC gc,
   1400     int clip_x_origin, int clip_y_origin,
   1401     XRectangle *rectangles,
   1402     int n,
   1403     int ordering);
   1404 
   1405 Status _XGetWindowAttributes(
   1406     Display *dpy,
   1407     Window w,
   1408     XWindowAttributes *attr);
   1409 
   1410 int _XPutBackEvent (
   1411     Display *dpy,
   1412     XEvent *event);
   1413 
   1414 extern Bool _XIsEventCookie(
   1415         Display *dpy,
   1416         XEvent *ev);
   1417 
   1418 extern void _XFreeEventCookies(
   1419         Display *dpy);
   1420 
   1421 extern void _XStoreEventCookie(
   1422         Display *dpy,
   1423         XEvent *ev);
   1424 
   1425 extern Bool _XFetchEventCookie(
   1426         Display *dpy,
   1427         XGenericEventCookie *ev);
   1428 
   1429 extern Bool _XCopyEventCookie(
   1430         Display *dpy,
   1431         XGenericEventCookie *in,
   1432         XGenericEventCookie *out);
   1433 
   1434 /* lcFile.c */
   1435 
   1436 extern void xlocaledir(
   1437     char *buf,
   1438     int buf_len
   1439 );
   1440 
   1441 #ifdef __clang__
   1442 #pragma clang diagnostic pop
   1443 #endif
   1444 
   1445 _XFUNCPROTOEND
   1446 
   1447 #endif /* _X11_XLIBINT_H_ */
   1448