import xlib, x

#fixes
const
 #/* There's only one cursor event so far */
 XFixesDisplayCursorNotify* = 0
 XFixesCursorNotify* =  1
 XFixesDisplayCursorNotifyMask* = (1 shl 0) # 1L (?)
 XFixesNumberEvents* = 2

 XFIXES_MINOR* = 0
 XFIXES_REVISION* = 1
 XFIXES_MAJOR* = 6
 XFIXES_VERSION* = 60001#	((XFIXES_MAJOR * 10000) + (XFIXES_MINOR * 100) + (XFIXES_REVISION))

type 
 XFixesSelectionNotifyEvent* {.bycopy.} = object
  typee*: int
  serial*: culong
  send_event*: bool
  display*: ptr Display
  window*: Window
  subtype*: int
  owner*: Window
  selection*: Atom
  timestamp*: Time
  selection_timestamp*: Time
 
 XFixesCursorNotifyEvent* {.bycopy.} = object
  typee*: int
  serial*: culong
  send_event*: bool
  display*: ptr Display
  window*: Window
  subtype*: int
  cursor_serial*: culong
  timestamp*: Time
  cursor_name*: Atom

 XFixesCursorImage* {.bycopy.} = object
  x*: cshort
  y*: cshort
  width*: cushort
  height*: cushort
  xhot*: cushort
  yhot*: cushort
  cursor_serial*: culong
  pixels*: ptr culong
  #if XFIXES_MAJOR >= 2
  atom*: Atom   # /* Version >= 2 only */
  name*: cstring   # /* Version >= 2 only */
#if XFIXES_MAJOR >= 2 ||||| XID == XserverRegion == culong 

 XFixesCursorImageAndName* {.bycopy.} = object
  x*: cshort
  y*: cshort
  width*: cushort
  height*: cushort
  xhot*: cushort
  yhot*: cushort
  cursor_serial*: culong
  pixels*: ptr culong
  atom*: Atom
  name*: cstring
#endif

#_XFUNCPROTOBEGIN

proc XFixesQueryExtension* ( dpy: ptr Display
                          , event_base_return: ptr int
                          , error_base_return1: ptr int
                          ): bool {.importc, cdecl.}
                          
proc XFixesSelectCursorInput* ( dpy: ptr Display
                              , win:  Window
                              , eventMask: culong
                              ): void {.importc, cdecl.}
 
 #[
Status XFixesQueryVersion (Display *dpy,
			    int     *major_version_return,
			    int     *minor_version_return);

int XFixesVersion (void);

void
XFixesChangeSaveSet (Display	*dpy,
		     Window	win,
		     int	mode,
		     int	target,
		     int	map);

void
XFixesSelectSelectionInput (Display	    *dpy,
			    Window	    win,
			    Atom	    selection,
			    unsigned long   eventMask);

;

XFixesCursorImage *
XFixesGetCursorImage (Display *dpy);

#if XFIXES_MAJOR >= 2
/* Version 2 functions */

culong
XFixesCreateRegion (Display *dpy, XRectangle *rectangles, int nrectangles);

culong
XFixesCreateRegionFromBitmap (Display *dpy, Pixmap bitmap);

culong
XFixesCreateRegionFromWindow (Display *dpy, Window window, int kind);

culong
XFixesCreateRegionFromGC (Display *dpy, GC gc);

culong
XFixesCreateRegionFromPicture (Display *dpy, XID picture);

void
XFixesDestroyRegion (Display *dpy, culong region);

void
XFixesSetRegion (Display *dpy, culong region,
		 XRectangle *rectangles, int nrectangles);

void
XFixesCopyRegion (Display *dpy, culong dst, culong src);

void
XFixesUnionRegion (Display *dpy, culong dst,
		   culong src1, culong src2);

void
XFixesIntersectRegion (Display *dpy, culong dst,
		       culong src1, culong src2);

void
XFixesSubtractRegion (Display *dpy, culong dst,
		      culong src1, culong src2);

void
XFixesInvertRegion (Display *dpy, culong dst,
		    XRectangle *rect, culong src);

void
XFixesTranslateRegion (Display *dpy, culong region, int dx, int dy);

void
XFixesRegionExtents (Display *dpy, culong dst, culong src);

XRectangle *
XFixesFetchRegion (Display *dpy, culong region, int *nrectanglesRet);

