replaced the timeout in wait-event with a select on a pipe that wakes up
a wait-event call in the after-function.
This commit is contained in:
parent
c813f7466b
commit
87ee1ef07d
|
@ -26,38 +26,22 @@
|
||||||
|
|
||||||
(define-exported-binding "scx-display" :display)
|
(define-exported-binding "scx-display" :display)
|
||||||
|
|
||||||
;(define (wakeup-display dpy)
|
(define (wakeup-display dpy)
|
||||||
; (placeholder-set! dpy #t))
|
(write-char #\x (cdr (display:wakeup dpy))))
|
||||||
|
|
||||||
;(define (sleep-display dpy)
|
(define (display-wakeup-inport dpy)
|
||||||
; (let ((ph (make-placeholder)))
|
(car (display:wakeup dpy)))
|
||||||
; (set-display:wakeup! dpy ph)
|
|
||||||
; (placeholder-value ph)))
|
|
||||||
|
|
||||||
(define (initialize-display dpy)
|
(define (initialize-display dpy)
|
||||||
; (set-display:wakeup! dpy (make-placeholder))
|
(call-with-values pipe
|
||||||
; ;; spawn a thread that weaks up a waiting wait-event call if the
|
(lambda (r w)
|
||||||
; ;; inport has data available
|
(set-display:wakeup! dpy (cons r w)))))
|
||||||
; (spawn (lambda ()
|
|
||||||
; (let loop ()
|
|
||||||
; (block-on-message-inport dpy)
|
|
||||||
; (wakeup-display dpy)
|
|
||||||
; (loop))))
|
|
||||||
;; the after-function may also send a wakup
|
|
||||||
#t)
|
|
||||||
|
|
||||||
(define-exported-binding "scx-initialize-display" initialize-display)
|
(define-exported-binding "scx-initialize-display" initialize-display)
|
||||||
|
|
||||||
(define (display-message-inport display)
|
(define (display-message-inport display)
|
||||||
(fdes->inport (display:connection-number display)))
|
(fdes->inport (display:connection-number display)))
|
||||||
|
|
||||||
(define (block-on-message-inport dpy . maybe-timeout)
|
|
||||||
(let ((port (display-message-inport dpy)))
|
|
||||||
(call-with-values
|
|
||||||
(lambda () (apply select (vector port) (vector) (vector) maybe-timeout))
|
|
||||||
(lambda (ready-read ready-write ex)
|
|
||||||
(member port (vector->list ready-read))))))
|
|
||||||
|
|
||||||
(define-enumerated-type byte-order :byte-order
|
(define-enumerated-type byte-order :byte-order
|
||||||
byte-order? byte-orders byte-order-name byte-order-index
|
byte-order? byte-orders byte-order-name byte-order-index
|
||||||
(lsb-first msb-first))
|
(lsb-first msb-first))
|
||||||
|
@ -178,10 +162,10 @@
|
||||||
((display:after-function display) display)
|
((display:after-function display) display)
|
||||||
;; else the default behaviour ;; TODO: check if this is the real one
|
;; else the default behaviour ;; TODO: check if this is the real one
|
||||||
(display-flush display))
|
(display-flush display))
|
||||||
)
|
|
||||||
;; if events are in the queue now, then wakeup a wait-event call
|
;; if events are in the queue now, then wakeup a wait-event call
|
||||||
;;(if (> (events-queued display (queued-mode already)) 0)
|
(if (> (events-queued display (queued-mode already)) 0)
|
||||||
;; (wakeup-display display)))
|
(wakeup-display display)))
|
||||||
|
|
||||||
(define-exported-binding "scx-general-after-function" general-after-function)
|
(define-exported-binding "scx-general-after-function" general-after-function)
|
||||||
|
|
||||||
|
|
|
@ -7,24 +7,29 @@
|
||||||
(if (> (events-queued dpy (queued-mode after-flush)) 0)
|
(if (> (events-queued dpy (queued-mode after-flush)) 0)
|
||||||
(next-event dpy)
|
(next-event dpy)
|
||||||
(begin
|
(begin
|
||||||
;;(sleep-display dpy)
|
(really-wait-event dpy)
|
||||||
(block-on-message-inport dpy 0.1)
|
|
||||||
(wait-event dpy))))
|
(wait-event dpy))))
|
||||||
|
|
||||||
;(define (block-on-message-inport dpy) ; needs ports, locks
|
(define (really-wait-event dpy . maybe-timeout)
|
||||||
; (let ((port (display-message-inport dpy)))
|
;; selects on the port to the X-server and on the internal wakeup
|
||||||
; (disable-interrupts!)
|
;; pipe. We get woke up, if a Xlib-call reads events and puts them
|
||||||
; (if (not (char-ready? port))
|
;; in the Xlib-internal event queue in our back. See
|
||||||
; (begin
|
;; general-after-function.
|
||||||
; (obtain-lock (port-lock port))
|
(let* ((message-port (display-message-inport dpy))
|
||||||
; (add-pending-channel (port->channel port))
|
(wakeup-port (display-wakeup-inport dpy))
|
||||||
; (wait-for-channel (port->channel port)) ;; enables interrupts
|
(l (select-port-channels (if (null? maybe-timeout)
|
||||||
; (release-lock (port-lock port)))
|
#f
|
||||||
; (enable-interrupts!))))
|
(car maybe-timeout))
|
||||||
|
message-port
|
||||||
;;; Only here until scsh provides us with select
|
wakeup-port)))
|
||||||
;(import-lambda-definition add-pending-channel (channel)
|
;; read all characters from the wakeup-port
|
||||||
; "scx_add_pending_channel")
|
(if (member wakeup-port l)
|
||||||
|
(let loop ()
|
||||||
|
(if (char-ready? wakeup-port)
|
||||||
|
(begin
|
||||||
|
(read-char wakeup-port)
|
||||||
|
(loop)))))
|
||||||
|
(member message-port l)))
|
||||||
|
|
||||||
;; How to find out if there are events available *********************
|
;; How to find out if there are events available *********************
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue