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