[comp.windows.x] c++ and X11

rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (11/01/88)

    Has anybody out there written a C++ interface to X11?  I.e.,
doctored up        the ".h" files so that CC likes them?   

Take a look at InterViews in the contrib/ part of R3.

xsmd@inesc.UUCP (Manuel Sequeira ; MDS) (11/02/88)

    Date: 31 Oct 88 22:01:21 GMT
    From: mcvax!june.cs.washington.edu!whaley  (Ken Whaley)

    Has anybody out there written a C++ interface to X11?  I.e., doctored up the
    ".h" files so that CC likes them?   

Yes we've done that.
There were two problems to solve:
1. Struct component names: new, delete, class.
    we solved that by including two files in every ".h" X file 
    which used such fields.
    - one at the beginning defining new, delete, and class as 
    Xnew, Xdelete, and Xclass.
    - another at the end undefining the previous definitions.

   Ramifications: if it is necessary to reference such fields in our code
		  we use Xnew etc. instead.

2. Functions Specification.
    As c++ was annoyed by the the C declarations in the ".h" X we deleted
    them. To avoid errors and warnings generated by the compiler, we
    specified the functions in others ".h" files (hidden to the user) and
    included by the usual ".h" X files.
    Since this specification task was not a very gratifing job to accomplish
    by hand, a mechanism was developed that using emacs macros, shell
    scripts and ".f" files (used to build the manual), somewhat automatized the
    process. 

  Ramifications: None whatsoever. 

We have been using this since X11R1, and the approach used facilitated the
upgrade to X11R2.

 -manel
..mcvax!inesc!xsmd

linton@INTERVIEWS.STANFORD.EDU (Mark Linton) (11/10/88)

Stergios Marinopoulos from Athena Systems writes
    " ... if  you dont  have  excellent  people designing and
    coding  I dont care what the  language  is you can  bet you'll have  a
    disaster on your hands."

I absolutely agree.  It is a mistake to believe that using C++
will somehow turn bad programmers into good ones.  However,
good programmers who are implementing an object-oriented design will
find C++ an order of magnitude better language than C.
Our experience is that the language advantages outweigh
the environment disadvantages (of course, it helps that I am able
to modify dbx to make our debugging lives a little easier).
We currently have over 80,000 lines of evolving C++ code.

Stergios goes on to say
    "As for  InterViews, well,
    lets just say: nahhh, forget it - just forget it."

This is a cheap shot.  Specific criticisms would be useful to us and
other readers, but this sort of attack is no good for anyone.

Jim Becker from Athena Systems writes
    "I strongly urge those embarking on InterViews and C++ related products
    to at least read the C++ news group, if not email or call us directly."

I hope that anyone who wants information about InterViews contacts me or
sends mail to interviews@lurch.stanford.edu instead of or in addition to
talking with the Athena Systems folks.

	Mark

csmoe@mtsu.EDU (Miss. Monisha Guglani) (10/10/90)

	C++ requires that the types for arguments to a function be
	declared when the function is declared within header files
	(extern)! C dosen't need u to specify the arguments to functions
	within header files. For already present header files like
	Xlib.h is there a way to get around this problem because c++
	gives an error of the type
	unexpected 1 argument for function.
	Has anyone else encountered similar problems. Here again this
	is X11R3 that I'm facing problems with.

-- 
/**************************************************************/
/*       csmoe@knuth.mtsu.edu        Monisha Guglani          */	   
/* "I haven't lost my mind its backed-up on a tape somewhere" */
/**************************************************************/

masa@hpsciz.HP.COM (Masayoshi Habu) (10/11/90)

So you want to use C++ and X window together ?  It is nice because you can
create your own "widget" as an class in C++, thus eliminating the complicated
process of manipulating widgets in bare C. I attached a header file which is
good for C++ in the next response. Please look at "#ifdef __cplusplus" lines.
If your compiler does not set this variable, you need to define it yourself.

Have fun !

Masa

masa@hpsciz.HP.COM (Masayoshi Habu) (10/11/90)

/* $XConsortium: Xlib.h,v 11.151 89/02/01 18:02:55 rws Exp $ */
/* 
 * Copyright 1985, 1986, 1987 by the Massachusetts Institute of Technology
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided 
 * that the above copyright notice appear in all copies and that both that 
 * copyright notice and this permission notice appear in supporting 
 * documentation, and that the name of M.I.T. not be used in advertising
 * or publicity pertaining to distribution of the software without specific, 
 * written prior permission. M.I.T. makes no representations about the 
 * suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 *
 * The X Window System is a Trademark of MIT.
 *
 */


/*
 *	Xlib.h - Header definition and support file for the C subroutine
 *	interface library (Xlib) to the X Window System Protocol (V11).
 *	Structures and symbols starting with "_" are private to the library.
 */
#ifndef _XLIB_H_
#define _XLIB_H_

#ifdef CRAY
#ifndef __TYPES__
#define __TYPES__
#include <sys/types.h>			/* forgot to protect it... */
#endif /* __TYPES__ */
#else
#include <sys/types.h>
#endif /* CRAY */

#include <X11/X.h>

