anchor.diff:  ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   
  -;; $Id: gtk.lisp,v 1.72 2007-06-04 19:03:12 espen Exp $
  +;; $Id: gtk.lisp,v 1.73 2007-06-19 11:32:25 espen Exp $
   
   
   (in-package "GTK")
  
positive.code: 
  ;;;; Initalization and display handling
  
  (defbinding (gtk-init "gtk_parse_args") () boolean
    "Initializes the library without opening the display."
    (nil null)
    (nil null))
  
  (defparameter *event-poll-interval* 10000)
  
  (defun clg-init (&optional display)
    "Initializes the system and starts event handling"
    #+sbcl(when (and 
  	       (find-package "SWANK")
  	       (eq (symbol-value (find-symbol "*COMMUNICATION-STYLE*" "SWANK")) :spawn))
  	  (error "When running clg in Slime the communication style :spawn can not be used. See the README file and <http://common-lisp.net/project/slime/doc/html/slime_45.html> for more information."))
  
    (unless (gdk:display-get-default)
      #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
      (progn
        #+sbcl(sb-int:set-floating-point-modes :traps nil) 
        #+cmu(ext:set-floating-point-modes :traps nil))
  
      (gdk:gdk-init)
      (unless (gtk-init)
        (error "Initialization of GTK+ failed."))
      #?(or (pkg-config:featurep :cmu) (and (pkg-config:featurep :sbcl) (not (pkg-config:sbcl>= 1 0 6))))
      (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*))
      #?(pkg-config:sbcl>= 1 0 6)
      (warn "Periodic polling functionality has been removed from SERVE-EVENT in SBCL 1.0.6. An explicit gtk main loop has to be invoked.")
      #+(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)))
  
  
  #+sbcl	  
  (defun clg-init-with-threading (&optional display)
    "Initializes the system and starts event handling"
    (unless (gdk:display-get-default)
      #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
      (progn
        #+sbcl(sb-int:set-floating-point-modes :traps nil) 
        #+cmu(ext:set-floating-point-modes :traps nil))
  
      (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")))
  
  
  ;;; Generic functions 
  
negative.code: ;;; Window
  
  (defmethod initialize-instance ((window window) &rest initargs 
  				&key display accel-group accel-groups)
    (declare (ignore accel-group accel-groups))
    (prog1
        (if display
  	  (apply #'call-next-method
  	   window :screen (gdk:display-get-default-screen display) initargs)
  	(call-next-method))
      (initial-add window #'window-add-accel-group 
       initargs :accel-group :accel-groups)))
  
  