XRectangle *
XFixesFetchRegionAndBounds (Display *dpy, culong region,
			    int *nrectanglesRet,
			    XRectangle *bounds);

void
XFixesSetGCClipRegion (Display *dpy, GC gc,
		       int clip_x_origin, int clip_y_origin,
		       culong region);

void
XFixesSetWindowShapeRegion (Display *dpy, Window win, int shape_kind,
			    int x_off, int y_off, culong region);

void
XFixesSetPictureClipRegion (Display *dpy, XID picture,
			    int clip_x_origin, int clip_y_origin,
			    culong region);

void
XFixesSetCursorName (Display *dpy, Cursor cursor, const char *name);

const char *
XFixesGetCursorName (Display *dpy, Cursor cursor, Atom *atom);

void
XFixesChangeCursor (Display *dpy, Cursor source, Cursor destination);

void
XFixesChangeCursorByName (Display *dpy, Cursor source, const char *name);

#endif	/* XFIXES_MAJOR >= 2 */

#if XFIXES_MAJOR >= 3

void
XFixesExpandRegion (Display *dpy, culong dst, culong src,
		    unsigned left, unsigned right,
		    unsigned top, unsigned bottom);

#endif	/* XFIXES_MAJOR >= 3 */

#if XFIXES_MAJOR >= 4
/* Version 4.0 externs */

void
XFixesHideCursor (Display *dpy, Window win);

void
XFixesShowCursor (Display *dpy, Window win);

#endif /* XFIXES_MAJOR >= 4 */

#if XFIXES_MAJOR >= 5

typedef XID PointerBarrier;

PointerBarrier
XFixesCreatePointerBarrier(Display *dpy, Window w, int x1, int y1,
			   int x2, int y2, int directions,
			   int num_devices, int *devices);

void
XFixesDestroyPointerBarrier(Display *dpy, PointerBarrier b);

#endif /* XFIXES_MAJOR >= 5 */

#if XFIXES_MAJOR >= 6

void
XFixesSetClientDisconnectMode(Display *dpy, int disconnect_mode);

int
XFixesGetClientDisconnectMode(Display *dpy);

#endif /* XFIXES_MAJOR >= 6 */

_XFUNCPROTOEND

#endif /* _XFIXES_H_ */
#/

#[
#proto
#include <X11/Xmd.h>
#include <X11/extensions/xfixeswire.h>
#include <X11/extensions/shapeconst.h>

#define Window CARD32
#define Drawable CARD32
#define Font CARD32
#define Pixmap CARD32
#define Cursor CARD32
#define Colormap CARD32
#define GContext CARD32
#define Atom CARD32
#define VisualID CARD32
#define Time CARD32
#define KeyCode CARD8
#define KeySym CARD32
#define Picture CARD32

/*************** Version 1 ******************/

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
} xXFixesReq;

/*
 * requests and replies
 */
typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    CARD32  majorVersion;
    CARD32  minorVersion;
} xXFixesQueryVersionReq;

#define sz_xXFixesQueryVersionReq   12

typedef struct {
    BYTE    type;   /* X_Reply */
    BYTE    pad1;
    CARD16  sequenceNumber;
    CARD32  length;
    CARD32  majorVersion;
    CARD32  minorVersion;
    CARD32  pad2;
    CARD32  pad3;
    CARD32  pad4;
    CARD32  pad5;
} xXFixesQueryVersionReply;

#define sz_xXFixesQueryVersionReply	32

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    BYTE    mode;	    /* SetModeInsert/SetModeDelete*/
    BYTE    target;	    /* SaveSetNearest/SaveSetRoot*/
    BYTE    map;	    /* SaveSetMap/SaveSetUnmap */
    BYTE    pad1;
    Window  window;
} xXFixesChangeSaveSetReq;

#define sz_xXFixesChangeSaveSetReq	12

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Window  window;
    Atom    selection;
    CARD32  eventMask;
} xXFixesSelectSelectionInputReq;

#define sz_xXFixesSelectSelectionInputReq   16

typedef struct {
    CARD8   type;
    CARD8   subtype;
    CARD16  sequenceNumber;
    Window  window;
    Window  owner;
    Atom    selection;
    Time    timestamp;
    Time    selectionTimestamp;
    CARD32  pad2;
    CARD32  pad3;
} xXFixesSelectionNotifyEvent;

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Window  window;
    CARD32  eventMask;
} xXFixesSelectCursorInputReq;