#ifdef __cplusplus
#ifndef class
#  define class c_class
#  define new c_new
#endif
extern "C" {
#endif

#define Bool int
#define Status int
#define True 1
#define False 0

#define QueuedAlready 0
#define QueuedAfterReading 1
#define QueuedAfterFlush 2

#define ConnectionNumber(dpy) 	((dpy)->fd)
#define RootWindow(dpy, scr) 	(((dpy)->screens[(scr)]).root)
#define DefaultScreen(dpy) 	((dpy)->default_screen)
#define DefaultRootWindow(dpy) 	(((dpy)->screens[(dpy)->default_screen]).root)
#define DefaultVisual(dpy, scr) (((dpy)->screens[(scr)]).root_visual)
#define DefaultGC(dpy, scr) 	(((dpy)->screens[(scr)]).default_gc)
#define BlackPixel(dpy, scr) 	(((dpy)->screens[(scr)]).black_pixel)
#define WhitePixel(dpy, scr) 	(((dpy)->screens[(scr)]).white_pixel)
#define AllPlanes 		(~0)
#define QLength(dpy) 		((dpy)->qlen)
#define DisplayWidth(dpy, scr) 	(((dpy)->screens[(scr)]).width)
#define DisplayHeight(dpy, scr) (((dpy)->screens[(scr)]).height)
#define DisplayWidthMM(dpy, scr)(((dpy)->screens[(scr)]).mwidth)
#define DisplayHeightMM(dpy, scr)(((dpy)->screens[(scr)]).mheight)
#define DisplayPlanes(dpy, scr) (((dpy)->screens[(scr)]).root_depth)
#define DisplayCells(dpy, scr) 	(DefaultVisual((dpy), (scr))->map_entries)
#define ScreenCount(dpy) 	((dpy)->nscreens)
#define ServerVendor(dpy) 	((dpy)->vendor)
#define ProtocolVersion(dpy) 	((dpy)->proto_major_version)
#define ProtocolRevision(dpy) 	((dpy)->proto_minor_version)
#define VendorRelease(dpy) 	((dpy)->release)
#define DisplayString(dpy) 	((dpy)->display_name)
#define DefaultDepth(dpy, scr) 	(((dpy)->screens[(scr)]).root_depth)
#define DefaultColormap(dpy, scr)(((dpy)->screens[(scr)]).cmap)
#define BitmapUnit(dpy) 	((dpy)->bitmap_unit)
#define BitmapBitOrder(dpy) 	((dpy)->bitmap_bit_order)
#define BitmapPad(dpy) 		((dpy)->bitmap_pad)
#define ImageByteOrder(dpy) 	((dpy)->byte_order)
#define NextRequest(dpy)	((dpy)->request + 1)
#define LastKnownRequestProcessed(dpy)	((dpy)->last_request_read)

/* macros for screen oriented applications (toolkit) */
#define ScreenOfDisplay(dpy, scr)(&((dpy)->screens[(scr)]))
#define DefaultScreenOfDisplay(dpy) (&((dpy)->screens[(dpy)->default_screen]))
#define DisplayOfScreen(s)	((s)->display)
#define RootWindowOfScreen(s)	((s)->root)
#define BlackPixelOfScreen(s)	((s)->black_pixel)
#define WhitePixelOfScreen(s)	((s)->white_pixel)
#define DefaultColormapOfScreen(s)((s)->cmap)
#define DefaultDepthOfScreen(s)	((s)->root_depth)
#define DefaultGCOfScreen(s)	((s)->default_gc)
#define DefaultVisualOfScreen(s)((s)->root_visual)
#define WidthOfScreen(s)	((s)->width)
#define HeightOfScreen(s)	((s)->height)
#define WidthMMOfScreen(s)	((s)->mwidth)
#define HeightMMOfScreen(s)	((s)->mheight)
#define PlanesOfScreen(s)	((s)->root_depth)
#define CellsOfScreen(s)	(DefaultVisualOfScreen((s))->map_entries)
#define MinCmapsOfScreen(s)	((s)->min_maps)
#define MaxCmapsOfScreen(s)	((s)->max_maps)
#define DoesSaveUnders(s)	((s)->save_unders)
#define DoesBackingStore(s)	((s)->backing_store)
#define EventMaskOfScreen(s)	((s)->root_input_mask)

/*
 * Extensions need a way to hang private data on some structures.
 */
typedef struct _XExtData {
	int number;		/* number returned by XRegisterExtension */
	struct _XExtData *next;	/* next item on list of data for structure */
#ifdef __cplusplus
	int (*free_private)(char *);
#else  /* __cplusplus */
	int (*free_private)();	/* called to free private storage */
#endif  /* __cplusplus */
	char *private_data;	/* data private to this extension. */
} XExtData;

/*
 * This file contains structures used by the extension mechanism.
 */
typedef struct {		/* public to extension, cannot be changed */
	int extension;		/* extension number */
	int major_opcode;	/* major op-code assigned by server */
	int first_event;	/* first event number for the extension */
	int first_error;	/* first error number for the extension */
} XExtCodes;

/*
 * This structure is private to the library.
 */
typedef struct _XExten {	/* private to extension mechanism */
	struct _XExten *next;	/* next in list */
	XExtCodes codes;	/* public information, all extension told */
#ifdef __cplusplus
	int (*create_GC)(struct _XDisplay *, struct _XGC *, XExtCodes *);
	int (*copy_GC)(struct _XDisplay *, struct _XGC *, XExtCodes *);
	int (*flush_GC)(struct _XDisplay *, struct _XGC *, XExtCodes *);
	int (*free_GC)(struct _XDisplay *, struct _XGC *, XExtCodes *);
	int (*create_Font)(struct _XDisplay *, struct _XFontStruct *, XExtCodes *);
	int (*free_Font)(struct _XDisplay *, struct _XFontStruct *, XExtCodes *);
	int (*close_display)(struct _XDisplay *, XExtCodes *);
	int (*error)();         /* (...)** */
	int (*error_string)(struct _XDisplay *, int, XExtCodes *);
#else  /* __cplusplus */
	int (*create_GC)();	/* routine to call when GC created */
	int (*copy_GC)();	/* routine to call when GC copied */
	int (*flush_GC)();	/* routine to call when GC flushed */
	int (*free_GC)();	/* routine to call when GC freed */
	int (*create_Font)();	/* routine to call when Font created */
	int (*free_Font)();	/* routine to call when Font freed */
	int (*close_display)();	/* routine to call when connection closed */
	int (*error)();		/* who to call when an error occurs */
	int (*error_string)();  /* routine to supply error string */
#endif  /* __cplusplus */
	char *name;		/* name of this extension */
} _XExtension;

/*
 * Data structure for setting graphics context.
 */
typedef struct {
	int function;		/* logical operation */
	unsigned long plane_mask;/* plane mask */
	unsigned long foreground;/* foreground pixel */
	unsigned long background;/* background pixel */
	int line_width;		/* line width */
	int line_style;	 	/* LineSolid, LineOnOffDash, LineDoubleDash */
	int cap_style;	  	/* CapNotLast, CapButt, 
				   CapRound, CapProjecting */
	int join_style;	 	/* JoinMiter, JoinRound, JoinBevel */
	int fill_style;	 	/* FillSolid, FillTiled, 
				   FillStippled, FillOpaeueStippled */
	int fill_rule;	  	/* EvenOddRule, WindingRule */
	int arc_mode;		/* ArcChord, ArcPieSlice */
	Pixmap tile;		/* tile pixmap for tiling operations */
	Pixmap stipple;		/* stipple 1 plane pixmap for stipping */
	int ts_x_origin;	/* offset for tile or stipple operations */
	int ts_y_origin;
        Font font;	        /* default text font for text operations */
	int subwindow_mode;     /* ClipByChildren, IncludeInferiors */
	Bool graphics_exposures;/* boolean, should exposures be generated */
	int clip_x_origin;	/* origin for clipping */
	int clip_y_origin;
	Pixmap clip_mask;	/* bitmap clipping; other calls for rects */
	int dash_offset;	/* patterned/dashed line information */
	char dashes;
} XGCValues;

/*
 * Graphics context.  All Xlib routines deal in this rather than
 * in raw protocol GContext ID's.  This is so that the library can keep
 * a "shadow" set of values, and thus avoid passing values over the
 * wire which are not in fact changing. 
 */

typedef struct _XGC {
    XExtData *ext_data;	/* hook for extension to hang data */
    GContext gid;	/* protocol ID for graphics context */
    Bool rects;		/* boolean: TRUE if clipmask is list of rectangles */
    Bool dashes;	/* boolean: TRUE if dash-list is really a list */
    unsigned long dirty;/* cache dirty bits */
    XGCValues values;	/* shadow structure of values */
} *GC;


/*
 * Visual structure; contains information about colormapping possible.
 */
typedef struct {
	XExtData *ext_data;	/* hook for extension to hang data */
	VisualID visualid;	/* visual id of this visual */
	int class;		/* class of screen (monochrome, etc.) */
	unsigned long red_mask, green_mask, blue_mask;	/* mask values */
	int bits_per_rgb;	/* log base 2 of distinct color values */
	int map_entries;	/* color map entries */
} Visual;

/*
 * Depth structure; contains information for each possible depth.
 */	
typedef struct {
	int depth;		/* this depth (Z) of the depth */
	int nvisuals;		/* number of Visual types at this depth */
	Visual *visuals;	/* list of visuals possible at this depth */
} Depth;

/*
 * Information about the screen.
 */
typedef struct {
	XExtData *ext_data;	/* hook for extension to hang data */
	struct _XDisplay *display;/* back pointer to display structure */
	Window root;		/* Root window id. */
	int width, height;	/* width and height of screen */
	int mwidth, mheight;	/* width and height of  in millimeters */
	int ndepths;		/* number of depths possible */
	Depth *depths;		/* list of allowable depths on the screen */
	int root_depth;		/* bits per pixel */
	Visual *root_visual;	/* root visual */
	GC default_gc;		/* GC for the root root visual */
	Colormap cmap;		/* default color map */
	unsigned long white_pixel;
	unsigned long black_pixel;	/* White and Black pixel values */
	int max_maps, min_maps;	/* max and min color maps */
	int backing_store;	/* Never, WhenMapped, Always */
	Bool save_unders;	
	long root_input_mask;	/* initial root input mask */
} Screen;

/*
 * Format structure; describes ZFormat data the screen will understand.
 */
typedef struct {
	XExtData *ext_data;	/* hook for extension to hang data */
	int depth;		/* depth of this image format */
	int bits_per_pixel;	/* bits/pixel at this depth */
	int scanline_pad;	/* scanline must padded to this multiple */
} ScreenFormat;

#ifndef _XSTRUCT_	/* hack to reduce symbol load in Xlib routines */
/*
 * Data structure for setting window attributes.
 */
typedef struct {
    Pixmap background_pixmap;	/* background or None or ParentRelative */
    unsigned long background_pixel;	/* background pixel */
    Pixmap border_pixmap;	/* border of the window */
    unsigned long border_pixel;	/* border pixel value */
    int bit_gravity;		/* one of bit gravity values */
    int win_gravity;		/* one of the window gravity values */
    int backing_store;		/* NotUseful, WhenMapped, Always */
    unsigned long backing_planes;/* planes to be preseved if possible */
    unsigned long backing_pixel;/* value to use in restoring planes */
    Bool save_under;		/* should bits under be saved? (popups) */
    long event_mask;		/* set of events that should be saved */
    long do_not_propagate_mask;	/* set of events that should not propagate */
    Bool override_redirect;	/* boolean value for override-redirect */
    Colormap colormap;		/* color map to be associated with window */
    Cursor cursor;		/* cursor to be displayed (or None) */
} XSetWindowAttributes;

typedef struct {
    int x, y;			/* location of window */
    int width, height;		/* width and height of window */
    int border_width;		/* border width of window */
    int depth;          	/* depth of window */
    Visual *visual;		/* the associated visual structure */
    Window root;        	/* root of screen containing window */
    int class;			/* InputOutput, InputOnly*/
    int bit_gravity;		/* one of bit gravity values */
    int win_gravity;		/* one of the window gravity values */
    int backing_store;		/* NotUseful, WhenMapped, Always */
    unsigned long backing_planes;/* planes to be preserved if possible */
    unsigned long backing_pixel;/* value to be used when restoring planes */
    Bool save_under;		/* boolean, should bits under be saved? */
    Colormap colormap;		/* color map to be associated with window */
    Bool map_installed;		/* boolean, is color map currently installed*/
    int map_state;		/* IsUnmapped, IsUnviewable, IsViewable */
    long all_event_masks;	/* set of events all people have interest in*/
    long your_event_mask;	/* my event mask */
    long do_not_propagate_mask; /* set of events that should not propagate */
    Bool override_redirect;	/* boolean value for override-redirect */
    Screen *screen;		/* back pointer to correct screen */
} XWindowAttributes;

/*
 * Data structure for host setting; getting routines.
 *
 */

typedef struct {
	int family;		/* for example AF_DNET */
	int length;		/* length of address, in bytes */
	char *address;		/* pointer to where to find the bytes */
} XHostAddress;

/*
 * Data structure for "image" data, used by image manipulation routines.
 */
typedef struct _XImage {
    int width, height;		/* size of image */
    int xoffset;		/* number of pixels offset in X direction */
    int format;			/* XYBitmap, XYPixmap, ZPixmap */
    char *data;			/* pointer to image data */
    int byte_order;		/* data byte order, LSBFirst, MSBFirst */
    int bitmap_unit;		/* quant. of scanline 8, 16, 32 */
    int bitmap_bit_order;	/* LSBFirst, MSBFirst */
    int bitmap_pad;		/* 8, 16, 32 either XY or ZPixmap */
    int depth;			/* depth of image */
    int bytes_per_line;		/* accelarator to next line */
    int bits_per_pixel;		/* bits per pixel (ZPixmap) */
    unsigned long red_mask;	/* bits in z arrangment */
    unsigned long green_mask;
    unsigned long blue_mask;
    char *obdata;		/* hook for the object routines to hang on */
    struct funcs {		/* image manipulation routines */
	struct _XImage *(*create_image)();	
	int (*destroy_image)();		
	unsigned long (*get_pixel)();
	int (*put_pixel)();	
	struct _XImage *(*sub_image)();		
	int (*add_pixel)();		
	} f;
} XImage;

/* 
 * Data structure for XReconfigureWindow
 */
typedef struct {
    int x, y;
    int width, height;
    int border_width;
    Window sibling;
    int stack_mode;
} XWindowChanges;

/*
 * Data structure used by color operations
 */
typedef struct {
	unsigned long pixel;
	unsigned short red, green, blue;
	char flags;  /* do_red, do_green, do_blue */
	char pad;
} XColor;

/* 
 * Data structures for graphics operations.  On most machines, these are
 * congruent with the wire protocol structures, so reformatting the data
 * can be avoided on these architectures.
 */
typedef struct {
    short x1, y1, x2, y2;
} XSegment;

typedef struct {
    short x, y;
} XPoint;
    
typedef struct {
    short x, y;
    unsigned short width, height;
} XRectangle;
    
typedef struct {
    short x, y;
    unsigned short width, height;
    short angle1, angle2;
} XArc;


/* Data structure for XChangeKeyboardControl */

typedef struct {
        int key_click_percent;
        int bell_percent;
        int bell_pitch;
        int bell_duration;
        int led;
        int led_mode;
        int key;
        int auto_repeat_mode;   /* On, Off, Default */
} XKeyboardControl;

/* Data structure for XGetKeyboardControl */

typedef struct {
        int key_click_percent;
	int bell_percent;
	unsigned int bell_pitch, bell_duration;
	unsigned long led_mask;
	int global_auto_repeat;
	char auto_repeats[32];
} XKeyboardState;

/* Data structure for XGetMotionEvents.  */

typedef struct {
        Time time;
	short x, y;
} XTimeCoord;

/* Data structure for X{Set,Get}ModifierMapping */

typedef struct {
 	int max_keypermod;	/* The server's max # of keys per modifier */
 	KeyCode *modifiermap;	/* An 8 by max_keypermod array of modifiers */
} XModifierKeymap;

#ifdef __cplusplus
XModifierKeymap *XNewModifiermap (int),
		*XGetModifierMapping (struct _XDisplay *),
		*XDeleteModifiermapEntry (XModifierKeymap *, KeyCode, int),
		*XInsertModifiermapEntry (XModifierKeymap *, KeyCode, int);
#else  /* __cplusplus */
XModifierKeymap *XNewModifiermap(),
		*XGetModifierMapping(),
		*XDeleteModifiermapEntry(),
		*XInsertModifiermapEntry();
#endif  /* __cplusplus */
#endif /* _XSTRUCT_ */

/*
 * Display datatype maintaining display specific data.
 */
typedef struct _XDisplay {
	XExtData *ext_data;	/* hook for extension to hang data */
	struct _XDisplay *next; /* next open Display on list */
	int fd;			/* Network socket. */
	int lock;		/* is someone in critical section? */
	int proto_major_version;/* maj. version of server's X protocol */
	int proto_minor_version;/* minor version of servers X protocol */
	char *vendor;		/* vendor of the server hardware */
        long resource_base;	/* resource ID base */
	long resource_mask;	/* resource ID mask bits */
	long resource_id;	/* allocator current ID */
	int resource_shift;	/* allocator shift to correct bits */
#ifdef __cplusplus
	XID (*resource_alloc)(); 
#else  /* __cplusplus */
	XID (*resource_alloc)(); /* allocator function */
#endif  /* __cplusplus */
	int byte_order;		/* screen byte order, LSBFirst, MSBFirst */
	int bitmap_unit;	/* padding and data requirements */
	int bitmap_pad;		/* padding requirements on bitmaps */
	int bitmap_bit_order;	/* LeastSignificant or MostSignificant */
	int nformats;		/* number of pixmap formats in list */
	ScreenFormat *pixmap_format;	/* pixmap format list */
	int vnumber;		/* Xlib's X protocol version number. */
	int release;		/* release of the server */
	struct _XSQEvent *head, *tail;	/* Input event queue. */
	int qlen;		/* Length of input event queue */
	unsigned long last_request_read; /* seq number of last event read */
	unsigned long request;	/* sequence number of last request. */
	char *last_req;		/* beginning of last request, or dummy */
	char *buffer;		/* Output buffer starting address. */
	char *bufptr;		/* Output buffer index pointer. */
	char *bufmax;		/* Output buffer maximum+1 address. */
	unsigned max_request_size; /* maximum number 32 bit words in request*/
	struct _XrmHashBucketRec *db;
#ifdef __cplusplus
	int (*synchandler)();	
#else  /* __cplusplus */
	int (*synchandler)();	/* Synchronization handler */
#endif  /* __cplusplus */
	char *display_name;	/* "host:display" string used on this connect*/
	int default_screen;	/* default screen for operations */
	int nscreens;		/* number of screens on this server*/
	Screen *screens;	/* pointer to list of screens */
	unsigned long motion_buffer;	/* size of motion buffer */
	Window current;		/* for use internally for Keymap notify */
	int min_keycode;	/* minimum defined keycode */
	int max_keycode;	/* maximum defined keycode */
	KeySym *keysyms;	/* This server's keysyms */
	XModifierKeymap *modifiermap;	/* This server's modifier keymap */
	int keysyms_per_keycode;/* number of rows */
	char *xdefaults;	/* contents of defaults from server */
	char *scratch_buffer;	/* place to hang scratch buffer */
	unsigned long scratch_length;	/* length of scratch buffer */
	int ext_number;		/* extension number on this display */
	_XExtension *ext_procs;	/* extensions initialized on this display */
	/*
	 * the following can be fixed size, as the protocol defines how
	 * much address space is available. 
	 * While this could be done using the extension vector, there
	 * may be MANY events processed, so a search through the extension
	 * list to find the right procedure for each event might be
	 * expensive if many extensions are being used.
	 */
#ifdef __cplusplus
	Bool (*event_vec[128])();   /* (...)** */
	Status (*wire_vec[128])();  /* (...)** */
#else  /* __cplusplus */
	Bool (*event_vec[128])();  /* vector for wire to event */
	Status (*wire_vec[128])(); /* vector for event to wire */
#endif  /* __cplusplus */
	KeySym lock_meaning;	   /* for XLookupString */
	struct XKeytrans *key_bindings; /* for XLookupString */
	Font cursor_font;	   /* for XCreateFontCursor */
} Display;

#ifndef _XEVENT_
/*
 * A "XEvent" structure always  has type as the first entry.  This 
 * uniquely identifies what  kind of event it is.  The second entry
 * is always a pointer to the display the event was read from.
 * The third entry is always a window of one type or another,
 * carefully selected to be useful to toolkit dispatchers.  (Except
 * for keymap events, which have no window.) You
 * must not change the order of the three elements or toolkits will
 * break! The pointer to the generic event must be cast before use to 
 * access any other information in the structure.
 */

/*
 * Definitions of specific events.
 */
typedef struct {
	int type;		/* of event */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;	        /* "event" window it is reported relative to */
	Window root;	        /* root window that the event occured on */
	Window subwindow;	/* child window */
	Time time;		/* milliseconds */
	int x, y;		/* pointer x, y coordinates in event window */
	int x_root, y_root;	/* coordinates relative to root */
	unsigned int state;	/* key or button mask */
	unsigned int keycode;	/* detail */
	Bool same_screen;	/* same screen flag */
} XKeyEvent;
typedef XKeyEvent XKeyPressedEvent;
typedef XKeyEvent XKeyReleasedEvent;

typedef struct {
	int type;		/* of event */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;	        /* "event" window it is reported relative to */
	Window root;	        /* root window that the event occured on */
	Window subwindow;	/* child window */
	Time time;		/* milliseconds */
	int x, y;		/* pointer x, y coordinates in event window */
	int x_root, y_root;	/* coordinates relative to root */
	unsigned int state;	/* key or button mask */
	unsigned int button;	/* detail */
	Bool same_screen;	/* same screen flag */
} XButtonEvent;
typedef XButtonEvent XButtonPressedEvent;
typedef XButtonEvent XButtonReleasedEvent;

typedef struct {
	int type;		/* of event */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;	        /* "event" window reported relative to */
	Window root;	        /* root window that the event occured on */
	Window subwindow;	/* child window */
	Time time;		/* milliseconds */
	int x, y;		/* pointer x, y coordinates in event window */
	int x_root, y_root;	/* coordinates relative to root */
	unsigned int state;	/* key or button mask */
	char is_hint;		/* detail */
	Bool same_screen;	/* same screen flag */
} XMotionEvent;
typedef XMotionEvent XPointerMovedEvent;

typedef struct {
	int type;		/* of event */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;	        /* "event" window reported relative to */
	Window root;	        /* root window that the event occured on */
	Window subwindow;	/* child window */
	Time time;		/* milliseconds */
	int x, y;		/* pointer x, y coordinates in event window */
	int x_root, y_root;	/* coordinates relative to root */
	int mode;		/* NotifyNormal, NotifyGrab, NotifyUngrab */
	int detail;
	/*
	 * NotifyAncestor, NotifyVirtual, NotifyInferior, 
	 * NotifyNonLinear,NotifyNonLinearVirtual
	 */
	Bool same_screen;	/* same screen flag */
	Bool focus;		/* boolean focus */
	unsigned int state;	/* key or button mask */
} XCrossingEvent;
typedef XCrossingEvent XEnterWindowEvent;
typedef XCrossingEvent XLeaveWindowEvent;

typedef struct {
	int type;		/* FocusIn or FocusOut */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;		/* window of event */
	int mode;		/* NotifyNormal, NotifyGrab, NotifyUngrab */
	int detail;
	/*
	 * NotifyAncestor, NotifyVirtual, NotifyInferior, 
	 * NotifyNonLinear,NotifyNonLinearVirtual, NotifyPointer,
	 * NotifyPointerRoot, NotifyDetailNone 
	 */
} XFocusChangeEvent;
typedef XFocusChangeEvent XFocusInEvent;
typedef XFocusChangeEvent XFocusOutEvent;

/* generated on EnterWindow and FocusIn  when KeyMapState selected */
typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;
	char key_vector[32];
} XKeymapEvent;	

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;
	int x, y;
	int width, height;
	int count;		/* if non-zero, at least this many more */
} XExposeEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Drawable drawable;
	int x, y;
	int width, height;
	int count;		/* if non-zero, at least this many more */
	int major_code;		/* core is CopyArea or CopyPlane */
	int minor_code;		/* not defined in the core */
} XGraphicsExposeEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Drawable drawable;
	int major_code;		/* core is CopyArea or CopyPlane */
	int minor_code;		/* not defined in the core */
} XNoExposeEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;
	int state;		/* Visibility state */
} XVisibilityEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window parent;		/* parent of the window */
	Window window;		/* window id of window created */
	int x, y;		/* window location */
	int width, height;	/* size of window */
	int border_width;	/* border width */
	Bool override_redirect;	/* creation should be overridden */
} XCreateWindowEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window event;
	Window window;
} XDestroyWindowEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window event;
	Window window;
	Bool from_configure;
} XUnmapEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window event;
	Window window;
	Bool override_redirect;	/* boolean, is override set... */
} XMapEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window parent;
	Window window;
} XMapRequestEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window event;
	Window window;
	Window parent;
	int x, y;
	Bool override_redirect;
} XReparentEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window event;
	Window window;
	int x, y;
	int width, height;
	int border_width;
	Window above;
	Bool override_redirect;
} XConfigureEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window event;
	Window window;
	int x, y;
} XGravityEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;
	int width, height;
} XResizeRequestEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window parent;
	Window window;
	int x, y;
	int width, height;
	int border_width;
	Window above;
	int detail;		/* Above, Below, TopIf, BottomIf, Opposite */
	unsigned long value_mask;
} XConfigureRequestEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window event;
	Window window;
	int place;		/* PlaceOnTop, PlaceOnBottom */
} XCirculateEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window parent;
	Window window;
	int place;		/* PlaceOnTop, PlaceOnBottom */
} XCirculateRequestEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;
	Atom atom;
	Time time;
	int state;		/* NewValue, Deleted */
} XPropertyEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;
	Atom selection;
	Time time;
} XSelectionClearEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window owner;
	Window requestor;
	Atom selection;
	Atom target;
	Atom property;
	Time time;
} XSelectionRequestEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window requestor;
	Atom selection;
	Atom target;
	Atom property;		/* ATOM or None */
	Time time;
} XSelectionEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;
	Colormap colormap;	/* COLORMAP or None */
	Bool new;
	int state;		/* ColormapInstalled, ColormapUninstalled */
} XColormapEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;
	Atom message_type;
	int format;
	union {
		char b[20];
		short s[10];
		long l[5];
		} data;
} XClientMessageEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;		/* unused */
	int request;		/* one of MappingModifier, MappingKeyboard,
				   MappingPointer */
	int first_keycode;	/* first keycode */
	int count;		/* defines range of change w. first_keycode*/
} XMappingEvent;

