- (prog1
- (gdk:display-open display)
- #+(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-package "SWANK")
- (let ((read-from-emacs (find-symbol "READ-FROM-EMACS" "SWANK"))
- (stream (funcall (find-symbol "CONNECTION.SOCKET-IO" "SWANK") (symbol-value (find-symbol "*EMACS-CONNECTION*" "SWANK")))))
- (setf (symbol-function (find-symbol "READ-FROM-EMACS" "SWANK"))
- #'(lambda ()
- (loop
- (case (socket:socket-status (cons stream :input) 0 *event-poll-interval*)
- (:input (return (funcall read-from-emacs)))
- (: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.")))))
+ #+(or cmu sbcl)
+ (progn
+ (signal-connect (gdk:display-manager) 'display-opened
+ #'(lambda (display)
+ (let ((fd (gdk:display-connection-number display)))
+ (unless (< fd 0)
+ (let ((handler (add-fd-handler
+ (gdk:display-connection-number display)
+ :input #'main-iterate-all)))
+ (signal-connect display 'closed
+ #'(lambda (is-error-p)
+ (declare (ignore is-error-p))
+ (remove-fd-handler handler))))))))
+ (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-package "SWANK")
+ (let ((read-from-emacs (symbol-function (find-symbol "READ-FROM-EMACS" "SWANK")))
+ (stream (funcall (find-symbol "CONNECTION.SOCKET-IO" "SWANK") (symbol-value (find-symbol "*EMACS-CONNECTION*" "SWANK")))))
+ (setf (symbol-function (find-symbol "READ-FROM-EMACS" "SWANK"))
+ #'(lambda ()
+ (loop
+ (case (socket:socket-status (cons stream :input) 0 *event-poll-interval*)
+ (:input (return (funcall read-from-emacs)))
+ (: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."))
+
+ (gdk:display-open display)))
+