- (add-fd-handler (gdk:display-connection-number) :input #'main-iterate-all)
- (setq *periodic-polling-function* #'main-iterate-all)
- (setq *max-event-to-sec* 0)
- (setq *max-event-to-usec* 1000))))
+ #+(or cmu sbcl)
+ (progn
+ (add-fd-handler (gdk:display-connection-number) :input #'main-iterate-all)
+ (setq *periodic-polling-function* #'main-iterate-all)
+ (setq *max-event-to-sec* 0)
+ (setq *max-event-to-usec* *event-poll-interval*))
+ #+(and clisp readline)
+ ;; Readline will call the event hook at most ten times per second
+ (setf readline:event-hook #'main-iterate-all)
+ #+clisp
+ ;; When running in Slime we need to hook into the Swank server
+ ;; to handle events asynchronously
+ (if (find-symbol "WAIT-UNTIL-READABLE" "SWANK")
+ (setf (symbol-function 'swank::wait-until-readable)
+ #'(lambda (stream)
+ (loop
+ (case (socket:socket-status (cons stream :input) 0 *event-poll-interval*)
+ (:input (return t))
+ (:eof (read-char stream))
+ (otherwise (main-iterate-all))))))
+ #-readline(warn "Not running in Slime and Readline support is missing, so the Gtk main loop has to be invoked explicit.")))))
+
+#+sbcl
+(defun clg-init-with-threading (&optional display)
+ "Initializes the system and starts the event handling"
+ (unless (gdk:display-get-default)
+ (gdk:gdk-init)
+ (gdk:threads-set-lock-functions)
+ (unless (gtk-init)
+ (error "Initialization of GTK+ failed."))
+ (sb-thread:make-thread
+ #'(lambda ()
+ (gdk:display-open display)
+ (gdk:with-global-lock (main)))
+ :name "gtk event loop")))
+