typedef struct {
	int type;
	Display *display;	/* Display the event was read from */
	XID resourceid;		/* resource id */
	unsigned long serial;	/* serial number of failed request */
	unsigned char error_code;	/* error code of failed request */
	unsigned char request_code;	/* Major op-code of failed request */
	unsigned char minor_code;	/* Minor op-code of failed request */
} XErrorEvent;

typedef struct {
	int type;
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;/* Display the event was read from */
	Window window;	/* window on which event was requested in event mask */
} XAnyEvent;

/*
 * this union is defined so Xlib can always use the same sized
 * event structure internally, to avoid memory fragmentation.
 */
typedef union _XEvent {
        int type;		/* must not be changed; first element */
	XAnyEvent xany;
	XKeyEvent xkey;
	XButtonEvent xbutton;
	XMotionEvent xmotion;
	XCrossingEvent xcrossing;
	XFocusChangeEvent xfocus;
	XExposeEvent xexpose;
	XGraphicsExposeEvent xgraphicsexpose;
	XNoExposeEvent xnoexpose;
	XVisibilityEvent xvisibility;
	XCreateWindowEvent xcreatewindow;
	XDestroyWindowEvent xdestroywindow;
	XUnmapEvent xunmap;
	XMapEvent xmap;
	XMapRequestEvent xmaprequest;
	XReparentEvent xreparent;
	XConfigureEvent xconfigure;
	XGravityEvent xgravity;
	XResizeRequestEvent xresizerequest;
	XConfigureRequestEvent xconfigurerequest;
	XCirculateEvent xcirculate;
	XCirculateRequestEvent xcirculaterequest;
	XPropertyEvent xproperty;
	XSelectionClearEvent xselectionclear;
	XSelectionRequestEvent xselectionrequest;
	XSelectionEvent xselection;
	XColormapEvent xcolormap;
	XClientMessageEvent xclient;
	XMappingEvent xmapping;
	XErrorEvent xerror;
	XKeymapEvent xkeymap;
	long pad[24];
} XEvent;
/*
 * _QEvent datatype for use in input queueing.
 */
