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