_fallibint.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* Xlibint.h 1.2 - Fujitsu source for CDEnext 95/12/07 10:53:12 */
  24. /* $XConsortium: _fallibint.h /main/1 1996/04/08 15:21:22 cde-fuj $ */
  25. /*
  26. Copyright (c) 1984, 1985, 1987, 1989 X Consortium
  27. Permission is hereby granted, free of charge, to any person obtaining
  28. a copy of this software and associated documentation files (the
  29. "Software"), to deal in the Software without restriction, including
  30. without limitation the rights to use, copy, modify, merge, publish,
  31. distribute, sublicense, and/or sell copies of the Software, and to
  32. permit persons to whom the Software is furnished to do so, subject to
  33. the following conditions:
  34. The above copyright notice and this permission notice shall be included
  35. in all copies or substantial portions of the Software.
  36. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  37. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  38. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  39. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  40. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  41. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  42. OTHER DEALINGS IN THE SOFTWARE.
  43. Except as contained in this notice, the name of the X Consortium shall
  44. not be used in advertising or otherwise to promote the sale, use or
  45. other dealings in this Software without prior written authorization
  46. from the X Consortium.
  47. */
  48. /*
  49. * Xlibint.h - Header definition and support file for the internal
  50. * support routines used by the C subroutine interface
  51. * library (Xlib) to the X Window System.
  52. *
  53. * Warning, there be dragons here....
  54. */
  55. /*
  56. * Copyright 1995 by FUJITSU LIMITED
  57. * This is source code modified by FUJITSU LIMITED under the Joint
  58. * Development Agreement for the CDEnext PST.
  59. * This is unpublished proprietry source code of FUJITSU LIMITED
  60. *
  61. * Modifier: Takanori Tateno FUJITSU LIMITED
  62. *
  63. */
  64. #if !defined(NEED_EVENTS) && !NeedFunctionPrototypes
  65. #define _XEVENT_
  66. #endif
  67. #include "syncx.h"
  68. struct _XGC
  69. {
  70. XExtData *ext_data; /* hook for extension to hang data */
  71. GContext gid; /* protocol ID for graphics context */
  72. Bool rects; /* boolean: TRUE if clipmask is list of rectangles */
  73. Bool dashes; /* boolean: TRUE if dash-list is really a list */
  74. unsigned long dirty;/* cache dirty bits */
  75. XGCValues values; /* shadow structure of values */
  76. };
  77. struct _XDisplay
  78. {
  79. XExtData *ext_data; /* hook for extension to hang data */
  80. struct _XFreeFuncs *free_funcs; /* internal free functions */
  81. int fd; /* Network socket. */
  82. int conn_checker; /* ugly thing used by _XEventsQueued */
  83. int proto_major_version;/* maj. version of server's X protocol */
  84. int proto_minor_version;/* minor version of server's X protocol */
  85. char *vendor; /* vendor of the server hardware */
  86. XID resource_base; /* resource ID base */
  87. XID resource_mask; /* resource ID mask bits */
  88. XID resource_id; /* allocator current ID */
  89. int resource_shift; /* allocator shift to correct bits */
  90. XID (*resource_alloc)(); /* allocator function */
  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. char *display_name; /* "host:display" string used on this connect*/
  111. int default_screen; /* default screen for operations */
  112. int nscreens; /* number of screens on this server*/
  113. Screen *screens; /* pointer to list of screens */
  114. unsigned long motion_buffer; /* size of motion buffer */
  115. unsigned long flags; /* internal connection flags */
  116. int min_keycode; /* minimum defined keycode */
  117. int max_keycode; /* maximum defined keycode */
  118. KeySym *keysyms; /* This server's keysyms */
  119. XModifierKeymap *modifiermap; /* This server's modifier keymap */
  120. int keysyms_per_keycode;/* number of rows */
  121. char *xdefaults; /* contents of defaults from server */
  122. char *scratch_buffer; /* place to hang scratch buffer */
  123. unsigned long scratch_length; /* length of scratch buffer */
  124. int ext_number; /* extension number on this display */
  125. struct _XExten *ext_procs; /* extensions initialized on this display */
  126. /*
  127. * the following can be fixed size, as the protocol defines how
  128. * much address space is available.
  129. * While this could be done using the extension vector, there
  130. * may be MANY events processed, so a search through the extension
  131. * list to find the right procedure for each event might be
  132. * expensive if many extensions are being used.
  133. */
  134. Bool (*event_vec[128])(); /* vector for wire to event */
  135. Status (*wire_vec[128])(); /* vector for event to wire */
  136. KeySym lock_meaning; /* for XLookupString */
  137. struct _XLockInfo *lock; /* multi-thread state, display lock */
  138. struct _XInternalAsync *async_handlers; /* for internal async */
  139. unsigned long bigreq_size; /* max size of big requests */
  140. struct _XLockPtrs *lock_fns; /* pointers to threads functions */
  141. void (*idlist_alloc)(); /* XID list allocator function */
  142. /* things above this line should not move, for binary compatibility */
  143. struct _XKeytrans *key_bindings; /* for XLookupString */
  144. Font cursor_font; /* for XCreateFontCursor */
  145. struct _XDisplayAtoms *atoms; /* for falInternAtom */
  146. unsigned int mode_switch; /* keyboard group modifiers */
  147. unsigned int num_lock; /* keyboard numlock modifiers */
  148. struct _XContextDB *context_db; /* context database */
  149. Bool (**error_vec)(); /* vector for wire to error */
  150. /*
  151. * Xcms information
  152. */
  153. struct {
  154. XPointer defaultCCCs; /* pointer to an array of default XcmsCCC */
  155. XPointer clientCmaps; /* pointer to linked list of XcmsCmapRec */
  156. XPointer perVisualIntensityMaps;
  157. /* linked list of XcmsIntensityMap */
  158. } cms;
  159. struct _XIMFilter *im_filters;
  160. struct _XSQEvent *qfree; /* unallocated event queue elements */
  161. unsigned long next_event_serial_num; /* inserted into next queue elt */
  162. struct _XExten *flushes; /* Flush hooks */
  163. struct _XConnectionInfo *im_fd_info; /* _XRegisterInternalConnection */
  164. int im_fd_length; /* number of im_fd_info */
  165. struct _XConnWatchInfo *conn_watchers; /* XAddConnectionWatch */
  166. int watcher_count; /* number of conn_watchers */
  167. XPointer filedes; /* struct pollfd cache for _XWaitForReadable */
  168. int (*savedsynchandler)(); /* user synchandler when Xlib usurps */
  169. XID resource_max; /* allocator max ID */
  170. int xcmisc_opcode; /* major opcode for XC-MISC */
  171. struct _XkbInfoRec *xkb_info; /* XKB info */
  172. struct _XtransConnInfo *trans_conn; /* transport connection object */
  173. };
  174. #define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
  175. /*
  176. * define DataRoutineIsProcedure if you want the Data macro to be a procedure
  177. * instead
  178. */
  179. #ifndef _XEVENT_
  180. /*
  181. * _QEvent datatype for use in input queueing.
  182. */
  183. typedef struct _XSQEvent
  184. {
  185. struct _XSQEvent *next;
  186. XEvent event;
  187. unsigned long qserial_num; /* so multi-threaded code can find new ones */
  188. } _XQEvent;
  189. #endif
  190. #ifdef XTHREADS /* for xReply */
  191. #define NEED_REPLIES
  192. #endif
  193. #define NEED_EVENTS
  194. #define NEED_REPLIES
  195. #include <X11/Xproto.h>
  196. #include <errno.h>
  197. #define _XBCOPYFUNC _Xbcopy
  198. #include <X11/Xfuncs.h>
  199. #include <X11/Xosdefs.h>
  200. #ifndef X_NOT_STDC_ENV
  201. #include <stdlib.h>
  202. #include <string.h>
  203. #else
  204. char *malloc(), *realloc(), *calloc();
  205. void exit();
  206. #ifdef SYSV
  207. #include <string.h>
  208. #else
  209. #include <strings.h>
  210. #endif
  211. #endif
  212. /*
  213. * The following definitions can be used for locking requests in multi-threaded
  214. * address spaces.
  215. */
  216. #ifdef XTHREADS
  217. /* Author: Stephen Gildea, MIT X Consortium
  218. *
  219. * declarations for C Threads locking
  220. */
  221. #include <X11/Xfuncproto.h>
  222. struct _XLockPtrs {
  223. /* used by all, including extensions; do not move */
  224. void (*lock_display)();
  225. void (*unlock_display)();
  226. };
  227. typedef struct _LockInfoRec *LockInfoPtr;
  228. /* in XlibInt.c */
  229. extern void (*_XCreateMutex_fn)(
  230. LockInfoPtr /* lock */
  231. );
  232. extern void (*_XFreeMutex_fn)(
  233. LockInfoPtr /* lock */
  234. );
  235. extern void (*_XLockMutex_fn)(
  236. LockInfoPtr /* lock */
  237. #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
  238. , char * /* file */
  239. , int /* line */
  240. #endif
  241. );
  242. extern void (*_XUnlockMutex_fn)(
  243. LockInfoPtr /* lock */
  244. #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
  245. , char * /* file */
  246. , int /* line */
  247. #endif
  248. );
  249. extern LockInfoPtr _Xglobal_lock;
  250. #if defined(XTHREADS_WARN) || defined(XTHREADS_FILE_LINE)
  251. #define LockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->lock_display)((d),__FILE__,__LINE__)
  252. #define UnlockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)((d),__FILE__,__LINE__)
  253. #define _XLockMutex(lock) if (_XLockMutex_fn) (*_XLockMutex_fn)(lock,__FILE__,__LINE__)
  254. #define _XUnlockMutex(lock) if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock,__FILE__,__LINE__)
  255. #else
  256. /* used everywhere, so must be fast if not using threads */
  257. #define LockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->lock_display)(d)
  258. #define UnlockDisplay(d) if ((d)->lock_fns) (*(d)->lock_fns->unlock_display)(d)
  259. #define _XLockMutex(lock) if (_XLockMutex_fn) (*_XLockMutex_fn)(lock)
  260. #define _XUnlockMutex(lock) if (_XUnlockMutex_fn) (*_XUnlockMutex_fn)(lock)
  261. #endif
  262. #define _XCreateMutex(lock) if (_XCreateMutex_fn) (*_XCreateMutex_fn)(lock);
  263. #define _XFreeMutex(lock) if (_XFreeMutex_fn) (*_XFreeMutex_fn)(lock);
  264. #else /* XTHREADS */
  265. #define LockDisplay(dis)
  266. #define _XLockMutex(lock)
  267. #define _XUnlockMutex(lock)
  268. #define UnlockDisplay(dis)
  269. #define _XCreateMutex(lock)
  270. #define _XFreeMutex(lock)
  271. #endif
  272. #define Xfree(ptr) free((ptr))
  273. /*
  274. * Note that some machines do not return a valid pointer for malloc(0), in
  275. * which case we provide an alternate under the control of the
  276. * define MALLOC_0_RETURNS_NULL. This is necessary because some
  277. * Xlib code expects malloc(0) to return a valid pointer to storage.
  278. */
  279. #ifdef MALLOC_0_RETURNS_NULL
  280. # define Xmalloc(size) malloc(((size) == 0 ? 1 : (size)))
  281. # define Xrealloc(ptr, size) realloc((ptr), ((size) == 0 ? 1 : (size)))
  282. # define Xcalloc(nelem, elsize) calloc(((nelem) == 0 ? 1 : (nelem)), (elsize))
  283. #else
  284. # define Xmalloc(size) malloc((size))
  285. # define Xrealloc(ptr, size) realloc((ptr), (size))
  286. # define Xcalloc(nelem, elsize) calloc((nelem), (elsize))
  287. #endif
  288. #define LOCKED 1
  289. #define UNLOCKED 0
  290. #ifdef X_NOT_STDC_ENV
  291. extern int errno; /* Internal system error number. */
  292. #endif
  293. #ifndef BUFSIZE
  294. #define BUFSIZE 2048 /* X output buffer size. */
  295. #endif
  296. #ifndef PTSPERBATCH
  297. #define PTSPERBATCH 1024 /* point batching */
  298. #endif
  299. #ifndef WLNSPERBATCH
  300. #define WLNSPERBATCH 50 /* wide line batching */
  301. #endif
  302. #ifndef ZLNSPERBATCH
  303. #define ZLNSPERBATCH 1024 /* thin line batching */
  304. #endif
  305. #ifndef WRCTSPERBATCH
  306. #define WRCTSPERBATCH 10 /* wide line rectangle batching */
  307. #endif
  308. #ifndef ZRCTSPERBATCH
  309. #define ZRCTSPERBATCH 256 /* thin line rectangle batching */
  310. #endif
  311. #ifndef FRCTSPERBATCH
  312. #define FRCTSPERBATCH 256 /* filled rectangle batching */
  313. #endif
  314. #ifndef FARCSPERBATCH
  315. #define FARCSPERBATCH 256 /* filled arc batching */
  316. #endif
  317. #ifndef CURSORFONT
  318. #define CURSORFONT "cursor" /* standard cursor fonts */
  319. #endif
  320. /*
  321. * Display flags
  322. */
  323. #define XlibDisplayIOError (1L << 0)
  324. #define XlibDisplayClosing (1L << 1)
  325. #define XlibDisplayNoXkb (1L << 2)
  326. #define XlibDisplayPrivSync (1L << 3)
  327. #define XlibDisplayProcConni (1L << 4) /* in _XProcessInternalConnection */
  328. #define XlibDisplayReadEvents (1L << 5) /* in _XReadEvents */
  329. #define XlibDisplayReply (1L << 5) /* in _XReply */
  330. #define XlibDisplayWriting (1L << 6) /* in _XFlushInt, _XSend */
  331. /*
  332. * X Protocol packetizing macros.
  333. */
  334. #define WORD64ALIGN
  335. /*
  336. * GetReq - Get the next available X request packet in the buffer and
  337. * return it.
  338. *
  339. * "name" is the name of the request, e.g. CreatePixmap, OpenFont, etc.
  340. * "req" is the name of the request pointer.
  341. *
  342. */
  343. #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
  344. #define GetReq(name, req) \
  345. WORD64ALIGN\
  346. if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\
  347. _XFlush(dpy);\
  348. req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
  349. req->reqType = X_##name;\
  350. req->length = (SIZEOF(x##name##Req))>>2;\
  351. dpy->bufptr += SIZEOF(x##name##Req);\
  352. dpy->request++
  353. #else /* non-ANSI C uses empty comment instead of "##" for token concatenation */
  354. #define GetReq(name, req) \
  355. WORD64ALIGN\
  356. if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\
  357. _XFlush(dpy);\
  358. req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
  359. req->reqType = X_/**/name;\
  360. req->length = (SIZEOF(x/**/name/**/Req))>>2;\
  361. dpy->bufptr += SIZEOF(x/**/name/**/Req);\
  362. dpy->request++
  363. #endif
  364. /* GetReqExtra is the same as GetReq, but allocates "n" additional
  365. bytes after the request. "n" must be a multiple of 4! */
  366. #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
  367. #define GetReqExtra(name, n, req) \
  368. WORD64ALIGN\
  369. if ((dpy->bufptr + SIZEOF(x##name##Req) + n) > dpy->bufmax)\
  370. _XFlush(dpy);\
  371. req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
  372. req->reqType = X_##name;\
  373. req->length = (SIZEOF(x##name##Req) + n)>>2;\
  374. dpy->bufptr += SIZEOF(x##name##Req) + n;\
  375. dpy->request++
  376. #else
  377. #define GetReqExtra(name, n, req) \
  378. WORD64ALIGN\
  379. if ((dpy->bufptr + SIZEOF(x/**/name/**/Req) + n) > dpy->bufmax)\
  380. _XFlush(dpy);\
  381. req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
  382. req->reqType = X_/**/name;\
  383. req->length = (SIZEOF(x/**/name/**/Req) + n)>>2;\
  384. dpy->bufptr += SIZEOF(x/**/name/**/Req) + n;\
  385. dpy->request++
  386. #endif
  387. /*
  388. * GetResReq is for those requests that have a resource ID
  389. * (Window, Pixmap, GContext, etc.) as their single argument.
  390. * "rid" is the name of the resource.
  391. */
  392. #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
  393. #define GetResReq(name, rid, req) \
  394. WORD64ALIGN\
  395. if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\
  396. _XFlush(dpy);\
  397. req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\
  398. req->reqType = X_##name;\
  399. req->length = 2;\
  400. req->id = (rid);\
  401. dpy->bufptr += SIZEOF(xResourceReq);\
  402. dpy->request++
  403. #else
  404. #define GetResReq(name, rid, req) \
  405. WORD64ALIGN\
  406. if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\
  407. _XFlush(dpy);\
  408. req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\
  409. req->reqType = X_/**/name;\
  410. req->length = 2;\
  411. req->id = (rid);\
  412. dpy->bufptr += SIZEOF(xResourceReq);\
  413. dpy->request++
  414. #endif
  415. /*
  416. * GetEmptyReq is for those requests that have no arguments
  417. * at all.
  418. */
  419. #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
  420. #define GetEmptyReq(name, req) \
  421. WORD64ALIGN\
  422. if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\
  423. _XFlush(dpy);\
  424. req = (xReq *) (dpy->last_req = dpy->bufptr);\
  425. req->reqType = X_##name;\
  426. req->length = 1;\
  427. dpy->bufptr += SIZEOF(xReq);\
  428. dpy->request++
  429. #else
  430. #define GetEmptyReq(name, req) \
  431. WORD64ALIGN\
  432. if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\
  433. _XFlush(dpy);\
  434. req = (xReq *) (dpy->last_req = dpy->bufptr);\
  435. req->reqType = X_/**/name;\
  436. req->length = 1;\
  437. dpy->bufptr += SIZEOF(xReq);\
  438. dpy->request++
  439. #endif
  440. #define MakeBigReq(req,n) \
  441. { \
  442. long _BRdat; \
  443. unsigned long _BRlen = req->length - 1; \
  444. req->length = 0; \
  445. _BRdat = ((long *)req)[_BRlen]; \
  446. memmove(((char *)req) + 8, ((char *)req) + 4, _BRlen << 2); \
  447. ((unsigned long *)req)[1] = _BRlen + n + 2; \
  448. Data32(dpy, &_BRdat, 4); \
  449. }
  450. #define SetReqLen(req,n,badlen) \
  451. if ((req->length + n) > (unsigned)65535) { \
  452. if (dpy->bigreq_size) { \
  453. MakeBigReq(req,n) \
  454. } else { \
  455. n = badlen; \
  456. req->length += n; \
  457. } \
  458. } else \
  459. req->length += n
  460. #define SyncHandle() \
  461. if (dpy->synchandler) (*dpy->synchandler)(dpy)
  462. #define FlushGC(dpy, gc) \
  463. if ((gc)->dirty) _XFlushGCCache((dpy), (gc))
  464. /*
  465. * Data - Place data in the buffer and pad the end to provide
  466. * 32 bit word alignment. Transmit if the buffer fills.
  467. *
  468. * "dpy" is a pointer to a Display.
  469. * "data" is a pinter to a data buffer.
  470. * "len" is the length of the data buffer.
  471. */
  472. #ifndef DataRoutineIsProcedure
  473. #define Data(dpy, data, len) \
  474. if (dpy->bufptr + (len) <= dpy->bufmax) {\
  475. memcpy(dpy->bufptr, data, (int)len);\
  476. dpy->bufptr += ((len) + 3) & ~3;\
  477. } else\
  478. _XSend(dpy, data, len)
  479. #endif /* DataRoutineIsProcedure */
  480. /* Allocate bytes from the buffer. No padding is done, so if
  481. * the length is not a multiple of 4, the caller must be
  482. * careful to leave the buffer aligned after sending the
  483. * current request.
  484. *
  485. * "type" is the type of the pointer being assigned to.
  486. * "ptr" is the pointer being assigned to.
  487. * "n" is the number of bytes to allocate.
  488. *
  489. * Example:
  490. * xTextElt *elt;
  491. * BufAlloc (xTextElt *, elt, nbytes)
  492. */
  493. #define BufAlloc(type, ptr, n) \
  494. if (dpy->bufptr + (n) > dpy->bufmax) \
  495. _XFlush (dpy); \
  496. ptr = (type) dpy->bufptr; \
  497. dpy->bufptr += (n);
  498. #define Data16(dpy, data, len) Data((dpy), (char *)(data), (len))
  499. #define _XRead16Pad(dpy, data, len) _XReadPad((dpy), (char *)(data), (len))
  500. #define _XRead16(dpy, data, len) _XRead((dpy), (char *)(data), (len))
  501. #ifdef LONG64
  502. #define Data32(dpy, data, len) _XData32(dpy, (long *)data, len)
  503. #else
  504. #define Data32(dpy, data, len) Data((dpy), (char *)(data), (len))
  505. #define _XRead32(dpy, data, len) _XRead((dpy), (char *)(data), (len))
  506. #endif
  507. #define PackData16(dpy,data,len) Data16 (dpy, data, len)
  508. #define PackData32(dpy,data,len) Data32 (dpy, data, len)
  509. /* Xlib manual is bogus */
  510. #define PackData(dpy,data,len) PackData16 (dpy, data, len)
  511. #define min(a,b) (((a) < (b)) ? (a) : (b))
  512. #define max(a,b) (((a) > (b)) ? (a) : (b))
  513. #define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
  514. (((cs)->rbearing|(cs)->lbearing| \
  515. (cs)->ascent|(cs)->descent) == 0))
  516. /*
  517. * CI_GET_CHAR_INFO_1D - return the charinfo struct for the indicated 8bit
  518. * character. If the character is in the column and exists, then return the
  519. * appropriate metrics (note that fonts with common per-character metrics will
  520. * return min_bounds). If none of these hold true, try again with the default
  521. * char.
  522. */
  523. #define CI_GET_CHAR_INFO_1D(fs,col,def,cs) \
  524. { \
  525. cs = def; \
  526. if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
  527. if (fs->per_char == NULL) { \
  528. cs = &fs->min_bounds; \
  529. } else { \
  530. cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
  531. if (CI_NONEXISTCHAR(cs)) cs = def; \
  532. } \
  533. } \
  534. }
  535. #define CI_GET_DEFAULT_INFO_1D(fs,cs) \
  536. CI_GET_CHAR_INFO_1D (fs, fs->default_char, NULL, cs)
  537. /*
  538. * CI_GET_CHAR_INFO_2D - return the charinfo struct for the indicated row and
  539. * column. This is used for fonts that have more than row zero.
  540. */
  541. #define CI_GET_CHAR_INFO_2D(fs,row,col,def,cs) \
  542. { \
  543. cs = def; \
  544. if (row >= fs->min_byte1 && row <= fs->max_byte1 && \
  545. col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
  546. if (fs->per_char == NULL) { \
  547. cs = &fs->min_bounds; \
  548. } else { \
  549. cs = &fs->per_char[((row - fs->min_byte1) * \
  550. (fs->max_char_or_byte2 - \
  551. fs->min_char_or_byte2 + 1)) + \
  552. (col - fs->min_char_or_byte2)]; \
  553. if (CI_NONEXISTCHAR(cs)) cs = def; \
  554. } \
  555. } \
  556. }
  557. #define CI_GET_DEFAULT_INFO_2D(fs,cs) \
  558. { \
  559. unsigned int r = (fs->default_char >> 8); \
  560. unsigned int c = (fs->default_char & 0xff); \
  561. CI_GET_CHAR_INFO_2D (fs, r, c, NULL, cs); \
  562. }
  563. #ifdef MUSTCOPY
  564. /* for when 32-bit alignment is not good enough */
  565. #define OneDataCard32(dpy,dstaddr,srcvar) \
  566. { dpy->bufptr -= 4; Data32 (dpy, (char *) &(srcvar), 4); }
  567. #else
  568. /* srcvar must be a variable for large architecture version */
  569. #define OneDataCard32(dpy,dstaddr,srcvar) \
  570. { *(CARD32 *)(dstaddr) = (srcvar); }
  571. #endif /* MUSTCOPY */
  572. typedef struct _XInternalAsync {
  573. struct _XInternalAsync *next;
  574. Bool (*handler)();
  575. XPointer data;
  576. } _XAsyncHandler;
  577. typedef struct _XAsyncEState {
  578. unsigned long min_sequence_number;
  579. unsigned long max_sequence_number;
  580. unsigned char error_code;
  581. unsigned char major_opcode;
  582. unsigned short minor_opcode;
  583. unsigned char last_error_received;
  584. int error_count;
  585. } _XAsyncErrorState;
  586. #define DeqAsyncHandler(dpy,handler) { \
  587. if (dpy->async_handlers == (handler)) \
  588. dpy->async_handlers = (handler)->next; \
  589. else \
  590. _XDeqAsyncHandler(dpy, handler); \
  591. }
  592. /*
  593. * This structure is private to the library.
  594. */
  595. typedef struct _XFreeFuncs {
  596. void (*atoms)(); /* _XFreeAtomTable */
  597. int (*modifiermap)(); /* XFreeModifierMap */
  598. void (*key_bindings)(); /* _XFreeKeyBindings */
  599. void (*context_db)(); /* _XFreeContextDB */
  600. void (*defaultCCCs)(); /* _XcmsFreeDefaultCCCs */
  601. void (*clientCmaps)(); /* _XcmsFreeClientCmaps */
  602. void (*intensityMaps)(); /* _XcmsFreeIntensityMaps */
  603. void (*im_filters)(); /* _XFreeIMFilters */
  604. void (*xkb)(); /* _XkbFreeInfo */
  605. } _XFreeFuncRec;
  606. /*
  607. * This structure is private to the library.
  608. */
  609. typedef struct _XExten { /* private to extension mechanism */
  610. struct _XExten *next; /* next in list */
  611. XExtCodes codes; /* public information, all extension told */
  612. int (*create_GC)(); /* routine to call when GC created */
  613. int (*copy_GC)(); /* routine to call when GC copied */
  614. int (*flush_GC)(); /* routine to call when GC flushed */
  615. int (*free_GC)(); /* routine to call when GC freed */
  616. int (*create_Font)(); /* routine to call when Font created */
  617. int (*free_Font)(); /* routine to call when Font freed */
  618. int (*close_display)(); /* routine to call when connection closed */
  619. int (*error)(); /* who to call when an error occurs */
  620. char *(*error_string)(); /* routine to supply error string */
  621. char *name; /* name of this extension */
  622. void (*error_values)(); /* routine to supply error values */
  623. void (*before_flush)(); /* routine to call when sending data */
  624. struct _XExten *next_flush; /* next in list of those with flushes */
  625. } _XExtension;
  626. /* extension hooks */
  627. _XFUNCPROTOBEGIN
  628. #ifdef DataRoutineIsProcedure
  629. extern void Data();
  630. #endif
  631. extern int _XError(
  632. Display* /* dpy */,
  633. xError* /* rep */
  634. );
  635. extern int _XIOError(
  636. Display* /* dpy */
  637. );
  638. extern int (*_XIOErrorFunction)(
  639. Display* /* dpy */
  640. );
  641. extern int (*_XErrorFunction)(
  642. Display* /* dpy */,
  643. XErrorEvent* /* error_event */
  644. );
  645. extern void _XEatData(
  646. Display* /* dpy */,
  647. unsigned long /* n */
  648. );
  649. extern char *_XAllocScratch(
  650. Display* /* dpy */,
  651. unsigned long /* nbytes */
  652. );
  653. extern char *_XAllocTemp(
  654. Display* /* dpy */,
  655. unsigned long /* nbytes */
  656. );
  657. extern void _XFreeTemp(
  658. Display* /* dpy */,
  659. char* /* buf */,
  660. unsigned long /* nbytes */
  661. );
  662. extern Visual *_XVIDtoVisual(
  663. Display* /* dpy */,
  664. VisualID /* id */
  665. );
  666. extern unsigned long _XSetLastRequestRead(
  667. Display* /* dpy */,
  668. xGenericReply* /* rep */
  669. );
  670. extern int _XGetHostname(
  671. char* /* buf */,
  672. int /* maxlen */
  673. );
  674. extern Screen *_XScreenOfWindow(
  675. Display* /* dpy */,
  676. Window /* w */
  677. );
  678. extern Bool _XAsyncErrorHandler(
  679. Display* /* dpy */,
  680. xReply* /* rep */,
  681. char* /* buf */,
  682. int /* len */,
  683. XPointer /* data */
  684. );
  685. extern char *_XGetAsyncReply(
  686. Display* /* dpy */,
  687. char* /* replbuf */,
  688. xReply* /* rep */,
  689. char* /* buf */,
  690. int /* len */,
  691. int /* extra */,
  692. Bool /* discard */
  693. );
  694. extern _XFlush(
  695. Display* /* dpy */
  696. );
  697. extern int _XEventsQueued(
  698. Display* /* dpy */,
  699. int /* mode */
  700. );
  701. extern _XReadEvents(
  702. Display* /* dpy */
  703. );
  704. extern _XRead(
  705. Display* /* dpy */,
  706. char* /* data */,
  707. long /* size */
  708. );
  709. extern _XReadPad(
  710. Display* /* dpy */,
  711. char* /* data */,
  712. long /* size */
  713. );
  714. extern _XSend(
  715. Display* /* dpy */,
  716. const char* /* data */,
  717. long /* size */
  718. );
  719. extern Status _XReply(
  720. Display* /* dpy */,
  721. xReply* /* rep */,
  722. int /* extra */,
  723. Bool /* discard */
  724. );
  725. extern _XEnq(
  726. Display* /* dpy */,
  727. xEvent* /* event */
  728. );
  729. extern _XDeq(
  730. Display* /* dpy */,
  731. _XQEvent* /* prev */,
  732. _XQEvent* /* qelt */
  733. );
  734. extern int (*XESetCreateGC(
  735. Display* /* display */,
  736. int /* extension */,
  737. int (*) (
  738. Display* /* display */,
  739. GC /* gc */,
  740. XExtCodes* /* codes */
  741. ) /* proc */
  742. ))(
  743. Display*, GC, XExtCodes*
  744. );
  745. extern int (*XESetCopyGC(
  746. Display* /* display */,
  747. int /* extension */,
  748. int (*) (
  749. Display* /* display */,
  750. GC /* gc */,
  751. XExtCodes* /* codes */
  752. ) /* proc */
  753. ))(
  754. Display*, GC, XExtCodes*
  755. );
  756. extern int (*XESetFlushGC(
  757. Display* /* display */,
  758. int /* extension */,
  759. int (*) (
  760. Display* /* display */,
  761. GC /* gc */,
  762. XExtCodes* /* codes */
  763. ) /* proc */
  764. ))(
  765. Display*, GC, XExtCodes*
  766. );
  767. extern int (*XESetFreeGC(
  768. Display* /* display */,
  769. int /* extension */,
  770. int (*) (
  771. Display* /* display */,
  772. GC /* gc */,
  773. XExtCodes* /* codes */
  774. ) /* proc */
  775. ))(
  776. Display*, GC, XExtCodes*
  777. );
  778. extern int (*XESetCreateFont(
  779. Display* /* display */,
  780. int /* extension */,
  781. int (*) (
  782. Display* /* display */,
  783. XFontStruct* /* fs */,
  784. XExtCodes* /* codes */
  785. ) /* proc */
  786. ))(
  787. Display*, XFontStruct*, XExtCodes*
  788. );
  789. extern int (*XESetFreeFont(
  790. Display* /* display */,
  791. int /* extension */,
  792. int (*) (
  793. Display* /* display */,
  794. XFontStruct* /* fs */,
  795. XExtCodes* /* codes */
  796. ) /* proc */
  797. ))(
  798. Display*, XFontStruct*, XExtCodes*
  799. );
  800. extern int (*XESetCloseDisplay(
  801. Display* /* display */,
  802. int /* extension */,
  803. int (*) (
  804. Display* /* display */,
  805. XExtCodes* /* codes */
  806. ) /* proc */
  807. ))(
  808. Display*, XExtCodes*
  809. );
  810. extern int (*XESetError(
  811. Display* /* display */,
  812. int /* extension */,
  813. int (*) (
  814. Display* /* display */,
  815. xError* /* err */,
  816. XExtCodes* /* codes */,
  817. int* /* ret_code */
  818. ) /* proc */
  819. ))(
  820. Display*, xError*, XExtCodes*, int*
  821. );
  822. extern char* (*XESetErrorString(
  823. Display* /* display */,
  824. int /* extension */,
  825. char* (*) (
  826. Display* /* display */,
  827. int /* code */,
  828. XExtCodes* /* codes */,
  829. char* /* buffer */,
  830. int /* nbytes */
  831. ) /* proc */
  832. ))(
  833. Display*, int, XExtCodes*, char*, int
  834. );
  835. extern void (*XESetPrintErrorValues (
  836. Display* /* display */,
  837. int /* extension */,
  838. void (*)(
  839. Display* /* display */,
  840. XErrorEvent* /* ev */,
  841. void* /* fp */
  842. ) /* proc */
  843. ))(
  844. Display*, XErrorEvent*, void*
  845. );
  846. extern Bool (*XESetWireToEvent(
  847. Display* /* display */,
  848. int /* event_number */,
  849. Bool (*) (
  850. Display* /* display */,
  851. XEvent* /* re */,
  852. xEvent* /* event */
  853. ) /* proc */
  854. ))(
  855. Display*, XEvent*, xEvent*
  856. );
  857. extern Status (*XESetEventToWire(
  858. Display* /* display */,
  859. int /* event_number */,
  860. Status (*) (
  861. Display* /* display */,
  862. XEvent* /* re */,
  863. xEvent* /* event */
  864. ) /* proc */
  865. ))(
  866. Display*, XEvent*, xEvent*
  867. );
  868. extern Bool (*XESetWireToError(
  869. Display* /* display */,
  870. int /* error_number */,
  871. Bool (*) (
  872. Display* /* display */,
  873. XErrorEvent* /* he */,
  874. xError* /* we */
  875. ) /* proc */
  876. ))(
  877. Display*, XErrorEvent*, xError*
  878. );
  879. extern void (*XESetBeforeFlush(
  880. Display* /* display */,
  881. int /* error_number */,
  882. void (*) (
  883. Display* /* display */,
  884. XExtCodes* /* codes */,
  885. char* /* data */,
  886. long /* len */
  887. ) /* proc */
  888. ))(
  889. Display*, XExtCodes*, char*, long
  890. );
  891. /* internal connections for IMs */
  892. typedef void (*_XInternalConnectionProc)(
  893. Display* /* dpy */,
  894. int /* fd */,
  895. XPointer /* call_data */
  896. );
  897. extern Status _XRegisterInternalConnection(
  898. Display* /* dpy */,
  899. int /* fd */,
  900. _XInternalConnectionProc /* callback */,
  901. XPointer /* call_data */
  902. );
  903. extern void _XUnregisterInternalConnection(
  904. Display* /* dpy */,
  905. int /* fd */
  906. );
  907. /* Display structure has pointers to these */
  908. struct _XConnectionInfo { /* info from _XRegisterInternalConnection */
  909. int fd;
  910. _XInternalConnectionProc read_callback;
  911. XPointer call_data;
  912. XPointer *watch_data; /* set/used by XConnectionWatchProc */
  913. struct _XConnectionInfo *next;
  914. };
  915. struct _XConnWatchInfo { /* info from XAddConnectionWatch */
  916. XConnectionWatchProc fn;
  917. XPointer client_data;
  918. struct _XConnWatchInfo *next;
  919. };
  920. extern int XTextHeight(
  921. XFontStruct* /* font_struct */,
  922. const char* /* string */,
  923. int /* count */
  924. );
  925. extern int XTextHeight16(
  926. XFontStruct* /* font_struct */,
  927. const XChar2b* /* string */,
  928. int /* count */
  929. );
  930. _XFUNCPROTOEND