typedef struct _XSQEvent {
    struct _XSQEvent *next;
    XEvent event;
} _XQEvent;
#endif
#define XAllocID(dpy) ((*(dpy)->resource_alloc)((dpy)))
#ifndef _XSTRUCT_

/*
 * per character font metric information.
 */
typedef struct {
    short	lbearing;	/* origin to left edge of raster */
    short	rbearing;	/* origin to right edge of raster */
    short	width;		/* advance to next char's origin */
    short	ascent;		/* baseline to top edge of raster */
    short	descent;	/* baseline to bottom edge of raster */
    unsigned short attributes;	/* per char flags (not predefined) */
} XCharStruct;

/*
 * To allow arbitrary information with fonts, there are additional properties
 * returned.
 */
typedef struct {
    Atom name;
    unsigned long card32;
} XFontProp;

typedef struct _XFontStruct {
    XExtData	*ext_data;	/* hook for extension to hang data */
    Font        fid;            /* Font id for this font */
    unsigned	direction;	/* hint about direction the font is painted */
    unsigned	min_char_or_byte2;/* first character */
    unsigned	max_char_or_byte2;/* last character */
    unsigned	min_byte1;	/* first row that exists */
    unsigned	max_byte1;	/* last row that exists */
    Bool	all_chars_exist;/* flag if all characters have non-zero size*/
    unsigned	default_char;	/* char to print for undefined character */
    int         n_properties;   /* how many properties there are */
    XFontProp	*properties;	/* pointer to array of additional properties*/
    XCharStruct	min_bounds;	/* minimum bounds over all existing char*/
    XCharStruct	max_bounds;	/* maximum bounds over all existing char*/
    XCharStruct	*per_char;	/* first_char to last_char information */
    int		ascent;		/* log. extent above baseline for spacing */
    int		descent;	/* log. descent below baseline for spacing */
} XFontStruct;

