;;; -*-Scheme-*-

(require 'xlib)

(define (hello-world)
  (let* ((dpy (open-display))
	 (black (black-pixel dpy)) (white (white-pixel dpy))
	 (font (open-font dpy "*-new century schoolbook-bold-r*24*"))
	 (text (translate-text "Hello world!"))
	 (width (+ (text-width font text '1-byte)))
	 (height (+ (max-char-ascent font) (max-char-descent font)))
	 (win (make-window (parent (display-root-window dpy))
			   (width width) (height height)
			   (background-pixel white)
			   (event-mask '(exposure button-press))))
	 (gc (make-gcontext (window win) (background white)
			    (foreground black) (font font))))
    (map-window win)
    (unwind-protect
     (handle-events dpy
       (button-press
	(lambda ignore #t))
       (expose
	(lambda ignore
	  (let ((x (truncate (/ (- (window-width win) width) 2)))
		(y (truncate (/ (- (+ (window-height win)
				      (max-char-ascent font))
				   (max-char-descent font)) 2))))
	    (draw-poly-text win gc x y text '1-byte)) #f)))
     (close-display dpy))))
		  
(hello-world)
