2003-03-10 21:47:38 -05:00
|
|
|
;; Copyright (c) 2001-2003 by Norbert Freudemann, David Frese
|
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(define-syntax import-xlib-function
|
|
|
|
(lambda (exp rename compare)
|
|
|
|
(let ((id (cadr exp))
|
|
|
|
(formals (caddr exp))
|
|
|
|
(external-id (cadddr exp))
|
|
|
|
(%define (rename 'define))
|
|
|
|
(%begin (rename 'begin))
|
|
|
|
(%lambda (rename 'lambda))
|
|
|
|
(%binding (rename 'binding))
|
|
|
|
(%import (rename 'import-lambda-definition))
|
|
|
|
(%call-xlib-function (rename 'call-xlib-function)))
|
|
|
|
`(,%begin
|
|
|
|
(,%import ,%binding ,formals ,external-id)
|
|
|
|
(,%define ,id
|
|
|
|
(,%lambda ,formals
|
|
|
|
(,%call-xlib-function ,(car formals) ,id
|
|
|
|
(,%lambda ()
|
|
|
|
(,%binding . ,formals)))))))))
|
|
|
|
|
|
|
|
(define (call-xlib-function display name thunk)
|
|
|
|
(if (display? display)
|
|
|
|
(if (display:warnings? display)
|
|
|
|
(call-critical
|
|
|
|
(lambda ()
|
|
|
|
(let* ((queue (display:error-queue display))
|
|
|
|
(result (thunk)))
|
|
|
|
(if (not (eq? queue (display:error-queue display)))
|
|
|
|
(let* ((next (next-x-error-queue queue))
|
|
|
|
(error (x-error-queue:this next)))
|
2003-05-04 13:35:02 -04:00
|
|
|
(signal-x-warning error)))
|
|
|
|
result)))
|
2003-05-01 17:05:33 -04:00
|
|
|
(thunk))
|
|
|
|
(error "first argument of an xlib-function must be a display object"
|
|
|
|
name display)))
|
|
|
|
|
|
|
|
(define (call-critical thunk)
|
2003-05-04 13:35:02 -04:00
|
|
|
(let ((old-enabled (set-enabled-interrupts! no-interrupts)))
|
|
|
|
(with-handler
|
|
|
|
(lambda (condition punt)
|
|
|
|
(set-enabled-interrupts! old-enabled)
|
|
|
|
(punt))
|
|
|
|
(lambda ()
|
|
|
|
(let ((result (thunk)))
|
|
|
|
(set-enabled-interrupts! old-enabled)
|
|
|
|
result)))))
|
2003-05-01 17:05:33 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; TODO: pixmap-formats (XListPixmapFormats)
|
|
|
|
(define-record-type display :display
|
|
|
|
(make-display cpointer connection-number protocol-version protocol-revision
|
|
|
|
server-vendor image-byte-order bitmap-unit bitmap-pad
|
|
|
|
bitmap-bit-order vendor-release queue-length name
|
2003-05-01 17:05:33 -04:00
|
|
|
default-screen screens after-function wakeup
|
|
|
|
warnings? error-queue)
|
2003-03-10 21:47:38 -05:00
|
|
|
display?
|
|
|
|
(cpointer display:cpointer)
|
|
|
|
(connection-number display:connection-number)
|
|
|
|
(protocol-version display:protocol-version)
|
|
|
|
(protocol-revision display:protocol-revision)
|
|
|
|
(server-vendor display:server-vendor)
|
|
|
|
(image-byte-order display:image-byte-order)
|
|
|
|
(bitmap-unit display:bitmap-unit)
|
|
|
|
(bitmap-pad display:bitmap-pad)
|
|
|
|
(bitmap-bit-order display:bitmap-bit-order)
|
|
|
|
(vendor-release display:vendor-release)
|
|
|
|
(queue-length display:queue-length)
|
|
|
|
(name display:name)
|
|
|
|
(default-screen display:default-screen)
|
|
|
|
(screens display:screens)
|
2003-03-25 13:27:18 -05:00
|
|
|
(after-function display:after-function set-display:after-function!)
|
2003-05-01 17:05:33 -04:00
|
|
|
(wakeup display:wakeup set-display:wakeup!)
|
|
|
|
(warnings? display:warnings? set-display:warnings?!)
|
|
|
|
(error-queue display:error-queue set-display:error-queue!))
|
2003-03-10 21:47:38 -05:00
|
|
|
|
|
|
|
(define-exported-binding "scx-display" :display)
|
|
|
|
|
2003-04-01 06:35:12 -05:00
|
|
|
(define (wakeup-display dpy)
|
|
|
|
(write-char #\x (cdr (display:wakeup dpy))))
|
2003-03-25 13:27:18 -05:00
|
|
|
|
2003-04-01 06:35:12 -05:00
|
|
|
(define (display-wakeup-inport dpy)
|
|
|
|
(car (display:wakeup dpy)))
|
2003-03-25 13:27:18 -05:00
|
|
|
|
|
|
|
(define (initialize-display dpy)
|
2003-05-01 17:05:33 -04:00
|
|
|
(set-display:error-queue! dpy (empty-x-error-queue))
|
2003-04-01 06:35:12 -05:00
|
|
|
(call-with-values pipe
|
|
|
|
(lambda (r w)
|
|
|
|
(set-display:wakeup! dpy (cons r w)))))
|
2003-03-25 13:27:18 -05:00
|
|
|
|
|
|
|
(define-exported-binding "scx-initialize-display" initialize-display)
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define (display-message-inport display)
|
|
|
|
(fdes->inport (display:connection-number display)))
|
|
|
|
|
|
|
|
(define-enumerated-type byte-order :byte-order
|
|
|
|
byte-order? byte-orders byte-order-name byte-order-index
|
|
|
|
(lsb-first msb-first))
|
|
|
|
|
|
|
|
(define-exported-binding "scx-byte-order" :byte-order)
|
|
|
|
(define-exported-binding "scx-byte-orders" byte-orders)
|
|
|
|
|
|
|
|
(define-enumerated-type bit-order :bit-order
|
|
|
|
bit-order? bit-orders bit-order-name bit-order-index
|
|
|
|
(lsb-first msb-first))
|
|
|
|
|
|
|
|
(define-exported-binding "scx-bit-order" :bit-order)
|
|
|
|
(define-exported-binding "scx-bit-orders" bit-orders)
|
|
|
|
|
|
|
|
(define-record-type screen-format :screen-format ;; aka pixmap-format
|
|
|
|
(make-screen-format depth bits-per-pixel scanline-pad)
|
|
|
|
screen-format?
|
|
|
|
(depth screen-format:depth)
|
|
|
|
(bits-per-pixel screen-format:bits-per-pixel)
|
|
|
|
(scanline-pad screen-format:scanline-pad))
|
|
|
|
|
|
|
|
(define-exported-binding "scx-screen-format" :screen-format)
|
|
|
|
|
|
|
|
(define-record-type screen :screen
|
|
|
|
(make-screen cpointer display root-window width height width-mm
|
2003-03-13 08:47:17 -05:00
|
|
|
height-mm number root-depth default-visual default-gc
|
2003-03-10 21:47:38 -05:00
|
|
|
default-colormap white-pixel black-pixel max-maps min-maps
|
|
|
|
does-backing-store does-save-unders? event-mask)
|
2003-03-13 08:47:17 -05:00
|
|
|
;; maybe add depths ?? (TODO)
|
2003-03-10 21:47:38 -05:00
|
|
|
;; does event-mask change ?? (TODO)
|
|
|
|
screen?
|
|
|
|
(cpointer screen:cpointer)
|
|
|
|
(display screen:display)
|
|
|
|
(root-window screen:root-window)
|
|
|
|
(width screen:width)
|
|
|
|
(height screen:height)
|
|
|
|
(width-mm screen:width-mm)
|
|
|
|
(height-mm screen:height-mm)
|
2003-03-13 08:47:17 -05:00
|
|
|
(number screen:number)
|
2003-03-10 21:47:38 -05:00
|
|
|
(root-depth screen:root-depth)
|
|
|
|
(default-visual screen:default-visual)
|
|
|
|
(default-gc screen:default-gc)
|
|
|
|
(default-colormap screen:default-colormap)
|
|
|
|
(white-pixel screen:white-pixel)
|
|
|
|
(black-pixel screen:black-pixel)
|
|
|
|
(max-maps screen:max-maps)
|
|
|
|
(min-maps screen:min-maps)
|
|
|
|
(does-backing-store screen:does-backing-store)
|
|
|
|
(does-save-unders? screen:does-save-unders?)
|
|
|
|
(event-mask screen:event-mask))
|
|
|
|
|
|
|
|
(define-exported-binding "scx-screen" :screen)
|
|
|
|
|
|
|
|
;(define (screen:cells screen)
|
|
|
|
; (visual:map-entries (screen:default-visual screen)))
|
|
|
|
|
|
|
|
;; *** connect or disconnect to X server *****************************
|
|
|
|
|
|
|
|
(import-lambda-definition %open-display (display-name)
|
|
|
|
"scx_Open_Display")
|
2001-07-16 09:12:11 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; returns a display or #f
|
2001-05-21 11:32:01 -04:00
|
|
|
(define (open-display . args)
|
|
|
|
(let ((display-name (if (null? args)
|
2003-03-10 21:47:38 -05:00
|
|
|
""
|
|
|
|
(if (null? (cdr args))
|
|
|
|
(cadr args)
|
|
|
|
(error "invalid arguments" (cdr args))))));; TODO
|
|
|
|
(%open-display display-name)))
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function close-display (display)
|
2003-03-10 21:47:38 -05:00
|
|
|
"scx_Close_Display")
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define none 0)
|
|
|
|
(define parent-relative 1)
|
|
|
|
(define copy-from-parent 0)
|
|
|
|
(define pointer-window 0)
|
|
|
|
(define input-focus 1)
|
|
|
|
(define pointer-root 1)
|
|
|
|
(define any-property-type 0)
|
|
|
|
(define any-key 0)
|
|
|
|
(define all-temporary 0)
|
|
|
|
(define current-time 0)
|
|
|
|
(define no-symbol 0)
|
|
|
|
(define all-planes (- (arithmetic-shift 1 32) 1))
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(import-lambda-definition display:last-request-read (display)
|
|
|
|
"scx_Display_Last_Request_Read")
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; *** convenience functions *****************************************
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define (default-root-window display)
|
2003-03-13 10:17:36 -05:00
|
|
|
(screen:root-window (display:default-screen display)))
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-13 08:47:17 -05:00
|
|
|
(define (black-pixel display)
|
2003-03-13 10:17:36 -05:00
|
|
|
(screen:black-pixel (display:default-screen display)))
|
2003-03-13 08:47:17 -05:00
|
|
|
|
|
|
|
(define (white-pixel display)
|
2003-03-13 10:17:36 -05:00
|
|
|
(screen:white-pixel (display:default-screen display)))
|
2003-03-13 08:47:17 -05:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(import-lambda-definition next-request (display)
|
|
|
|
"scx_Next_Request")
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; *** enable or disable synchronization *****************************
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-25 13:27:18 -05:00
|
|
|
(define (synchronize dpy on?)
|
2003-03-10 21:47:38 -05:00
|
|
|
(if on?
|
2003-03-25 13:27:18 -05:00
|
|
|
(set-after-function! dpy
|
|
|
|
(lambda (dpy)
|
|
|
|
(display-sync dpy #f)))
|
|
|
|
(set-after-function! dpy #f)))
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; returns the previous after-function. An after-function is called
|
|
|
|
;; with the display object.
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-25 13:27:18 -05:00
|
|
|
(define (general-after-function display)
|
|
|
|
(if (display:after-function display)
|
|
|
|
((display:after-function display) display)
|
|
|
|
;; else the default behaviour ;; TODO: check if this is the real one
|
|
|
|
(display-flush display))
|
2003-04-01 06:35:12 -05:00
|
|
|
|
2003-03-25 13:27:18 -05:00
|
|
|
;; if events are in the queue now, then wakeup a wait-event call
|
2003-04-01 06:35:12 -05:00
|
|
|
(if (> (events-queued display (queued-mode already)) 0)
|
|
|
|
(wakeup-display display)))
|
2003-03-25 13:27:18 -05:00
|
|
|
|
|
|
|
(define-exported-binding "scx-general-after-function" general-after-function)
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define (set-after-function! display fun)
|
|
|
|
(let ((prev (display:after-function display)))
|
|
|
|
(set-display:after-function! display fun)
|
|
|
|
prev))
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; *** handle output buffer or event queue ***************************
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function display-flush (display)
|
2003-03-10 21:47:38 -05:00
|
|
|
"scx_Display_Flush")
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function display-sync (display discard?)
|
2003-03-10 21:47:38 -05:00
|
|
|
"scx_Display_Sync")
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2001-07-16 09:12:11 -04:00
|
|
|
;; display-no-op sends a NoOperation protocol request to the X server, thereby
|
|
|
|
;; exercising the connection. See XNoOp.
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function display-no-op (display)
|
2001-07-31 10:54:53 -04:00
|
|
|
"scx_No_Op")
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; *** select input events *******************************************
|
2001-05-21 11:32:01 -04:00
|
|
|
|
2003-05-01 17:05:33 -04:00
|
|
|
(import-xlib-function display-select-input (display window event-mask)
|
2001-10-09 11:33:45 -04:00
|
|
|
"scx_Display_Select_Input")
|