/*
 * PolyText routines take these as arguments.
 */
typedef struct {
    char *chars;		/* pointer to string */
    int nchars;			/* number of characters */
    int delta;			/* delta between strings */
    Font font;			/* font to print it in, None don't change */
} XTextItem;

typedef struct {		/* normal 16 bit characters are two bytes */
    unsigned char byte1;
    unsigned char byte2;
} XChar2b;

typedef struct {
    XChar2b *chars;		/* two byte characters */
    int nchars;			/* number of characters */
    int delta;			/* delta between strings */
    Font font;			/* font to print it in, None don't change */
} XTextItem16;


#ifdef __cplusplus
XFontStruct *XLoadQueryFont(Display *, const char *),
            *XQueryFont(Display *, XID);
XTimeCoord *XGetMotionEvents(Display *, Window, Time, Time, int *);
#else  /* __cplusplus */
XFontStruct *XLoadQueryFont(), *XQueryFont();

XTimeCoord *XGetMotionEvents();
#endif  /* __cplusplus */

typedef union { Display *display;
		GC gc;
		Visual *visual;
		Screen *screen;
		ScreenFormat *pixmap_format;
		XFontStruct *font; } XEDataObject;
#endif
/* 
 * X function declarations.
 */
#ifdef __cplusplus

Display *XOpenDisplay (const char *);

char *XFetchBytes(Display *, int *);
char *XFetchBuffer(Display *, int *, int);
char *XGetAtomName(Display *, Atom);
char *XGetDefault(Display *,const char *, const char *);
char *XDisplayName(const char *);
char *XKeysymToString(KeySym);

int (*XSynchronize(Display *, int))(Display *);
int (*XSetAfterFunction(Display *, int (*)(Display *)))(Display *);
Atom XInternAtom(Display *, const char *, Bool);
Colormap XCopyColormapAndFree(Display *, Colormap),
         XCreateColormap(Display *, Window, Visual *, int);
Cursor XCreatePixmapCursor(Display *, Pixmap, Pixmap, XColor *, XColor *,
			   unsigned int, unsigned int),
       XCreateGlyphCursor(Display *, Font, Font, unsigned int, unsigned int,
			  XColor *, XColor *),
       XCreateFontCursor(Display *, unsigned int);
Font XLoadFont(Display *, const char *);
GC XCreateGC(Display *, Drawable, unsigned long, XGCValues *);
GContext XGContextFromGC(GC);
Pixmap XCreatePixmap(Display *, Drawable, unsigned int, unsigned int,
		     unsigned int);
Pixmap XCreateBitmapFromData(Display *, Drawable, const char *, unsigned int,
			     unsigned int),
       XCreatePixmapFromBitmapData(Display *, Drawable, char *, unsigned int,
				   unsigned int, unsigned long, unsigned long,
				   unsigned int);
Window XCreateSimpleWindow(Display *, Window, int, int, unsigned int,
			   unsigned int, unsigned int, unsigned long,
			   unsigned long),
       XGetSelectionOwner(Display *, Atom);
Window XCreateWindow(Display *, Window, int, int, unsigned int, unsigned int,
		     unsigned int, int, unsigned int, Visual *, unsigned long,
		     XSetWindowAttributes *); 
Colormap *XListInstalledColormaps(Display *, Window, int *);
char **XListFonts(Display *, const char *, int, int *),
     **XListFontsWithInfo(Display *, const char *, int, int *, XFontStruct **),
     **XGetFontPath(Display *, int *);