#define sz_xXFixesSelectCursorInputReq	12

typedef struct {
    CARD8   type;
    CARD8   subtype;
    CARD16  sequenceNumber;
    Window  window;
    CARD32  cursorSerial;
    Time    timestamp;
    Atom    name;	    /* Version 2 */
    CARD32  pad1;
    CARD32  pad2;
    CARD32  pad3;
} xXFixesCursorNotifyEvent;

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
} xXFixesGetCursorImageReq;

#define sz_xXFixesGetCursorImageReq 4

typedef struct {
    BYTE    type;   /* X_Reply */
    BYTE    pad1;
    CARD16  sequenceNumber;
    CARD32  length;
    INT16   x;
    INT16   y;
    CARD16  width;
    CARD16  height;
    CARD16  xhot;
    CARD16  yhot;
    CARD32  cursorSerial;
    CARD32  pad2;
    CARD32  pad3;
} xXFixesGetCursorImageReply;

#define sz_xXFixesGetCursorImageReply	32

/*************** Version 2 ******************/

#define Region CARD32

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  region;
    /* LISTofRECTANGLE */
} xXFixesCreateRegionReq;

#define sz_xXFixesCreateRegionReq	8

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  region;
    Pixmap  bitmap;
} xXFixesCreateRegionFromBitmapReq;

#define sz_xXFixesCreateRegionFromBitmapReq	12

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  region;
    Window  window;
    CARD8   kind;
    CARD8   pad1;
    CARD16  pad2;
} xXFixesCreateRegionFromWindowReq;

#define sz_xXFixesCreateRegionFromWindowReq	16

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  region;
    GContext gc;
} xXFixesCreateRegionFromGCReq;

#define sz_xXFixesCreateRegionFromGCReq	12

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  region;
    Picture picture;
} xXFixesCreateRegionFromPictureReq;

#define sz_xXFixesCreateRegionFromPictureReq	12

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  region;
} xXFixesDestroyRegionReq;

#define sz_xXFixesDestroyRegionReq	8

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  region;
    /* LISTofRECTANGLE */
} xXFixesSetRegionReq;

#define sz_xXFixesSetRegionReq		8

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  source;
    Region  destination;
} xXFixesCopyRegionReq;

#define sz_xXFixesCopyRegionReq		12

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  source1;
    Region  source2;
    Region  destination;
} xXFixesCombineRegionReq,
  xXFixesUnionRegionReq,
  xXFixesIntersectRegionReq,
  xXFixesSubtractRegionReq;

#define sz_xXFixesCombineRegionReq	16
#define sz_xXFixesUnionRegionReq	sz_xXFixesCombineRegionReq
#define sz_xXFixesIntersectRegionReq	sz_xXFixesCombineRegionReq
#define sz_xXFixesSubtractRegionReq	sz_xXFixesCombineRegionReq

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  source;
    INT16   x, y;
    CARD16  width, height;
    Region  destination;
} xXFixesInvertRegionReq;

#define sz_xXFixesInvertRegionReq	20

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  region;
    INT16   dx, dy;
} xXFixesTranslateRegionReq;

#define sz_xXFixesTranslateRegionReq	12

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  source;
    Region  destination;
} xXFixesRegionExtentsReq;

#define sz_xXFixesRegionExtentsReq	12

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  region;
} xXFixesFetchRegionReq;

#define sz_xXFixesFetchRegionReq	8

typedef struct {
    BYTE    type;   /* X_Reply */
    BYTE    pad1;
    CARD16  sequenceNumber;
    CARD32  length;
    INT16   x, y;
    CARD16  width, height;
    CARD32  pad2;
    CARD32  pad3;
    CARD32  pad4;
    CARD32  pad5;
} xXFixesFetchRegionReply;

#define sz_xXFixesFetchRegionReply	32

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    GContext	gc;
    Region  region;
    INT16   xOrigin, yOrigin;
} xXFixesSetGCClipRegionReq;

#define sz_xXFixesSetGCClipRegionReq	16

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Window  dest;
    BYTE    destKind;
    CARD8   pad1;
    CARD16  pad2;
    INT16   xOff, yOff;
    Region  region;
} xXFixesSetWindowShapeRegionReq;

