2002-03-17 10:44:45 -05:00
|
|
|
;; Thread-safe event reading *****************************************
|
|
|
|
|
2002-02-08 12:09:43 -05:00
|
|
|
;; wait-event blocks the current thread until an event is available,
|
|
|
|
;; and then it returns this new event.
|
|
|
|
|
2002-03-17 10:44:45 -05:00
|
|
|
(define (wait-event dpy)
|
2003-03-25 13:27:18 -05:00
|
|
|
(if (> (events-queued dpy (queued-mode after-flush)) 0)
|
|
|
|
(next-event dpy)
|
|
|
|
(begin
|
2003-04-01 06:35:12 -05:00
|
|
|
(really-wait-event dpy)
|
2003-03-25 13:27:18 -05:00
|
|
|
(wait-event dpy))))
|
2002-03-17 10:44:45 -05:00
|
|
|
|
2003-04-01 06:35:12 -05:00
|
|
|
(define (really-wait-event dpy . maybe-timeout)
|
|
|
|
;; selects on the port to the X-server and on the internal wakeup
|
|
|
|
;; pipe. We get woke up, if a Xlib-call reads events and puts them
|
|
|
|
;; in the Xlib-internal event queue in our back. See
|
|
|
|
;; general-after-function.
|
|
|
|
(let* ((message-port (display-message-inport dpy))
|
|
|
|
(wakeup-port (display-wakeup-inport dpy))
|
|
|
|
(l (select-port-channels (if (null? maybe-timeout)
|
|
|
|
#f
|
|
|
|
(car maybe-timeout))
|
|
|
|
message-port
|
|
|
|
wakeup-port)))
|
|
|
|
;; read all characters from the wakeup-port
|
|
|
|
(if (member wakeup-port l)
|
|
|
|
(let loop ()
|
|
|
|
(if (char-ready? wakeup-port)
|
|
|
|
(begin
|
|
|
|
(read-char wakeup-port)
|
|
|
|
(loop)))))
|
|
|
|
(member message-port l)))
|
2002-03-17 10:44:45 -05:00
|
|
|
|
|
|
|
;; How to find out if there are events available *********************
|
2002-02-08 12:09:43 -05:00
|
|
|
|
2002-03-17 10:44:45 -05:00
|
|
|
(define-enumerated-type queued-mode :queued-mode
|
|
|
|
queued-mode? queued-modes queued-mode-name queued-mode-index
|
|
|
|
(already after-reading after-flush))
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(define-exported-binding "scx-queued-mode" :queued-mode)
|
|
|
|
|
|
|
|
(import-lambda-definition events-queued (display mode)
|
|
|
|
"scx_Events_Queued")
|
|
|
|
|
|
|
|
(define (event-ready? display)
|
|
|
|
(or (> (events-queued display (queued-mode already)) 0)
|
|
|
|
(char-ready? (display-message-inport display))))
|
2002-03-17 10:44:45 -05:00
|
|
|
|
2002-04-17 10:51:31 -04:00
|
|
|
;; events-pending is identical to events-queued with after-flush
|
2002-03-17 10:44:45 -05:00
|
|
|
;; mode.
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(import-lambda-definition events-pending (display)
|
2002-03-17 10:44:45 -05:00
|
|
|
"scx_Events_Pending")
|
|
|
|
|
|
|
|
;; Other event reading ***********************************************
|
2001-07-09 09:49:38 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(import-lambda-definition next-event (display)
|
2002-03-17 10:44:45 -05:00
|
|
|
"scx_Next_Event")
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(import-lambda-definition peek-event (display)
|
2002-03-17 10:44:45 -05:00
|
|
|
"scx_Peek_Event")
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
;; returns a list of (time . (x . y)) elements
|
|
|
|
(import-lambda-definition get-motion-events (display window from to)
|
2002-03-17 10:44:45 -05:00
|
|
|
"scx_Get_Motion_Events")
|
|
|
|
|
|
|
|
;; Sending events ****************************************************
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
(import-lambda-definition send-event (display window propagate mask event)
|
2002-02-25 08:10:11 -05:00
|
|
|
"scx_Send_Event")
|