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