Copyright 1984, 1985, 1987, 1989, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
#define _X11_XLIBINT_H_ 1
* Xlibint.h - Header definition and support file for the internal
* support routines used by the C subroutine interface
* library (Xlib) to the X Window System.
* Warning, there be dragons here....
#include <X11/Xproto.h> /* to declare xEvent */
#include <X11/XlibConf.h> /* for configured options like XTHREADS */
/* The Xlib structs are full of implicit padding to properly align members.
We can't clean that up without breaking ABI, so tell clang not to bother
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
#define _XFlush _XFlushIt
XExtData *ext_data; /* hook for extension to hang data */
GContext gid; /* protocol ID for graphics context */
Bool rects; /* boolean: TRUE if clipmask is list of rectangles */
Bool dashes; /* boolean: TRUE if dash-list is really a list */
unsigned long dirty;/* cache dirty bits */
XGCValues values; /* shadow structure of values */
XExtData *ext_data; /* hook for extension to hang data */
struct _XFreeFuncs *free_funcs; /* internal free functions */
int fd; /* Network socket. */
int conn_checker; /* ugly thing used by _XEventsQueued */
int proto_major_version;/* maj. version of server's X protocol */
int proto_minor_version;/* minor version of server's X protocol */
char *vendor; /* vendor of the server hardware */
XID resource_base; /* resource ID base */
XID resource_mask; /* resource ID mask bits */
XID resource_id; /* allocator current ID */
int resource_shift; /* allocator shift to correct bits */
XID (*resource_alloc)( /* allocator function */
int byte_order; /* screen byte order, LSBFirst, MSBFirst */
int bitmap_unit; /* padding and data requirements */
int bitmap_pad; /* padding requirements on bitmaps */
int bitmap_bit_order; /* LeastSignificant or MostSignificant */
int nformats; /* number of pixmap formats in list */
ScreenFormat *pixmap_format; /* pixmap format list */
int vnumber; /* Xlib's X protocol version number. */
int release; /* release of the server */
struct _XSQEvent *head, *tail; /* Input event queue. */
int qlen; /* Length of input event queue */
unsigned long last_request_read; /* seq number of last event read */
unsigned long request; /* sequence number of last request. */
char *last_req; /* beginning of last request, or dummy */
char *buffer; /* Output buffer starting address. */
char *bufptr; /* Output buffer index pointer. */
char *bufmax; /* Output buffer maximum+1 address. */
unsigned max_request_size; /* maximum number 32 bit words in request*/
struct _XrmHashBucketRec *db;
int (*synchandler)( /* Synchronization handler */
char *display_name; /* "host:display" string used on this connect*/
int default_screen; /* default screen for operations */
int nscreens; /* number of screens on this server*/
Screen *screens; /* pointer to list of screens */
unsigned long motion_buffer; /* size of motion buffer */
volatile unsigned long flags; /* internal connection flags */
int min_keycode; /* minimum defined keycode */
int max_keycode; /* maximum defined keycode */
KeySym *keysyms; /* This server's keysyms */
XModifierKeymap *modifiermap; /* This server's modifier keymap */
int keysyms_per_keycode;/* number of rows */
char *xdefaults; /* contents of defaults from server */
char *scratch_buffer; /* place to hang scratch buffer */
unsigned long scratch_length; /* length of scratch buffer */
int ext_number; /* extension number on this display */
struct _XExten *ext_procs; /* extensions initialized on this display */
* the following can be fixed size, as the protocol defines how
* much address space is available.
* While this could be done using the extension vector, there
* may be MANY events processed, so a search through the extension
* list to find the right procedure for each event might be
* expensive if many extensions are being used.
Bool (*event_vec[128])( /* vector for wire to event */
Status (*wire_vec[128])( /* vector for event to wire */
KeySym lock_meaning; /* for XLookupString */
struct _XLockInfo *lock; /* multi-thread state, display lock */
struct _XInternalAsync *async_handlers; /* for internal async */
unsigned long bigreq_size; /* max size of big requests */
struct _XLockPtrs *lock_fns; /* pointers to threads functions */
void (*idlist_alloc)( /* XID list allocator function */
/* things above this line should not move, for binary compatibility */
struct _XKeytrans *key_bindings; /* for XLookupString */
Font cursor_font; /* for XCreateFontCursor */
struct _XDisplayAtoms *atoms; /* for XInternAtom */
unsigned int mode_switch; /* keyboard group modifiers */
unsigned int num_lock; /* keyboard numlock modifiers */
struct _XContextDB *context_db; /* context database */
Bool (**error_vec)( /* vector for wire to error */
XPointer defaultCCCs; /* pointer to an array of default XcmsCCC */
XPointer clientCmaps; /* pointer to linked list of XcmsCmapRec */
XPointer perVisualIntensityMaps;
/* linked list of XcmsIntensityMap */
struct _XIMFilter *im_filters;
struct _XSQEvent *qfree; /* unallocated event queue elements */
unsigned long next_event_serial_num; /* inserted into next queue elt */
struct _XExten *flushes; /* Flush hooks */
struct _XConnectionInfo *im_fd_info; /* _XRegisterInternalConnection */
int im_fd_length; /* number of im_fd_info */
struct _XConnWatchInfo *conn_watchers; /* XAddConnectionWatch */
int watcher_count; /* number of conn_watchers */
XPointer filedes; /* struct pollfd cache for _XWaitForReadable */
int (*savedsynchandler)( /* user synchandler when Xlib usurps */
XID resource_max; /* allocator max ID */
int xcmisc_opcode; /* major opcode for XC-MISC */
struct _XkbInfoRec *xkb_info; /* XKB info */
struct _XtransConnInfo *trans_conn; /* transport connection object */
struct _X11XCBPrivate *xcb; /* XCB glue private data */
/* Generic event cookie handling */
unsigned int next_cookie; /* next event cookie */
/* vector for wire to generic event, index is (extension - 128) */
Bool (*generic_event_vec[128])(
XGenericEventCookie * /* Xlib event */,
xEvent * /* wire event */);
/* vector for event copy, index is (extension - 128) */
Bool (*generic_event_copy_vec[128])(
XGenericEventCookie * /* in */,
XGenericEventCookie * /* out*/);
void *cookiejar; /* cookie events returned but not claimed */
unsigned long last_request_read_upper32bit;
unsigned long request_upper32bit;
struct _XErrorThreadInfo *error_threads;
#define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
* access "last_request_read" and "request" with 64bit
* warning: the value argument of the SET-macros must not
* have any side-effects because it may get called twice.
/* accessors for 32-bit unsigned long */
#define X_DPY_GET_REQUEST(dpy) \
((uint64_t)(((struct _XDisplay*)dpy)->request)) \
+ (((uint64_t)(((struct _XDisplay*)dpy)->request_upper32bit)) << 32) \
#define X_DPY_SET_REQUEST(dpy, value) \
(((struct _XDisplay*)dpy)->request = \
(value) & 0xFFFFFFFFUL), \
(((struct _XDisplay*)dpy)->request_upper32bit = \
((uint64_t)(value)) >> 32), \
(void)0 /* don't use the result */ \
#define X_DPY_GET_LAST_REQUEST_READ(dpy) \
((uint64_t)(((struct _XDisplay*)dpy)->last_request_read)) \
((struct _XDisplay*)dpy)->last_request_read_upper32bit \
#define X_DPY_SET_LAST_REQUEST_READ(dpy, value) \
(((struct _XDisplay*)dpy)->last_request_read = \
(value) & 0xFFFFFFFFUL), \
(((struct _XDisplay*)dpy)->last_request_read_upper32bit = \
((uint64_t)(value)) >> 32), \
(void)0 /* don't use the result */ \
* widen a 32-bit sequence number to a 64 sequence number.
* This macro makes the following assumptions:
* - ulseq refers to a sequence that has already been sent
* - ulseq means the most recent possible sequence number
* with these lower 32 bits.
* The following optimization is used:
* The comparison result is taken a 0 or 1 to avoid a branch.
#define X_DPY_WIDEN_UNSIGNED_LONG_SEQ(dpy, ulseq) \
((uint64_t)(((struct _XDisplay*)dpy)->request_upper32bit)) \
(ulseq) > (((struct _XDisplay*)dpy)->request) \
#define X_DPY_REQUEST_INCREMENT(dpy) \
((struct _XDisplay*)dpy)->request++, \
(((struct _XDisplay*)dpy)->request == 0) ? ( \
((struct _XDisplay*)dpy)->request_upper32bit++ \
(void)0 /* don't use the result */ \
#define X_DPY_REQUEST_DECREMENT(dpy) \
(((struct _XDisplay*)dpy)->request == 0) ? (\
((struct _XDisplay*)dpy)->request--, /* wrap */ \
((struct _XDisplay*)dpy)->request_upper32bit-- \
((struct _XDisplay*)dpy)->request-- \
(void)0 /* don't use the result */ \
/* accessors for 64-bit unsigned long */
#define X_DPY_GET_REQUEST(dpy) \
(((struct _XDisplay*)dpy)->request)
#define X_DPY_SET_REQUEST(dpy, value) \
((struct _XDisplay*)dpy)->request = (value)
#define X_DPY_GET_LAST_REQUEST_READ(dpy) \
(((struct _XDisplay*)dpy)->last_request_read)
#define X_DPY_SET_LAST_REQUEST_READ(dpy, value) \
((struct _XDisplay*)dpy)->last_request_read = (value)
#define X_DPY_WIDEN_UNSIGNED_LONG_SEQ(dpy, ulseq) ulseq
#define X_DPY_REQUEST_INCREMENT(dpy) ((struct _XDisplay*)dpy)->request++
#define X_DPY_REQUEST_DECREMENT(dpy) ((struct _XDisplay*)dpy)->request--
* _QEvent datatype for use in input queueing.
unsigned long qserial_num; /* so multi-threaded code can find new ones */
#define _SGI_MP_SOURCE /* turn this on to get MP safe errno */
#define _XBCOPYFUNC _Xbcopy
/* Utek leaves kernel macros around in include files (bleah) */
#include <X11/Xfuncproto.h>
* The following definitions can be used for locking requests in multi-threaded
/* Author: Stephen Gildea, MIT X Consortium
* declarations for C Threads locking
typedef struct _LockInfoRec *LockInfoPtr;
/* interfaces for locking.c */
/* used by all, including extensions; do not move */
#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
#if defined(WIN32) && !defined(_XLIBINT_)
#define _XCreateMutex_fn (*_XCreateMutex_fn_p)
#define _XFreeMutex_fn (*_XFreeMutex_fn_p)
#define _XLockMutex_fn (*_XLockMutex_fn_p)
#define _XUnlockMutex_fn (*_XUnlockMutex_fn_p)
#define _Xglobal_lock (*_Xglobal_lock_p)
extern void (*_XCreateMutex_fn)(
extern void (*_XFreeMutex_fn)(
extern void (*_XLockMutex_fn)(
#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
extern void (*_XUnlockMutex_fn)(
#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
extern LockInfoPtr _Xglobal_lock;
#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
#define LockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->lock_display)((d),__FILE__,__LINE__)
#define UnlockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)((d),__FILE__,__LINE__)
#define _XLockMutex(lock) if (_XLockMutex_fn) (*_XLockMutex_fn)(lock,__FILE__,__LINE__)
#define _XUnlockMutex(lock) if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock,__FILE__,__LINE__)
/* used everywhere, so must be fast if not using threads */
#define LockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->lock_display)(d)
#define UnlockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)(d)
#define _XLockMutex(lock) if (_XLockMutex_fn) (*_XLockMutex_fn)(lock)
#define _XUnlockMutex(lock) if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock)
#define _XCreateMutex(lock) if (_XCreateMutex_fn) (*_XCreateMutex_fn)(lock);
#define _XFreeMutex(lock) if (_XFreeMutex_fn) (*_XFreeMutex_fn)(lock);
#define _XLockMutex(lock)
#define _XUnlockMutex(lock)
#define UnlockDisplay(dis)
#define _XCreateMutex(lock)
#define _XFreeMutex(lock)
#define Xfree(ptr) free((ptr))
* Note that some machines do not return a valid pointer for malloc(0), in
* which case we provide an alternate under the control of the
* define MALLOC_0_RETURNS_NULL. This is necessary because some
* Xlib code expects malloc(0) to return a valid pointer to storage.
#if defined(MALLOC_0_RETURNS_NULL) || defined(__clang_analyzer__)
# define Xmalloc(size) malloc(((size) == 0 ? 1 : (size)))
# define Xrealloc(ptr, size) realloc((ptr), ((size) == 0 ? 1 : (size)))
# define Xcalloc(nelem, elsize) calloc(((nelem) == 0 ? 1 : (nelem)), (elsize))
# define Xmalloc(size) malloc((size))
# define Xrealloc(ptr, size) realloc((ptr), (size))
# define Xcalloc(nelem, elsize) calloc((nelem), (elsize))
#define BUFSIZE 2048 /* X output buffer size. */
#define PTSPERBATCH 1024 /* point batching */
#define WLNSPERBATCH 50 /* wide line batching */
#define ZLNSPERBATCH 1024 /* thin line batching */
#define WRCTSPERBATCH 10 /* wide line rectangle batching */
#define ZRCTSPERBATCH 256 /* thin line rectangle batching */
#define FRCTSPERBATCH 256 /* filled rectangle batching */
#define FARCSPERBATCH 256 /* filled arc batching */
#define CURSORFONT "cursor" /* standard cursor fonts */
#define XlibDisplayIOError (1L << 0)
#define XlibDisplayClosing (1L << 1)
#define XlibDisplayNoXkb (1L << 2)
#define XlibDisplayPrivSync (1L << 3)