char **XListExtensions(Display *, int *);
Atom *XListProperties(Display *, Window, int *);
XImage *XCreateImage(Display *, Visual *, unsigned int, int, int, char *,
		     unsigned int, unsigned int, int, int),
       *XGetImage(Display *, Drawable, int, int, unsigned int, unsigned int,
		  unsigned long, int),
       *XGetSubImage(Display *, Drawable, int, int, unsigned int, unsigned int,
		     unsigned long, int, XImage *, int, int);
XHostAddress *XListHosts(Display *, int *, Bool *);
KeySym XKeycodeToKeysym(Display *, KeyCode, int),
       XLookupKeysym(XKeyEvent *, int),
      *XGetKeyboardMapping(Display *, KeyCode, int, int *);
KeySym XStringToKeysym(const char *);
long XMaxRequestSize(Display*);
char *XResourceManagerString(Display*);
unsigned long XDisplayMotionBufferSize(Display*);
VisualID XVisualIDFromVisual(Visual*);

/* routines for dealing with extensions */
XExtCodes *XInitExtension(Display *, const char*);
int
    (*XESetCreateGC(Display *, int,
		    int (*)(Display *, GC, XExtCodes *)))
                                            (Display *, GC, XExtCodes *),
    (*XESetCopyGC(Display *, int,
		  int (*)(Display *, GC, XExtCodes *)))
                                            (Display *, GC, XExtCodes *),
    (*XESetFlushGC(Display *, int,
		   int (*)(Display *, GC, XExtCodes *)))
                                            (Display *, GC, XExtCodes *),
    (*XESetFreeGC(Display *, int,
		  int (*)(Display *, GC, XExtCodes *)))
                                            (Display *, GC, XExtCodes *),
    (*XESetCreateFont(Display *, int,
		      int (*)(Display *, XFontStruct *, XExtCodes *)))
                                       (Display *, XFontStruct *, XExtCodes *),
    (*XESetFreeFont(Display *, int,
		    int (*)(Display *, XFontStruct *, XExtCodes *)))
                                       (Display *, XFontStruct *, XExtCodes *),
    (*XESetCloseDisplay (Display *, int,
			 int (*)(Display *, XExtCodes)))(Display *, XExtCodes),
    (*XESetError(Display *, int, int (*)()))(),      
    (*XESetErrorString(Display *, int,
		       char (*)(Display *, int, XExtCodes *)))
                                                 (Display *, int, XExtCodes *);

Bool (*XESetWireToEvent(Display *, int, int (*)())) (); 
Status (*XESetEventToWire(Display *, int, int (*)())) (); 

XExtCodes *XAddExtension(Display*);
XExtData *XFindOnExtensionList(XExtData**, int);
XExtData **XEHeadOfExtensionList(XEDataObject);

/* these are routines for which there are also macros */
Window XRootWindow(Display *, int),
       XDefaultRootWindow(Display *),
       XRootWindowOfScreen(Screen *);
Visual *XDefaultVisual(Display *, int),
       *XDefaultVisualOfScreen(Screen *);
GC XDefaultGC(Display *, int),
   XDefaultGCOfScreen(Screen *);
unsigned long XBlackPixel(Display *, int),
              XWhitePixel(Display *, int),
              XAllPlanes(void);
unsigned long XBlackPixelOfScreen(Screen *),
              XWhitePixelOfScreen(Screen *);
unsigned long XNextRequest(Display *),
              XLastKnownRequestProcessed(Display *);
char *XServerVendor(Display *),
     *XDisplayString(Display *);
Colormap XDefaultColormap(Display *, int),
         XDefaultColormapOfScreen(Screen *);
Display *XDisplayOfScreen(Screen *);
Screen *XScreenOfDisplay(Display *, int),
       *XDefaultScreenOfDisplay(Display *);
long XEventMaskOfScreen(Screen *);

#else  /* __cplusplus */
Display *XOpenDisplay();

char *XFetchBytes();
char *XFetchBuffer();
char *XGetAtomName();
char *XGetDefault();
char *XDisplayName();
char *XKeysymToString();

int (*XSynchronize())();
int (*XSetAfterFunction())();
Atom XInternAtom();
Colormap XCopyColormapAndFree(), XCreateColormap();
Cursor XCreatePixmapCursor(), XCreateGlyphCursor(), XCreateFontCursor();
Font XLoadFont();
GC XCreateGC();
GContext XGContextFromGC();
Pixmap XCreatePixmap();
Pixmap XCreateBitmapFromData(), XCreatePixmapFromBitmapData();
Window XCreateSimpleWindow(), XGetSelectionOwner();
Window XCreateWindow(); 
Colormap *XListInstalledColormaps();
char **XListFonts(), **XListFontsWithInfo(), **XGetFontPath();
char **XListExtensions();
Atom *XListProperties();
XImage *XCreateImage(), *XGetImage(), *XGetSubImage();
XHostAddress *XListHosts();
KeySym XKeycodeToKeysym(), XLookupKeysym(), *XGetKeyboardMapping();
KeySym XStringToKeysym();
long XMaxRequestSize();
char *XResourceManagerString();
unsigned long XDisplayMotionBufferSize();
VisualID XVisualIDFromVisual();

/* routines for dealing with extensions */
XExtCodes *XInitExtension();
int (*XESetCreateGC())(), (*XESetCopyGC())(), (*XESetFlushGC())(),
    (*XESetFreeGC())(), (*XESetCreateFont())(), (*XESetFreeFont())(), 
    (*XESetCloseDisplay())(),
    (*XESetError())(), (*XESetErrorString())();
Bool (*XESetWireToEvent())();
Status (*XESetEventToWire())();
XExtCodes *XAddExtension();
XExtData *XFindOnExtensionList();
XExtData **XEHeadOfExtensionList();

/* these are routines for which there are also macros */
Window XRootWindow(), XDefaultRootWindow(), XRootWindowOfScreen();
Visual *XDefaultVisual(), *XDefaultVisualOfScreen();
GC XDefaultGC(), XDefaultGCOfScreen();
unsigned long XBlackPixel(), XWhitePixel(), XAllPlanes();
unsigned long XBlackPixelOfScreen(), XWhitePixelOfScreen();
unsigned long XNextRequest(), XLastKnownRequestProcessed();
char *XServerVendor(), *XDisplayString();
Colormap XDefaultColormap(), XDefaultColormapOfScreen();
Display *XDisplayOfScreen();
Screen *XScreenOfDisplay(), *XDefaultScreenOfDisplay();
long XEventMaskOfScreen();
#endif  /* __cplusplus */

/* These routines are added for C++
   There was no decl for them in Xlib earlier */

#ifdef __cplusplus
void XClearArea (Display *, Window, int, int, unsigned int, unsigned int, Bool);
void XClearWindow(Display*, Window);
void XCopyGC(Display*, GC src, unsigned int, GC dst);
void XChangeGC(Display*, GC, unsigned long, XGCValues*);
void XCopyArea ( Display *, Drawable, Drawable, GC, int, int, unsigned int,
         unsigned int, int, int);
void XCopyPlane ( Display *, Drawable, Drawable, GC, int, int, unsigned int,
         unsigned int, int, int, unsigned long);
void XFreeCursor ( Display *, Cursor);
void XFreeGC (Display *, GC);
void XFreePixmap (Display *, Pixmap);
void  XSetState(
   Display *, GC, unsigned long, unsigned long, int, unsigned long);

