(define-interface toy-geometry-interface
  (export make-point
	  point?
	  point-x point-y
	  point+ point-
	  point<?
	  point-in-rectangle?
	  make-rectangle
	  rectangle-x rectangle-y
	  rectangle-origin
	  rectangle-width rectangle-height
	  rectangle-move rectangle?
	  rectangle+ rectangle-
	  rectangle-within))

(define-interface toy-display-system-interface
  (export bitmap-draw-line
	  bitmap-draw-rectangle
	  bitmap-fill-rectangle
	  texture-solid
	  texture-grey
	  texture-horizontal-stripes-1
	  texture-horizontal-stripes-2
	  texture-vertical-stripes-1
	  texture-vertical-stripes-2
	  texture-checker
	  bitmap-bitblt
	  bitmap-draw-text
	  bitmap-text-size

	  make-bitmap
	  bitmap-to-front!
	  bitmap-to-back!
	  bitmap-move!
	  bitmap-delete!
	  bitmap=?
	  bitmap-rectangle
	  bitmap-clear

	  mouse-message-up?
	  mouse-message-down?
	  mouse-message-position
	  mouse-message-translate

	  key-message?
	  key-message-keycode
          key-message-string
	  key-message-down?

	  make-display))

(define-interface toy-window-system-interface
  (export make-control-message
	  control-message?
	  control-message-type control-message-rectangle
	  make-widget-env make-vanilla-widget-env
	  widget-env?
	  widget-env-bitmap
	  widget-env-mouse-channel
	  widget-env-keyboard-channel
	  widget-env-control-in-channel
	  widget-env-control-out-channel

	  realize-widget
	  make-channel-sink
	  make-window-system))

(define-interface toy-frame-interface
  (export frame?
	  frame-border
	  make-frame
	  frame=?
	  frame-widget-env
	  frame-highlight!))

(define-interface toy-button-interface
  (export make-button))

(define-interface toy-window-map-interface
  (export
   make-window-map
   window-map?
   window-map-children
   window-map-widget-to-front!
   window-map-widget-to-back!
   window-map-insert-widget!
   window-map-delete-widget!
   window-map-move-widget!
   window-map-find-by-point))

(define-structure toy-geometry toy-geometry-interface
  (open scheme 
	define-record-types)
  (files geometry))

(define-structure toy-display-system toy-display-system-interface
  (open scheme
	arrays
	(modify xlib 
		(rename (make-rectangle make-xlib-rectangle)
			(rectangle? make-xlib-rectangle?)
			(rectangle:x xlib-rectangle:x)
			(set-rectangle:x! set-xlib-rectangle:x!)
			(rectangle:y xlib-rectangle:y)
			(rectangle:y! set-xlib-rectangle:y!)
			(rectangle:width xlib-rectangle:width)
			(set-rectangle:width! set-xlib-rectangle:width!)
			(rectangle:height xlib-rectangle:height)
			(set-rectangle:height! set-xlib-rectangle:height!)))
	xlib-internal
	locks
	rendezvous
	rendezvous-channels
	(modify signals (hide error))
	big-util queues
	threads
	define-record-types
	i/o

	toy-geometry)
  (files display-system))
;  (files display-system-synced))

(define-structure toy-window-system toy-window-system-interface
  (open scheme threads
	toy-display-system
	rendezvous rendezvous-channels
	rendezvous-async-channels
	define-record-types)
  (files window-system))


(define-structure toy-frame toy-frame-interface
  (open scheme threads
	toy-geometry toy-display-system toy-window-system
	rendezvous rendezvous-channels
	define-record-types)
  (files frame))

(define-structure toy-button toy-button-interface
  (open scheme threads
	toy-geometry toy-display-system toy-window-system
	rendezvous rendezvous-channels
	rendezvous-async-channels
	define-record-types)
  (files button))

(define-structure toy-window-map toy-window-map-interface
  (open scheme threads
	toy-geometry toy-display-system toy-window-system
	rendezvous rendezvous-channels
	define-record-types
	(subset srfi-1 (delete)))
  (files window-map))
