Xlibint.h revision eb411b4b
1
2/*
3
4Copyright 1984, 1985, 1987, 1989, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included
13in all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of The Open Group shall
24not be used in advertising or otherwise to promote the sale, use or
25other dealings in this Software without prior written authorization
26from 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 <X11/Xlib.h>
42#include <X11/Xproto.h>		/* to declare xEvent */
43#include <X11/XlibConf.h>	/* for configured options like XTHREADS */
44
45/* The Xlib structs are full of implicit padding to properly align members.
46   We can't clean that up without breaking ABI, so tell clang not to bother
47   complaining about it. */
48#ifdef __clang__
49#pragma clang diagnostic push
50#pragma clang diagnostic ignored "-Wpadded"
51#endif
52
53#ifdef WIN32
54#define _XFlush _XFlushIt
55#endif
56
57/*
58 * If your BytesReadable correctly detects broken connections, then
59 * you should NOT define XCONN_CHECK_FREQ.
60 */
61#ifndef XCONN_CHECK_FREQ
62#define XCONN_CHECK_FREQ 256
63#endif
64
65struct _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
75struct _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};
209
210#define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
211
212#ifndef _XEVENT_
213/*
214 * _QEvent datatype for use in input queueing.
215 */
216typedef struct _XSQEvent
217{
218    struct _XSQEvent *next;
219    XEvent event;
220    unsigned long qserial_num;	/* so multi-threaded code can find new ones */
221} _XQEvent;
222#endif
223
224#include <X11/Xproto.h>
225#ifdef __sgi
226#define _SGI_MP_SOURCE  /* turn this on to get MP safe errno */
227#endif
228#include <errno.h>
229#define _XBCOPYFUNC _Xbcopy
230#include <X11/Xfuncs.h>
231#include <X11/Xosdefs.h>
232
233/* Utek leaves kernel macros around in include files (bleah) */
234#ifdef dirty
235#undef dirty
236#endif
237
238#include <stdlib.h>
239#include <string.h>
240
241#include <X11/Xfuncproto.h>
242
243_XFUNCPROTOBEGIN
244
245/*
246 * The following definitions can be used for locking requests in multi-threaded
247 * address spaces.
248 */
249#ifdef XTHREADS
250/* Author: Stephen Gildea, MIT X Consortium
251 *
252 * declarations for C Threads locking
253 */
254
255typedef struct _LockInfoRec *LockInfoPtr;
256
257/* interfaces for locking.c */
258struct _XLockPtrs {
259    /* used by all, including extensions; do not move */
260    void (*lock_display)(
261		Display *dpy
262#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
263		, char *file
264		, int line
265#endif
266	);
267    void (*unlock_display)(
268		Display *dpy
269#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
270		, char *file
271		, int line
272#endif
273	);
274};
275
276#if defined(WIN32) && !defined(_XLIBINT_)
277#define _XCreateMutex_fn (*_XCreateMutex_fn_p)
278#define _XFreeMutex_fn (*_XFreeMutex_fn_p)
279#define _XLockMutex_fn (*_XLockMutex_fn_p)
280#define _XUnlockMutex_fn (*_XUnlockMutex_fn_p)
281#define _Xglobal_lock (*_Xglobal_lock_p)
282#endif
283
284/* in XlibInt.c */
285extern void (*_XCreateMutex_fn)(
286    LockInfoPtr /* lock */
287);
288extern void (*_XFreeMutex_fn)(
289    LockInfoPtr /* lock */
290);
291extern void (*_XLockMutex_fn)(
292    LockInfoPtr	/* lock */
293#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
294    , char * /* file */
295    , int /* line */
296#endif
297);
298extern void (*_XUnlockMutex_fn)(
299    LockInfoPtr	/* lock */
300#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
301    , char * /* file */
302    , int /* line */
303#endif
304);
305
306extern LockInfoPtr _Xglobal_lock;
307
308#if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
309#define LockDisplay(d)	     if ((d)->lock_fns) (*(d)->lock_fns->lock_display)((d),__FILE__,__LINE__)
310#define UnlockDisplay(d)     if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)((d),__FILE__,__LINE__)
311#define _XLockMutex(lock)		if (_XLockMutex_fn) (*_XLockMutex_fn)(lock,__FILE__,__LINE__)
312#define _XUnlockMutex(lock)	if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock,__FILE__,__LINE__)
313#else
314/* used everywhere, so must be fast if not using threads */
315#define LockDisplay(d)	     if ((d)->lock_fns) (*(d)->lock_fns->lock_display)(d)
316#define UnlockDisplay(d)     if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)(d)
317#define _XLockMutex(lock)		if (_XLockMutex_fn) (*_XLockMutex_fn)(lock)
318#define _XUnlockMutex(lock)	if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock)
319#endif
320#define _XCreateMutex(lock)	if (_XCreateMutex_fn) (*_XCreateMutex_fn)(lock);
321#define _XFreeMutex(lock)	if (_XFreeMutex_fn) (*_XFreeMutex_fn)(lock);
322
323#else /* XTHREADS */
324#define LockDisplay(dis)
325#define _XLockMutex(lock)
326#define _XUnlockMutex(lock)
327#define UnlockDisplay(dis)
328#define _XCreateMutex(lock)
329#define _XFreeMutex(lock)
330#endif
331
332#define Xfree(ptr) free((ptr))
333
334/*
335 * Note that some machines do not return a valid pointer for malloc(0), in
336 * which case we provide an alternate under the control of the
337 * define MALLOC_0_RETURNS_NULL.  This is necessary because some
338 * Xlib code expects malloc(0) to return a valid pointer to storage.
339 */
340#if defined(MALLOC_0_RETURNS_NULL) || defined(__clang_analyzer__)
341
342# define Xmalloc(size) malloc(((size) == 0 ? 1 : (size)))
343# define Xrealloc(ptr, size) realloc((ptr), ((size) == 0 ? 1 : (size)))
344# define Xcalloc(nelem, elsize) calloc(((nelem) == 0 ? 1 : (nelem)), (elsize))
345
346#else
347
348# define Xmalloc(size) malloc((size))
349# define Xrealloc(ptr, size) realloc((ptr), (size))
350# define Xcalloc(nelem, elsize) calloc((nelem), (elsize))
351
352#endif
353
354#include <stddef.h>
355
356#define LOCKED 1
357#define UNLOCKED 0
358
359#ifndef BUFSIZE
360#define BUFSIZE 2048			/* X output buffer size. */
361#endif
362#ifndef PTSPERBATCH
363#define PTSPERBATCH 1024		/* point batching */
364#endif
365#ifndef WLNSPERBATCH
366#define WLNSPERBATCH 50			/* wide line batching */
367#endif
368#ifndef ZLNSPERBATCH
369#define ZLNSPERBATCH 1024		/* thin line batching */
370#endif
371#ifndef WRCTSPERBATCH
372#define WRCTSPERBATCH 10		/* wide line rectangle batching */
373#endif
374#ifndef ZRCTSPERBATCH
375#define ZRCTSPERBATCH 256		/* thin line rectangle batching */
376#endif
377#ifndef FRCTSPERBATCH
378#define FRCTSPERBATCH 256		/* filled rectangle batching */
379#endif
380#ifndef FARCSPERBATCH
381#define FARCSPERBATCH 256		/* filled arc batching */
382#endif
383#ifndef CURSORFONT
384#define CURSORFONT "cursor"		/* standard cursor fonts */
385#endif
386
387/*
388 * Display flags
389 */
390#define XlibDisplayIOError	(1L << 0)
391#define XlibDisplayClosing	(1L << 1)
392#define XlibDisplayNoXkb	(1L << 2)
393#define XlibDisplayPrivSync	(1L << 3)
394#define XlibDisplayProcConni	(1L << 4) /* in _XProcessInternalConnection */
395#define XlibDisplayReadEvents	(1L << 5) /* in _XReadEvents */
396#define XlibDisplayReply	(1L << 5) /* in _XReply */
397#define XlibDisplayWriting	(1L << 6) /* in _XFlushInt, _XSend */
398#define XlibDisplayDfltRMDB     (1L << 7) /* mark if RM db from XGetDefault */
399
400/*
401 * X Protocol packetizing macros.
402 */
403
404/* Leftover from CRAY support - was defined empty on all non-Cray systems */
405#define WORD64ALIGN
406
407/**
408 * Return a len-sized request buffer for the request type. This function may
409 * flush the output queue.
410 *
411 * @param dpy The display connection
412 * @param type The request type
413 * @param len Length of the request in bytes
414 *
415 * @returns A pointer to the request buffer with a few default values
416 * initialized.
417 */
418extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len);
419
420/* GetReqSized is the same as GetReq but allows the caller to specify the
421 * size in bytes. 'sz' must be a multiple of 4! */
422
423#if !defined(UNIXCPP) || defined(ANSICPP)
424#define GetReqSized(name, sz, req) \
425	req = (x##name##Req *) _XGetRequest(dpy, X_##name, sz)
426#else
427#define GetReqSized(name, sz, req) \
428	req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, sz)
429#endif
430
431
432/*
433 * GetReq - Get the next available X request packet in the buffer and
434 * return it.
435 *
436 * "name" is the name of the request, e.g. CreatePixmap, OpenFont, etc.
437 * "req" is the name of the request pointer.
438 *
439 */
440
441#if !defined(UNIXCPP) || defined(ANSICPP)
442#define GetReq(name, req) \
443	GetReqSized(name, SIZEOF(x##name##Req), req)
444#else  /* non-ANSI C uses empty comment instead of "##" for token concatenation */
445#define GetReq(name, req) \
446	GetReqSized(name, SIZEOF(x/**/name/**/Req), req)
447#endif
448
449/* GetReqExtra is the same as GetReq, but allocates "n" additional
450   bytes after the request. "n" must be a multiple of 4!  */
451
452#if !defined(UNIXCPP) || defined(ANSICPP)
453#define GetReqExtra(name, n, req) \
454        GetReqSized(name, SIZEOF(x##name##Req) + n, req)
455#else
456#define GetReqExtra(name, n, req) \
457        GetReqSized(name, SIZEOF(x/**/name/**/Req) + n, req)
458#endif
459
460
461/*
462 * GetResReq is for those requests that have a resource ID
463 * (Window, Pixmap, GContext, etc.) as their single argument.
464 * "rid" is the name of the resource.
465 */
466
467#if !defined(UNIXCPP) || defined(ANSICPP)
468#define GetResReq(name, rid, req) \
469	req = (xResourceReq *) _XGetRequest(dpy, X_##name, SIZEOF(xResourceReq)); \
470	req->id = (rid)
471#else
472#define GetResReq(name, rid, req) \
473	req = (xResourceReq *) _XGetRequest(dpy, X_/**/name, SIZEOF(xResourceReq)); \
474	req->id = (rid)
475#endif
476
477/*
478 * GetEmptyReq is for those requests that have no arguments
479 * at all.
480 */
481#if !defined(UNIXCPP) || defined(ANSICPP)
482#define GetEmptyReq(name, req) \
483	req = (xReq *) _XGetRequest(dpy, X_##name, SIZEOF(xReq))
484#else
485#define GetEmptyReq(name, req) \
486	req = (xReq *) _XGetRequest(dpy, X_/**/name, SIZEOF(xReq))
487#endif
488
489/*
490 * MakeBigReq sets the CARD16 "req->length" to 0 and inserts a new CARD32
491 * length, after req->length, before the data in the request.  The new length
492 * includes the "n" extra 32-bit words.
493 *
494 * Do not use MakeBigReq if there is no data already in the request.
495 * req->length must already be >= 2.
496 */
497#ifdef LONG64
498#define MakeBigReq(req,n) \
499    { \
500    CARD64 _BRdat; \
501    CARD32 _BRlen = req->length - 1; \
502    req->length = 0; \
503    _BRdat = ((CARD32 *)req)[_BRlen]; \
504    memmove(((char *)req) + 8, ((char *)req) + 4, (_BRlen - 1) << 2); \
505    ((CARD32 *)req)[1] = _BRlen + n + 2; \
506    Data32(dpy, &_BRdat, 4); \
507    }
508#else
509#define MakeBigReq(req,n) \
510    { \
511    CARD32 _BRdat; \
512    CARD32 _BRlen = req->length - 1; \
513    req->length = 0; \
514    _BRdat = ((CARD32 *)req)[_BRlen]; \
515    memmove(((char *)req) + 8, ((char *)req) + 4, (_BRlen - 1) << 2); \
516    ((CARD32 *)req)[1] = _BRlen + n + 2; \
517    Data32(dpy, &_BRdat, 4); \
518    }
519#endif
520
521/*
522 * SetReqLen increases the count of 32-bit words in the request by "n",
523 * or by "badlen" if "n" is too large.
524 *
525 * Do not use SetReqLen if "req" does not already have data after the
526 * xReq header.  req->length must already be >= 2.
527 */
528#ifndef __clang_analyzer__
529#define SetReqLen(req,n,badlen) \
530    if ((req->length + n) > (unsigned)65535) { \
531	if (dpy->bigreq_size) { \
532	    MakeBigReq(req,n) \
533	} else { \
534	    n = badlen; \
535	    req->length += n; \
536	} \
537    } else \
538	req->length += n
539#else
540#define SetReqLen(req,n,badlen) \
541    req->length += n
542#endif
543
544#define SyncHandle() \
545	if (dpy->synchandler) (*dpy->synchandler)(dpy)
546
547extern void _XFlushGCCache(Display *dpy, GC gc);
548#define FlushGC(dpy, gc) \
549	if ((gc)->dirty) _XFlushGCCache((dpy), (gc))
550/*
551 * Data - Place data in the buffer and pad the end to provide
552 * 32 bit word alignment.  Transmit if the buffer fills.
553 *
554 * "dpy" is a pointer to a Display.
555 * "data" is a pointer to a data buffer.
556 * "len" is the length of the data buffer.
557 */
558#ifndef DataRoutineIsProcedure
559#define Data(dpy, data, len) {\
560	if (dpy->bufptr + (len) <= dpy->bufmax) {\
561		memcpy(dpy->bufptr, data, (int)len);\
562		dpy->bufptr += ((len) + 3) & ~3;\
563	} else\
564		_XSend(dpy, data, len);\
565}
566#endif /* DataRoutineIsProcedure */
567
568
569/* Allocate bytes from the buffer.  No padding is done, so if
570 * the length is not a multiple of 4, the caller must be
571 * careful to leave the buffer aligned after sending the
572 * current request.
573 *
574 * "type" is the type of the pointer being assigned to.
575 * "ptr" is the pointer being assigned to.
576 * "n" is the number of bytes to allocate.
577 *
578 * Example:
579 *    xTextElt *elt;
580 *    BufAlloc (xTextElt *, elt, nbytes)
581 */
582
583#define BufAlloc(type, ptr, n) \
584    if (dpy->bufptr + (n) > dpy->bufmax) \
585        _XFlush (dpy); \
586    ptr = (type) dpy->bufptr; \
587    memset(ptr, '\0', n); \
588    dpy->bufptr += (n);
589
590#define Data16(dpy, data, len) Data((dpy), (_Xconst char *)(data), (len))
591#define _XRead16Pad(dpy, data, len) _XReadPad((dpy), (char *)(data), (len))
592#define _XRead16(dpy, data, len) _XRead((dpy), (char *)(data), (len))
593#ifdef LONG64
594#define Data32(dpy, data, len) _XData32(dpy, (_Xconst long *)data, len)
595extern int _XData32(
596	     Display *dpy,
597	     register _Xconst long *data,
598	     unsigned len
599);
600extern void _XRead32(
601	     Display *dpy,
602	     register long *data,
603	     long len
604);
605#else
606#define Data32(dpy, data, len) Data((dpy), (_Xconst char *)(data), (len))
607#define _XRead32(dpy, data, len) _XRead((dpy), (char *)(data), (len))
608#endif
609
610#define PackData16(dpy,data,len) Data16 (dpy, data, len)
611#define PackData32(dpy,data,len) Data32 (dpy, data, len)
612
613/* Xlib manual is bogus */
614#define PackData(dpy,data,len) PackData16 (dpy, data, len)
615
616#define min(a,b) (((a) < (b)) ? (a) : (b))
617#define max(a,b) (((a) > (b)) ? (a) : (b))
618
619#define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
620			     (((cs)->rbearing|(cs)->lbearing| \
621			       (cs)->ascent|(cs)->descent) == 0))
622
623/*
624 * CI_GET_CHAR_INFO_1D - return the charinfo struct for the indicated 8bit
625 * character.  If the character is in the column and exists, then return the
626 * appropriate metrics (note that fonts with common per-character metrics will
627 * return min_bounds).  If none of these hold true, try again with the default
628 * char.
629 */
630#define CI_GET_CHAR_INFO_1D(fs,col,def,cs) \
631{ \
632    cs = def; \
633    if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
634	if (fs->per_char == NULL) { \
635	    cs = &fs->min_bounds; \
636	} else { \
637	    cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
638	    if (CI_NONEXISTCHAR(cs)) cs = def; \
639	} \
640    } \
641}
642
643#define CI_GET_DEFAULT_INFO_1D(fs,cs) \
644  CI_GET_CHAR_INFO_1D (fs, fs->default_char, NULL, cs)
645
646
647
648/*
649 * CI_GET_CHAR_INFO_2D - return the charinfo struct for the indicated row and
650 * column.  This is used for fonts that have more than row zero.
651 */
652#define CI_GET_CHAR_INFO_2D(fs,row,col,def,cs) \
653{ \
654    cs = def; \
655    if (row >= fs->min_byte1 && row <= fs->max_byte1 && \
656	col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
657	if (fs->per_char == NULL) { \
658	    cs = &fs->min_bounds; \
659	} else { \
660	    cs = &fs->per_char[((row - fs->min_byte1) * \
661			        (fs->max_char_or_byte2 - \
662				 fs->min_char_or_byte2 + 1)) + \
663			       (col - fs->min_char_or_byte2)]; \
664	    if (CI_NONEXISTCHAR(cs)) cs = def; \
665        } \
666    } \
667}
668
669#define CI_GET_DEFAULT_INFO_2D(fs,cs) \
670{ \
671    unsigned int r = (fs->default_char >> 8); \
672    unsigned int c = (fs->default_char & 0xff); \
673    CI_GET_CHAR_INFO_2D (fs, r, c, NULL, cs); \
674}
675
676
677/* srcvar must be a variable for large architecture version */
678#define OneDataCard32(dpy,dstaddr,srcvar) \
679  { *(CARD32 *)(dstaddr) = (srcvar); }
680
681
682typedef struct _XInternalAsync {
683    struct _XInternalAsync *next;
684    /*
685     * handler arguments:
686     * rep is the generic reply that caused this handler
687     * to be invoked.  It must also be passed to _XGetAsyncReply.
688     * buf and len are opaque values that must be passed to
689     * _XGetAsyncReply or _XGetAsyncData.
690     * data is the closure stored in this struct.
691     * The handler returns True iff it handled this reply.
692     */
693    Bool (*handler)(
694		    Display*	/* dpy */,
695		    xReply*	/* rep */,
696		    char*	/* buf */,
697		    int		/* len */,
698		    XPointer	/* data */
699		    );
700    XPointer data;
701} _XAsyncHandler;
702
703typedef struct _XAsyncEState {
704    unsigned long min_sequence_number;
705    unsigned long max_sequence_number;
706    unsigned char error_code;
707    unsigned char major_opcode;
708    unsigned short minor_opcode;
709    unsigned char last_error_received;
710    int error_count;
711} _XAsyncErrorState;
712
713extern void _XDeqAsyncHandler(Display *dpy, _XAsyncHandler *handler);
714#define DeqAsyncHandler(dpy,handler) { \
715    if (dpy->async_handlers == (handler)) \
716	dpy->async_handlers = (handler)->next; \
717    else \
718	_XDeqAsyncHandler(dpy, handler); \
719    }
720
721typedef void (*FreeFuncType) (
722    Display*	/* display */
723);
724
725typedef int (*FreeModmapType) (
726    XModifierKeymap*	/* modmap */
727);
728
729/*
730 * This structure is private to the library.
731 */
732typedef struct _XFreeFuncs {
733    FreeFuncType atoms;		/* _XFreeAtomTable */
734    FreeModmapType modifiermap;	/* XFreeModifiermap */
735    FreeFuncType key_bindings;	/* _XFreeKeyBindings */
736    FreeFuncType context_db;	/* _XFreeContextDB */
737    FreeFuncType defaultCCCs;	/* _XcmsFreeDefaultCCCs */
738    FreeFuncType clientCmaps;	/* _XcmsFreeClientCmaps */
739    FreeFuncType intensityMaps;	/* _XcmsFreeIntensityMaps */
740    FreeFuncType im_filters;	/* _XFreeIMFilters */
741    FreeFuncType xkb;		/* _XkbFreeInfo */
742} _XFreeFuncRec;
743
744/* types for InitExt.c */
745typedef int (*CreateGCType) (
746    Display*	/* display */,
747    GC		/* gc */,
748    XExtCodes*	/* codes */
749);
750
751typedef int (*CopyGCType)(
752    Display*	/* display */,
753    GC		/* gc */,
754    XExtCodes*	/* codes */
755);
756
757typedef int (*FlushGCType) (
758    Display*	/* display */,
759    GC		/* gc */,
760    XExtCodes*	/* codes */
761);
762
763typedef int (*FreeGCType) (
764    Display*	/* display */,
765    GC		/* gc */,
766    XExtCodes*	/* codes */
767);
768
769typedef int (*CreateFontType) (
770    Display*	/* display */,
771    XFontStruct* /* fs */,
772    XExtCodes*	/* codes */
773);
774
775typedef int (*FreeFontType) (
776    Display*	/* display */,
777    XFontStruct* /* fs */,
778    XExtCodes*	/* codes */
779);
780
781typedef int (*CloseDisplayType) (
782    Display*	/* display */,
783    XExtCodes*	/* codes */
784);
785
786typedef int (*ErrorType) (
787    Display*	/* display */,
788    xError*	/* err */,
789    XExtCodes*	/* codes */,
790    int*	/* ret_code */
791);
792
793typedef char* (*ErrorStringType) (
794    Display*	/* display */,
795    int		/* code */,
796    XExtCodes*	/* codes */,
797    char*	/* buffer */,
798    int		/* nbytes */
799);
800
801typedef void (*PrintErrorType)(
802    Display*	/* display */,
803    XErrorEvent* /* ev */,
804    void*	/* fp */
805);
806
807typedef void (*BeforeFlushType)(
808    Display*	/* display */,
809    XExtCodes*	/* codes */,
810    _Xconst char* /* data */,
811    long	/* len */
812);
813
814/*
815 * This structure is private to the library.
816 */
817typedef struct _XExten {		/* private to extension mechanism */
818	struct _XExten *next;		/* next in list */
819	XExtCodes codes;		/* public information, all extension told */
820	CreateGCType create_GC;		/* routine to call when GC created */
821	CopyGCType copy_GC;		/* routine to call when GC copied */
822	FlushGCType flush_GC;		/* routine to call when GC flushed */
823	FreeGCType free_GC;		/* routine to call when GC freed */
824	CreateFontType create_Font;	/* routine to call when Font created */
825	FreeFontType free_Font;		/* routine to call when Font freed */
826	CloseDisplayType close_display;	/* routine to call when connection closed */
827	ErrorType error;		/* who to call when an error occurs */
828	ErrorStringType error_string;	/* routine to supply error string */
829	char *name;			/* name of this extension */
830	PrintErrorType error_values;	/* routine to supply error values */
831	BeforeFlushType before_flush;	/* routine to call when sending data */
832	struct _XExten *next_flush;	/* next in list of those with flushes */
833} _XExtension;
834
835/* Temporary definition until we can depend on an xproto release with it */
836#ifdef _X_COLD
837# define _XLIB_COLD _X_COLD
838#elif defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403) /* 4.3+ */
839# define _XLIB_COLD __attribute__((__cold__))
840#else
841# define _XLIB_COLD /* nothing */
842#endif
843
844/* extension hooks */
845
846#ifdef DataRoutineIsProcedure
847extern void Data(Display *dpy, char *data, long len);
848#endif
849extern int _XError(
850    Display*	/* dpy */,
851    xError*	/* rep */
852);
853extern int _XIOError(
854    Display*	/* dpy */
855) _X_NORETURN;
856extern int (*_XIOErrorFunction)(
857    Display*	/* dpy */
858);
859extern int (*_XErrorFunction)(
860    Display*		/* dpy */,
861    XErrorEvent*	/* error_event */
862);
863extern void _XEatData(
864    Display*		/* dpy */,
865    unsigned long	/* n */
866) _XLIB_COLD;
867extern void _XEatDataWords(
868    Display*		/* dpy */,
869    unsigned long	/* n */
870) _XLIB_COLD;
871#if defined(__SUNPRO_C) /* Studio compiler alternative to "cold" attribute */
872# pragma rarely_called(_XEatData, _XEatDataWords)
873#endif
874extern char *_XAllocScratch(
875    Display*		/* dpy */,
876    unsigned long	/* nbytes */
877);
878extern char *_XAllocTemp(
879    Display*		/* dpy */,
880    unsigned long	/* nbytes */
881);
882extern void _XFreeTemp(
883    Display*		/* dpy */,
884    char*		/* buf */,
885    unsigned long	/* nbytes */
886);
887extern Visual *_XVIDtoVisual(
888    Display*	/* dpy */,
889    VisualID	/* id */
890);
891extern unsigned long _XSetLastRequestRead(
892    Display*		/* dpy */,
893    xGenericReply*	/* rep */
894);
895extern int _XGetHostname(
896    char*	/* buf */,
897    int		/* maxlen */
898);
899extern Screen *_XScreenOfWindow(
900    Display*	/* dpy */,
901    Window	/* w */
902);
903extern Bool _XAsyncErrorHandler(
904    Display*	/* dpy */,
905    xReply*	/* rep */,
906    char*	/* buf */,
907    int		/* len */,
908    XPointer	/* data */
909);
910extern char *_XGetAsyncReply(
911    Display*	/* dpy */,
912    char*	/* replbuf */,
913    xReply*	/* rep */,
914    char*	/* buf */,
915    int		/* len */,
916    int		/* extra */,
917    Bool	/* discard */
918);
919extern void _XGetAsyncData(
920    Display*	/* dpy */,
921    char *	/* data */,
922    char *	/* buf */,
923    int		/* len */,
924    int		/* skip */,
925    int		/* datalen */,
926    int		/* discardtotal */
927);
928extern void _XFlush(
929    Display*	/* dpy */
930);
931extern int _XEventsQueued(
932    Display*	/* dpy */,
933    int 	/* mode */
934);
935extern void _XReadEvents(
936    Display*	/* dpy */
937);
938extern int _XRead(
939    Display*	/* dpy */,
940    char*	/* data */,
941    long	/* size */
942);
943extern void _XReadPad(
944    Display*	/* dpy */,
945    char*	/* data */,
946    long	/* size */
947);
948extern void _XSend(
949    Display*		/* dpy */,
950    _Xconst char*	/* data */,
951    long		/* size */
952);
953extern Status _XReply(
954    Display*	/* dpy */,
955    xReply*	/* rep */,
956    int		/* extra */,
957    Bool	/* discard */
958);
959extern void _XEnq(
960    Display*	/* dpy */,
961    xEvent*	/* event */
962);
963extern void _XDeq(
964    Display*	/* dpy */,
965    _XQEvent*	/* prev */,
966    _XQEvent*	/* qelt */
967);
968
969extern Bool _XUnknownWireEvent(
970    Display*	/* dpy */,
971    XEvent*	/* re */,
972    xEvent*	/* event */
973);
974
975extern Bool _XUnknownWireEventCookie(
976    Display*	/* dpy */,
977    XGenericEventCookie*	/* re */,
978    xEvent*	/* event */
979);
980
981extern Bool _XUnknownCopyEventCookie(
982    Display*	/* dpy */,
983    XGenericEventCookie*	/* in */,
984    XGenericEventCookie*	/* out */
985);
986
987extern Status _XUnknownNativeEvent(
988    Display*	/* dpy */,
989    XEvent*	/* re */,
990    xEvent*	/* event */
991);
992
993extern Bool _XWireToEvent(Display *dpy, XEvent *re, xEvent *event);
994extern Bool _XDefaultWireError(Display *display, XErrorEvent *he, xError *we);
995extern Bool _XPollfdCacheInit(Display *dpy);
996extern void _XPollfdCacheAdd(Display *dpy, int fd);
997extern void _XPollfdCacheDel(Display *dpy, int fd);
998extern XID _XAllocID(Display *dpy);
999extern void _XAllocIDs(Display *dpy, XID *ids, int count);
1000
1001extern int _XFreeExtData(
1002    XExtData*	/* extension */
1003);
1004
1005extern int (*XESetCreateGC(
1006    Display*		/* display */,
1007    int			/* extension */,
1008    int (*) (
1009	      Display*			/* display */,
1010	      GC			/* gc */,
1011	      XExtCodes*		/* codes */
1012	    )		/* proc */
1013))(
1014    Display*, GC, XExtCodes*
1015);
1016
1017extern int (*XESetCopyGC(
1018    Display*		/* display */,
1019    int			/* extension */,
1020    int (*) (
1021	      Display*			/* display */,
1022              GC			/* gc */,
1023              XExtCodes*		/* codes */
1024            )		/* proc */
1025))(
1026    Display*, GC, XExtCodes*
1027);
1028
1029extern int (*XESetFlushGC(
1030    Display*		/* display */,
1031    int			/* extension */,
1032    int (*) (
1033	      Display*			/* display */,
1034              GC			/* gc */,
1035              XExtCodes*		/* codes */
1036            )		/* proc */
1037))(
1038    Display*, GC, XExtCodes*
1039);
1040
1041extern int (*XESetFreeGC(
1042    Display*		/* display */,
1043    int			/* extension */,
1044    int (*) (
1045	      Display*			/* display */,
1046              GC			/* gc */,
1047              XExtCodes*		/* codes */
1048            )		/* proc */
1049))(
1050    Display*, GC, XExtCodes*
1051);
1052
1053extern int (*XESetCreateFont(
1054    Display*		/* display */,
1055    int			/* extension */,
1056    int (*) (
1057	      Display*			/* display */,
1058              XFontStruct*		/* fs */,
1059              XExtCodes*		/* codes */
1060            )		/* proc */
1061))(
1062    Display*, XFontStruct*, XExtCodes*
1063);
1064
1065extern int (*XESetFreeFont(
1066    Display*		/* display */,
1067    int			/* extension */,
1068    int (*) (
1069	      Display*			/* display */,
1070              XFontStruct*		/* fs */,
1071              XExtCodes*		/* codes */
1072            )		/* proc */
1073))(
1074    Display*, XFontStruct*, XExtCodes*
1075);
1076
1077extern int (*XESetCloseDisplay(
1078    Display*		/* display */,
1079    int			/* extension */,
1080    int (*) (
1081	      Display*			/* display */,
1082              XExtCodes*		/* codes */
1083            )		/* proc */
1084))(
1085    Display*, XExtCodes*
1086);
1087
1088extern int (*XESetError(
1089    Display*		/* display */,
1090    int			/* extension */,
1091    int (*) (
1092	      Display*			/* display */,
1093              xError*			/* err */,
1094              XExtCodes*		/* codes */,
1095              int*			/* ret_code */
1096            )		/* proc */
1097))(
1098    Display*, xError*, XExtCodes*, int*
1099);
1100
1101extern char* (*XESetErrorString(
1102    Display*		/* display */,
1103    int			/* extension */,
1104    char* (*) (
1105	        Display*		/* display */,
1106                int			/* code */,
1107                XExtCodes*		/* codes */,
1108                char*			/* buffer */,
1109                int			/* nbytes */
1110              )		/* proc */
1111))(
1112    Display*, int, XExtCodes*, char*, int
1113);
1114
1115extern void (*XESetPrintErrorValues (
1116    Display*		/* display */,
1117    int			/* extension */,
1118    void (*)(
1119	      Display*			/* display */,
1120	      XErrorEvent*		/* ev */,
1121	      void*			/* fp */
1122	     )		/* proc */
1123))(
1124    Display*, XErrorEvent*, void*
1125);
1126
1127extern Bool (*XESetWireToEvent(
1128    Display*		/* display */,
1129    int			/* event_number */,
1130    Bool (*) (
1131	       Display*			/* display */,
1132               XEvent*			/* re */,
1133               xEvent*			/* event */
1134             )		/* proc */
1135))(
1136    Display*, XEvent*, xEvent*
1137);
1138
1139extern Bool (*XESetWireToEventCookie(
1140    Display*		/* display */,
1141    int			/* extension */,
1142    Bool (*) (
1143	       Display*			/* display */,
1144               XGenericEventCookie*	/* re */,
1145               xEvent*			/* event */
1146             )		/* proc */
1147))(
1148    Display*, XGenericEventCookie*, xEvent*
1149);
1150
1151extern Bool (*XESetCopyEventCookie(
1152    Display*		/* display */,
1153    int			/* extension */,
1154    Bool (*) (
1155	       Display*			/* display */,
1156               XGenericEventCookie*	/* in */,
1157               XGenericEventCookie*	/* out */
1158             )		/* proc */
1159))(
1160    Display*, XGenericEventCookie*, XGenericEventCookie*
1161);
1162
1163
1164extern Status (*XESetEventToWire(
1165    Display*		/* display */,
1166    int			/* event_number */,
1167    Status (*) (
1168	      Display*			/* display */,
1169              XEvent*			/* re */,
1170              xEvent*			/* event */
1171            )		/* proc */
1172))(
1173    Display*, XEvent*, xEvent*
1174);
1175
1176extern Bool (*XESetWireToError(
1177    Display*		/* display */,
1178    int			/* error_number */,
1179    Bool (*) (
1180	       Display*			/* display */,
1181	       XErrorEvent*		/* he */,
1182	       xError*			/* we */
1183            )		/* proc */
1184))(
1185    Display*, XErrorEvent*, xError*
1186);
1187
1188extern void (*XESetBeforeFlush(
1189    Display*		/* display */,
1190    int			/* error_number */,
1191    void (*) (
1192	       Display*			/* display */,
1193	       XExtCodes*		/* codes */,
1194	       _Xconst char*		/* data */,
1195	       long			/* len */
1196            )		/* proc */
1197))(
1198    Display*, XExtCodes*, _Xconst char*, long
1199);
1200
1201/* internal connections for IMs */
1202
1203typedef void (*_XInternalConnectionProc)(
1204    Display*			/* dpy */,
1205    int				/* fd */,
1206    XPointer			/* call_data */
1207);
1208
1209
1210extern Status _XRegisterInternalConnection(
1211    Display*			/* dpy */,
1212    int				/* fd */,
1213    _XInternalConnectionProc	/* callback */,
1214    XPointer			/* call_data */
1215);
1216
1217extern void _XUnregisterInternalConnection(
1218    Display*			/* dpy */,
1219    int				/* fd */
1220);
1221
1222extern void _XProcessInternalConnection(
1223    Display*			/* dpy */,
1224    struct _XConnectionInfo*	/* conn_info */
1225);
1226
1227/* Display structure has pointers to these */
1228
1229struct _XConnectionInfo {	/* info from _XRegisterInternalConnection */
1230    int fd;
1231    _XInternalConnectionProc read_callback;
1232    XPointer call_data;
1233    XPointer *watch_data;	/* set/used by XConnectionWatchProc */
1234    struct _XConnectionInfo *next;
1235};
1236
1237struct _XConnWatchInfo {	/* info from XAddConnectionWatch */
1238    XConnectionWatchProc fn;
1239    XPointer client_data;
1240    struct _XConnWatchInfo *next;
1241};
1242
1243#ifdef __UNIXOS2__
1244extern char* __XOS2RedirRoot(
1245    char*
1246);
1247#endif
1248
1249extern int _XTextHeight(
1250    XFontStruct*	/* font_struct */,
1251    _Xconst char*	/* string */,
1252    int			/* count */
1253);
1254
1255extern int _XTextHeight16(
1256    XFontStruct*	/* font_struct */,
1257    _Xconst XChar2b*	/* string */,
1258    int			/* count */
1259);
1260
1261#if defined(WIN32)
1262
1263extern int _XOpenFile(
1264    _Xconst char*	/* path */,
1265    int			/* flags */
1266);
1267
1268extern int _XOpenFileMode(
1269    _Xconst char*	/* path */,
1270    int			/* flags */,
1271    mode_t              /* mode */
1272);
1273
1274extern void* _XFopenFile(
1275    _Xconst char*	/* path */,
1276    _Xconst char*	/* mode */
1277);
1278
1279extern int _XAccessFile(
1280    _Xconst char*	/* path */
1281);
1282#else
1283#define _XOpenFile(path,flags) open(path,flags)
1284#define _XOpenFileMode(path,flags,mode) open(path,flags,mode)
1285#define _XFopenFile(path,mode) fopen(path,mode)
1286#endif
1287
1288/* EvToWire.c */
1289extern Status _XEventToWire(Display *dpy, XEvent *re, xEvent *event);
1290
1291extern int _XF86LoadQueryLocaleFont(
1292    Display*		/* dpy */,
1293    _Xconst char*	/* name*/,
1294    XFontStruct**	/* xfp*/,
1295    Font*		/* fidp */
1296);
1297
1298extern void _XProcessWindowAttributes (
1299    register Display *dpy,
1300    xChangeWindowAttributesReq *req,
1301    register unsigned long valuemask,
1302    register XSetWindowAttributes *attributes);
1303
1304extern int _XDefaultError(
1305        Display *dpy,
1306        XErrorEvent *event);
1307
1308extern int _XDefaultIOError(
1309        Display *dpy);
1310
1311extern void _XSetClipRectangles (
1312    register Display *dpy,
1313    GC gc,
1314    int clip_x_origin, int clip_y_origin,
1315    XRectangle *rectangles,
1316    int n,
1317    int ordering);
1318
1319Status _XGetWindowAttributes(
1320    register Display *dpy,
1321    Window w,
1322    XWindowAttributes *attr);
1323
1324int _XPutBackEvent (
1325    register Display *dpy,
1326    register XEvent *event);
1327
1328extern Bool _XIsEventCookie(
1329        Display *dpy,
1330        XEvent *ev);
1331
1332extern void _XFreeEventCookies(
1333        Display *dpy);
1334
1335extern void _XStoreEventCookie(
1336        Display *dpy,
1337        XEvent *ev);
1338
1339extern Bool _XFetchEventCookie(
1340        Display *dpy,
1341        XGenericEventCookie *ev);
1342
1343extern Bool _XCopyEventCookie(
1344        Display *dpy,
1345        XGenericEventCookie *in,
1346        XGenericEventCookie *out);
1347
1348/* lcFile.c */
1349
1350extern void xlocaledir(
1351    char *buf,
1352    int buf_len
1353);
1354
1355#ifdef __clang__
1356#pragma clang diagnostic pop
1357#endif
1358
1359_XFUNCPROTOEND
1360
1361#endif /* _X11_XLIBINT_H_ */
1362