#define sz_xXFixesSetWindowShapeRegionReq	20

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Picture picture;
    Region  region;
    INT16   xOrigin, yOrigin;
} xXFixesSetPictureClipRegionReq;

#define sz_xXFixesSetPictureClipRegionReq   16

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Cursor  cursor;
    CARD16  nbytes;
    CARD16  pad;
} xXFixesSetCursorNameReq;

#define sz_xXFixesSetCursorNameReq	    12

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Cursor  cursor;
} xXFixesGetCursorNameReq;

#define sz_xXFixesGetCursorNameReq	    8

typedef struct {
    BYTE    type;   /* X_Reply */
    BYTE    pad1;
    CARD16  sequenceNumber;
    CARD32  length;
    Atom    atom;
    CARD16  nbytes;
    CARD16  pad2;
    CARD32  pad3;
    CARD32  pad4;
    CARD32  pad5;
    CARD32  pad6;
} xXFixesGetCursorNameReply;

#define sz_xXFixesGetCursorNameReply	    32

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
} xXFixesGetCursorImageAndNameReq;

#define sz_xXFixesGetCursorImageAndNameReq  4

typedef struct {
    BYTE    type;   /* X_Reply */
    BYTE    pad1;
    CARD16  sequenceNumber;
    CARD32  length;
    INT16   x;
    INT16   y;
    CARD16  width;
    CARD16  height;
    CARD16  xhot;
    CARD16  yhot;
    CARD32  cursorSerial;
    Atom    cursorName;
    CARD16  nbytes;
    CARD16  pad;
} xXFixesGetCursorImageAndNameReply;

#define sz_xXFixesGetCursorImageAndNameReply	32

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Cursor  source;
    Cursor  destination;
} xXFixesChangeCursorReq;

#define sz_xXFixesChangeCursorReq	12

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Cursor  source;
    CARD16  nbytes;
    CARD16  pad;
} xXFixesChangeCursorByNameReq;

#define sz_xXFixesChangeCursorByNameReq	12

/*************** Version 3 ******************/

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Region  source;
    Region  destination;
    CARD16  left;
    CARD16  right;
    CARD16  top;
    CARD16  bottom;
} xXFixesExpandRegionReq;

#define sz_xXFixesExpandRegionReq	20

/*************** Version 4.0 ******************/

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Window  window;
} xXFixesHideCursorReq;

#define sz_xXFixesHideCursorReq	sizeof(xXFixesHideCursorReq)

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Window  window;
} xXFixesShowCursorReq;

#define sz_xXFixesShowCursorReq	sizeof(xXFixesShowCursorReq)

/*************** Version 5.0 ******************/

#define Barrier CARD32

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Barrier barrier;
    Window  window;
    INT16   x1;
    INT16   y1;
    INT16   x2;
    INT16   y2;
    CARD32  directions;
    CARD16  pad;
    CARD16  num_devices;
    /* array of CARD16 devices */
} xXFixesCreatePointerBarrierReq;

#define sz_xXFixesCreatePointerBarrierReq 28

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    Barrier barrier;
} xXFixesDestroyPointerBarrierReq;

#define sz_xXFixesDestroyPointerBarrierReq 8

/*************** Version 6.0 ******************/

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
    CARD32  disconnect_mode;
} xXFixesSetClientDisconnectModeReq;

#define sz_xXFixesSetClientDisconnectModeReq    8

typedef struct {
    CARD8   reqType;
    CARD8   xfixesReqType;
    CARD16  length;
} xXFixesGetClientDisconnectModeReq;

#define sz_xXFixesGetClientDisconnectModeReq    4

typedef struct {
    BYTE        type;                   /* X_Reply */
    CARD8       pad0;
    CARD16      sequenceNumber;
    CARD32      length;
    CARD32      disconnect_mode;
    CARD32      pad1;
    CARD32      pad2;
    CARD32      pad3;
    CARD32      pad4;
    CARD32      pad5;
} xXFixesGetClientDisconnectModeReply;

#define sz_xXFixesGetClientDisconnectModeReply	32

#undef Barrier
#undef Region
#undef Picture
#undef Window
#undef Drawable
#undef Font
#undef Pixmap
#undef Cursor
#undef Colormap
#undef GContext
#undef Atom
#undef VisualID
#undef Time
#undef KeyCode
#undef KeySym