void XCloseDisplay(Display*);
void XSetScreenSaver( Display*, int , int , int , int );
void XForceScreenSaver(Display*, int);
void XActivateScreenSaver(Display*);
void XResetScreenSaver(Display*);
void XGetScreenSaver(Display*, int* , int* , int* , int*);
void XAddHost(Display*, XHostAddress*);
void XAddHosts(Display*, XHostAddress[], int);
void XRemoveHost(Display*, XHostAddress*);
void XRemoveHosts(Display*, XHostAddress[], int);
void XDestroyWindow(Display*, Window);
void XDestroySubwindows(Display*, Window);
void XMapWindow(Display*, Window);
void XMapRaised(Display*, Window);
void XMapSubwindows(Display*, Window);
void XUnmapWindow(Display*, Window);
void XUnmapSubwindows(Display*, Window);
void XConfigureWindow(Display*, Window, unsigned int, XWindowChanges*);
void XMoveWindow(Display*, Window, int , int );
void XResizeWindow( Display*, Window, unsigned int , unsigned int );
void XMoveResizeWindow(
     Display*, Window, int , int , unsigned int , unsigned int );
void XSetWindowBorderWidth(Display*, Window, unsigned int width);
void XRaiseWindow(Display*, Window);
void XLowerWindow(Display*, Window);
void XCirculateSubwindows(Display*, Window, int direction);
void XCirculateSubwindowsUp(Display*, Window);
void XCirculateSubwindowsDown(Display*, Window);
void XRestackWindows(Display*, Window[], int nwindows);
void XChangeWindowAttributes(
    Display*, Window, unsigned long, XSetWindowAttributes*
);
void XSetWindowBackground(Display*, Window, unsigned long);
void XSetWindowBackgroundPixmap(Display*, Window, Pixmap);
void XSetWindowBorder(Display*, Window, unsigned long);
void XSetWindowBorderPixmap(Display*, Window, Pixmap);
void XRecolorCursor(Display*, Cursor, XColor* fg, XColor* bg);
void XFreeCursor(Display*, Cursor);
Status XQueryBestCursor(
    Display*, Drawable, unsigned int width, unsigned int height,
    unsigned int* rwidth, unsigned int* rheight
);
void XDefineCursor(Display*, Window, Cursor);
void XUndefineCursor(Display*, Window);
Status XQueryTree(
    Display*, Window, Window* root, Window* parent,
    Window** children, unsigned int* nchildren
);
Status XGetWindowAttributes(Display*, Window, XWindowAttributes*);
Status XGetGeometry(
    Display*, Drawable, Window* root, int* x, int* y,
    unsigned int* width, unsigned int* height,
    unsigned int* bwidth, unsigned int* depth
);
int XTranslateCoordinates(
    Display*, Window src, Window dst, int srcx, int srcy,
    int* dstx, int* dsty, Window* child
);
int XGetWindowProperty(
    Display*, Window, Atom, long offset, long len, Bool del,
    Atom req_type, Atom* actual_type, int* actual_format, unsigned long* n,
    unsigned long* bytes_after, unsigned char** prop
);
void XChangeProperty(
    Display*, Window, Atom prop, Atom type, int format, int mode,
    const unsigned char* data, int nelements
);
void XRotateWindowProperties(Display*, Window, Atom[], int n, int npos);
void XDeleteProperty(Display*, Window, Atom);

void XSetSelectionOwner(Display*, Atom, Window, Time);
void XConvertSelection(
    Display*, Atom selection, Atom target, Atom prop,
    Window requestor, Time
);
void XStoreName(Display*, Window, const char*);
Status XFetchName(Display*, Window, char**);
void XSetIconName(Display*, Window, const char*);
Status XGetIconName(Display*, Window, char**);
void XSetCommand(Display*, Window, char* argv[], int argc);

void XFreeColormap(Display*, Colormap);
void XSetWindowColormap(Display*, Window, Colormap);
Status XAllocColor(Display*, Colormap, XColor*);
Status XAllocNamedColor(Display*, Colormap,const char*, XColor*, XColor*);
Status XLookupColor(Display*, Colormap, const char*, XColor*, XColor*);
void XStoreColors(Display*, Colormap, XColor[], int);
void XStoreColor(Display*, Colormap, XColor*);
Status XAllocColorCells(
    Display*, Colormap, Bool, unsigned long plane[], unsigned int nplanes,
    unsigned long[], unsigned int ncolors
);
Status XAllocColorPlanes(
    Display*, Colormap, Bool, unsigned long[], int ncolors,
    int nreds, int ngreens, int nblues,
    unsigned long* rmask, unsigned long* gmask, unsigned long* bmask
);
void XStoreNamedColor(Display*, Colormap, const char*, unsigned long, int);

void XFreeColors(
    Display*, Colormap, unsigned long[], int, unsigned long nplanes
);
void XQueryColor(Display*, Colormap, XColor*);
void XQueryColors(Display*, Colormap, XColor[], int ncolors);
void XFreeFont(Display*, XFontStruct*);
Bool XGetFontProperty(XFontStruct*, Atom, unsigned long*);
void XSetFontPath(Display*, char**, int);
void XFreeFontPath(char**);
int XTextWidth(XFontStruct*,const  char*, int);
int XTextWidth16(XFontStruct*, const XChar2b*, int);
void XTextExtents(
    XFontStruct*,const char*, int,
    int* direction, int* ascent, int* descent, XCharStruct* overall
);
void XTextExtents16(
    XFontStruct*, const XChar2b*, int, int* direction,
    int* ascent, int* descent, XCharStruct* overall
);
void XQueryTextExtents(
    Display*, XID, const char*, int,
    int* direction, int* ascent, int* descent, XCharStruct* overall
);

void XQueryTextExtents16(
    Display*, XID, const XChar2b*, int,
    int* direction, int* ascent, int* descent, XCharStruct* overall
);

void XDrawText(Display*, Drawable, GC, int x, int y, XTextItem[], int);
void XDrawText16(Display*, Drawable, GC, int x, int y, XTextItem16[], int);
void XDrawString16(
    Display*, Drawable, GC, int x, int y, const XChar2b*, int
);
void XDrawImageString16(
    Display*, Drawable, GC, int x, int y, const XChar2b*, int
);

void XSetFunction(Display*, GC, int);
void XSetPlaneMask(Display*, GC, unsigned long);
void XSetForeground(Display*, GC, unsigned long);
void XSetBackground(Display*, GC, unsigned long);
void XSetLineAttributes(
    Display*, GC, unsigned int width, int style, int cap, int join
);
void XSetDashes(Display*, GC, int offset, const char* dash, int n);
void XSetFillStyle(Display*, GC, int);
void XSetFillRule(Display*, GC, int);
Status XQueryBestSize(
    Display*, int, Drawable, unsigned int width, unsigned int height,
    unsigned int* rwidth, unsigned int* rheight
);
Status XQueryBestTile(
    Display*, Drawable, unsigned int width, unsigned int height,
    unsigned int* rwidth, unsigned int* rheight
);
Status XQueryBestStipple(
    Display*, Drawable, unsigned int width, unsigned int height,
    unsigned int* rwidth, unsigned int* rheight
);
void XSetTile(Display*, GC, Pixmap);
void XSetStipple(Display*, GC, Pixmap);
void XSetTSOrigin(Display*, GC, int x, int y);

void XSetFont(Display*, GC, Font);
void XSetClipOrigin(Display*, GC, int x, int y);
void XSetClipMask(Display*, GC, Pixmap);
void XSetClipRectangles(
    Display*, GC, int x, int y, XRectangle[], int n, int ordering
);
void XSetArcMode(Display*, GC, int);
void XSetSubwindowMode(Display*, GC, int);
void XSetGraphicsExposures(Display*, GC, Bool);
void XDrawPoint(Display*, Drawable, GC, int x, int y);
void XDrawPoints(Display*, Drawable, GC, XPoint[], int, int mode);
void XDrawLine(Display*, Drawable, GC, int x1, int y1, int x2, int y2);
void XDrawLines(Display*, Drawable, GC, XPoint[], int n, int mode);
void XDrawSegments(Display*, Drawable, GC, XSegment[], int);
void XDrawRectangle(
    Display*, Drawable, GC, int x, int y,
    unsigned int width, unsigned int height
);

