+(defmethod allocate-foreign ((region region) &key rectangle polygon fill-rule)
+ (cond
+ ((and rectangle polygon)
+ (error "Only one of the keyword arguments :RECTANGLE and :POLYGON can be specified"))
+ (rectangle (%region-rectangle (ensure-rectangle rectangle)))
+ (polygon (%region-polygon polygon (length polygon) fill-rule))
+ ((%region-new))))
+
+(defun ensure-region (region)
+ (etypecase region
+ (region region)
+ ((or rectangle vector)
+ (make-instance 'region :rectangle (ensure-rectangle region)))
+ (list
+ (make-instance 'region :polygon region))))
+
+(defbinding region-get-clipbox (region &optional (rectangle (make-instance 'rectangle))) nil
+ (region region)
+ (rectangle rectangle :in/return))
+
+(defbinding %region-get-rectangles () nil
+ (region region)
+ (rectangles pointer :out)
+ (n-rectangles int :out))
+
+(defun region-get-rectangles (region)
+ "Obtains the area covered by the region as a list of rectangles."
+ (multiple-value-bind (location length) (%region-get-rectangles region)
+ (prog1
+ (map-c-vector 'list #'identity location '(inlined rectangle) length :get)
+ (deallocate-memory location))))
+
+(defbinding region-empty-p () boolean
+ (region region))
+
+(defbinding region-equal-p () boolean
+ (region1 region)
+ (region2 region))
+
+(defbinding region-point-in-p () boolean
+ (region region)
+ (x int)
+ (y int))
+
+(defbinding region-rect-in (region rectangle) overlap-type
+ (region region)
+ ((ensure-rectangle rectangle) rectangle))
+
+(defbinding region-offset () nil
+ (region region)
+ (dx int)
+ (dy int))
+
+(defbinding region-shrink () nil
+ (region region)
+ (dx int)
+ (dy int))
+
+(defbinding region-intersect (source1 source2) nil
+ ((ensure-region source1) region :in/return)
+ ((ensure-region source2) region))
+
+(defbinding region-union (source1 source2) nil
+ ((ensure-region source1) region :in/return)
+ ((ensure-region source2) region))
+
+(defbinding region-subtract (source1 source2) nil
+ ((ensure-region source1) region :in/return)
+ ((ensure-region source2) region))
+
+(defbinding region-xor (source1 source2) nil
+ ((ensure-region source1) region :in/return)
+ ((ensure-region source2) region))
+
+
+;;; Events
+
+(defbinding (events-pending-p "gdk_events_pending") () boolean)
+
+(defbinding event-get () event)
+
+(defbinding event-peek () event)
+
+(defbinding event-get-graphics-expose () event
+ (window window))
+
+(defbinding event-put () event
+ (event event))
+
+;(defbinding event-handler-set () ...)
+
+(defbinding set-show-events () nil
+ (show-events boolean))
+
+(defbinding get-show-events () boolean)
+
+
+;;; Miscellaneous functions
+
+(defbinding screen-width () int
+ (screen screen))
+
+(defbinding screen-height () int
+ (screen screen))
+
+(defbinding screen-width-mm () int
+ (screen screen))
+
+(defbinding screen-height-mm () int
+ (screen screen))
+
+
+(defbinding pointer-grab
+ (window &key owner-events events confine-to cursor time) grab-status