#endif /* _XFIXESPROTO_H_ */
#]/

#[fixesWire
#define XFIXES_NAME	"XFIXES"
#define XFIXES_MAJOR	6
#define XFIXES_MINOR	0

/*************** Version 1 ******************/
#define X_XFixesQueryVersion		    0
#define X_XFixesChangeSaveSet		    1
#define X_XFixesSelectSelectionInput	    2
#define X_XFixesSelectCursorInput	    3
#define X_XFixesGetCursorImage		    4
/*************** Version 2 ******************/
#define X_XFixesCreateRegion		    5
#define X_XFixesCreateRegionFromBitmap	    6
#define X_XFixesCreateRegionFromWindow	    7
#define X_XFixesCreateRegionFromGC	    8
#define X_XFixesCreateRegionFromPicture	    9
#define X_XFixesDestroyRegion		    10
#define X_XFixesSetRegion		    11
#define X_XFixesCopyRegion		    12
#define X_XFixesUnionRegion		    13
#define X_XFixesIntersectRegion		    14
#define X_XFixesSubtractRegion		    15
#define X_XFixesInvertRegion		    16
#define X_XFixesTranslateRegion		    17
#define X_XFixesRegionExtents		    18
#define X_XFixesFetchRegion		    19
#define X_XFixesSetGCClipRegion		    20
#define X_XFixesSetWindowShapeRegion	    21
#define X_XFixesSetPictureClipRegion	    22
#define X_XFixesSetCursorName		    23
#define X_XFixesGetCursorName		    24
#define X_XFixesGetCursorImageAndName	    25
#define X_XFixesChangeCursor		    26
#define X_XFixesChangeCursorByName	    27
/*************** Version 3 ******************/
#define X_XFixesExpandRegion		    28
/*************** Version 4 ******************/
#define X_XFixesHideCursor		    29
#define X_XFixesShowCursor		    30
/*************** Version 5 ******************/
#define X_XFixesCreatePointerBarrier	    31
#define X_XFixesDestroyPointerBarrier	    32
/*************** Version 6 ******************/
#define X_XFixesSetClientDisconnectMode	    33
#define X_XFixesGetClientDisconnectMode	    34

#define XFixesNumberRequests		    (X_XFixesGetClientDisconnectMode+1)

/* Selection events share one event number */
#define XFixesSelectionNotify		    0

/* Within the selection, the 'subtype' field distinguishes */
#define XFixesSetSelectionOwnerNotify	    0
#define XFixesSelectionWindowDestroyNotify  1
#define XFixesSelectionClientCloseNotify    2

#define XFixesSetSelectionOwnerNotifyMask	(1L << 0)
#define XFixesSelectionWindowDestroyNotifyMask	(1L << 1)
#define XFixesSelectionClientCloseNotifyMask	(1L << 2)



/* errors */
#define BadRegion			    0
#define BadBarrier			    1
#define XFixesNumberErrors		    (BadBarrier+1)

#define SaveSetNearest			    0
#define SaveSetRoot			    1

#define SaveSetMap			    0
#define SaveSetUnmap			    1

/*************** Version 2 ******************/

#define WindowRegionBounding		    0
#define WindowRegionClip		    1

/*************** Version 5 ******************/

#define BarrierPositiveX		    (1L << 0)
#define BarrierPositiveY		    (1L << 1)
#define BarrierNegativeX		    (1L << 2)
#define BarrierNegativeY		    (1L << 3)

/*************** Version 6 ******************/

/* The default server behaviour */
#define XFixesClientDisconnectFlagDefault   0
/* The server may disconnect this client to shut down */
#define XFixesClientDisconnectFlagTerminate  (1L << 0)

#endif	/* _XFIXESWIRE_H_ */
#

# shapeConst
#define SHAPENAME "SHAPE"

#define SHAPE_MAJOR_VERSION	1	/* current version numbers */
#define SHAPE_MINOR_VERSION	1

#define ShapeSet			0
#define ShapeUnion			1
#define ShapeIntersect			2
#define ShapeSubtract			3
#define ShapeInvert			4

#define ShapeBounding			0
#define ShapeClip			1
#define ShapeInput			2

#define ShapeNotifyMask			(1L << 0)
#define ShapeNotify			0

#define ShapeNumberEvents		(ShapeNotify + 1)
]#
]#
]#