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