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