void XDrawRectangles(Display*, Drawable, GC, struct XRectangle[], int);
void XDrawArc(
    Display*, Drawable, GC, int x, int y,
    unsigned int width, unsigned int height,
    int angle1, int angle2
);
void XDrawArcs(Display*, Drawable, GC, XArc[], int);
void XFillRectangle(
    Display*, Drawable, GC, int x, int y,
    unsigned int width, unsigned int height
);
void XFillRectangles(Display*, Drawable, GC, XRectangle[], int);
void XFillPolygon(
    Display*, Drawable, GC, XPoint[], int, int shape, int mode
);
void XFillArc(
    Display*, Drawable, GC, int x, int y,
    unsigned int width, unsigned int height,
    int angle1, int angle2
);
void XFillArcs(Display*, Drawable, GC, XArc[], int);

void XDrawString(Display*, Drawable, GC, int x, int y, const char*, int);
void XDrawImageString(
    Display*, Drawable, GC, int x, int y, const char*, int
);
void XGrabButton(
    Display*, unsigned int, unsigned int, Window, Bool,
    unsigned int, int ptrmode, int kbdmode, Window confined, Cursor
);
void XUngrabButton(Display*, unsigned int, unsigned int, Window);
int XGrabPointer(
    Display*, Window, Bool, unsigned int, int ptrmode, int kbdmode,
    Window confined, Cursor, Time
);
void XUngrabPointer(Display*, Time);
void XChangeActivePointerGrab(Display*, unsigned int, Cursor, Time);
void XGrabKeyboard(Display*, Window, Bool, int ptrmode, int kbdmode, Time);
void XUngrabKeyboard(Display*, Time);
void XGrabKey(
    Display*, int, unsigned int, Window, Bool, int ptrmode, int kbdmode
);
void XUngrabKey(Display*, int key, unsigned int, Window);
void XAllowEvents(Display*, int, Time);

void XGrabServer(Display*);
void XUngrabServer(Display*);

void XWarpPointer(
    Display*, Window src, Window dst, int srcx, int srcy,
    unsigned int width, unsigned int height, int dstx, int dsty
);
void XSetInputFocus(Display*, Window, int revert, Time);
void XGetInputFocus(Display*, Window*, int* revert);

void XChangePointerControl(
    Display*, Bool has_acc, Bool has_thresh, int acc1, int acc2, int thresh
);
void XGetPointerControl(Display*, int* acc1, int* acc2, int* thresh);

void XChangeKeyboardControl(Display*, unsigned long, XKeyboardControl*);
void XGetKeyboardControl(Display*, XKeyboardState*);
void XAutoRepeatOn(Display*);
void XAutoRepeatOff(Display*);
void XBell(Display*, int percent);
int XSetPointerMapping(Display*, const unsigned char*, int);
int XGetPointerMapping(Display*, unsigned char[], int);

Bool XQueryPointer(
    Display*, Window, Window* root, Window* child, int* x0, int* y0,
    int* wx, int* wy, unsigned int*
);

void XChangeKeyboardMapping(Display*, int first, int percode, KeySym[], int);
int XSetModifierMapping(Display*, XModifierKeymap*);
void XQueryKeymap(Display*, char keys[32]);

void XSelectInput(Display*, Window, unsigned long);

void XFlush(Display*);
void XSync(Display*, int);
int XPending(Display*);
void XNextEvent(Display*, XEvent*);
void XPeekEvent(Display*, XEvent*);
typedef Bool (*XPredicate)(Display*, XEvent*, char*);

void XIfEvent(Display*, XEvent*, XPredicate, char*);
int XCheckIfEvent(Display*, XEvent*, XPredicate, char*);
void XPeekIfEvent(Display*, XEvent*, XPredicate, char*);
void XPutBackEvent(Display*, XEvent*);
void XWindowEvent(Display*, Window, long, XEvent*);
int XCheckWindowEvent(Display*, Window, int, XEvent*);
void XMaskEvent(Display*, unsigned long, XEvent*);
int XCheckMaskEvent(Display*, unsigned long, XEvent*);
void XSendEvent(Display*, Window, Bool, unsigned long, XEvent*);
void XRefereshKeyboardMapping(XMappingEvent*);
int XLookupString(XKeyEvent*, char*, int, KeySym*, struct _XComposeStatus*);
void XRebindKeySym(
    Display*, KeySym, KeySym[], int, unsigned char*, int nbytes
);
void XPutImage(
    Display*, Drawable, GC, XImage*, int srcx, int srcy,
    int dstx, int dsty, unsigned int width, unsigned int height
);
void XAddToExtensionList(_XExtData**,XExtData*);
void XAddToSaveSet(Display*,Window);
int XBitmapBitOrder(Display*);
int XBitmapPad(Display*);
int XBitmapUnit(Display*);
int XCellsOfScreen(Screen*);
Bool XCheckTypedEvent(Display *,int,XEvent *);
Bool XCheckTypedWindowEvent(Display *,Window,int,XEvent *);
int XConnectionNumber(Display*);
int XDefaultDepth(Display*,int);
int XDefaultDepthOfScreen(Screen*);
void XDisableAccessControl(Display*);
int XDisplayCells(Display*, int);
int XDisplayHeight(Display*, int);
int XDisplayHeightMM(Display*, int);
void XDisplayKeycodes(Display*,int*,int*);
int XDisplayPlanes(Display*, int);
int XDisplayWidth(Display*, int);
int XDisplayWidthMM(Display*, int);
int XDoesBackingStore(Screen*);
Bool XDoesSaveUnders(Screen*);
void XEnableAccessControl(Display*);
int XEventsQueued(Display*,int); 
void XFreeFontInfo(char**, XFontStruct *, int);
void XFreeFontNames(char*[]);
void XFreeModifiermap(XModifierKeymap*);
int  XGeometry(Display *,int,const char *,const char *,unsigned int,
               unsigned int, unsigned int,int,int,int *,int *,int*,int*);
void XGetErrorDatabaseText(Display*, const char*, const char*, const char*,
            char*, int);
void XGetErrorText(Display*, int, char*, int);
Status XGetTransientForHint(Display*, Window, Window*);
int XHeightMMOfScreen(Screen *);
int XHeightOfScreen(Screen *);
int XImageByteOrder(Display*);
void XInstallColormap(Display*, Colormap);
KeyCode XKeysymToKeycode(Display*, KeySym);
void XKillClient(Display*, XID);
int XMaxCmapsOfScreen(Screen*);
int XMinCmapsOfScreen(Screen*);
Status XParseColor(Display*,Colormap, const char*,XColor*);
int XPlanesOfScreen(Screen*);
int XProtocolRevision(Display*);
int XProtocolVersion(Display*);
int XQLength(Display*);
void XRefreshKeyboardMapping(XMappingEvent*);
void XRemoveFromSaveSet(Display*,Window);
int XScreenCount(Display*);
void XSetErrorHandler(int (*)(Display*, XErrorEvent*));
void XSetIOErrorHandler(int (*)(Display*));
void XSetTransientForHint(Display*, Window, Window);
void XStoreBuffer(Display*,const char*,int,int);
voidXStoreBytes(Display*,const char*,int);
void XUninstallColormap(Display*, Colormap);
void XUnloadFont(Display*, Font);
int XVendorRelease(Display*);
int XWidthMMOfScreen(Screen*);
int XWidthOfScreen(Screen*);
int XReadBitmapFile(Display*, Drawable, const char*, unsigned int*,
       unsigned int*, Pixmap*, int*, int*);
int XWriteBitmapFile(Display*, const char*, Pixmap,
                      unsigned int, unsigned int, int, int);
Bool XQueryExtension(Display *,const char *, int *, int *, int *);
void XFreeExtensionList(char **);
void XFree(caddr_t);
void XReparentWindow(Display*, Window, Window, int, int);
void XSetAccessControl(Display*, int);
void XNoOp(Display *);
int  XParseGeometry(const char *,int *,int *,unsigned int *,unsigned int *);
void XRotateBuffers(Display*,int);
void XSetCloseDownMode(Display*,int);
#endif

#ifdef __cplusplus
}
#undef class
#undef new
#endif

#endif /* _XLIB_H_ */