(:file "gobject.cffi-callbacks")
(:file "gobject.foreign-gobject-subclassing")
- (:file "gobject.boxed")
-
- #+sbcl (:file "sbcl"))
+ (:file "gobject.boxed"))
:depends-on (:cffi :trivial-garbage :iterate :bordeaux-threads :iterate :closer-mop))
\ No newline at end of file
#:g-idle-add-full
#:g-idle-add
#:g-timeout-add-full
- #:g-source-remove)
+ #:g-source-remove
+ #:at-finalize)
(:documentation
"Cl-gtk2-glib is wrapper for @a[http://library.gnome.org/devel/glib/]{GLib}."))
(defun register-initializer (key fn)
(unless (gethash key *initializers-table*)
(setf (gethash key *initializers-table*) t
- *initializers* (nconc *initializers* (list fn))))))
+ *initializers* (nconc *initializers* (list fn)))))
+ (defvar *finalizers-table* (make-hash-table :test 'equalp))
+ (defvar *finalizers* nil)
+ (defun register-finalizer (key fn)
+ (unless (gethash key *finalizers-table*)
+ (setf (gethash key *finalizers-table*) t
+ *finalizers* (nconc *finalizers* (list fn))))))
(defun run-initializers ()
(iter (for fn in *initializers*)
(funcall fn)))
+(defun run-finalizers ()
+ (iter (for fn in *finalizers*)
+ (funcall fn)))
+
+#+sbcl
+(pushnew 'run-initializers sb-ext:*init-hooks*)
+
+#+sbcl
+(pushnew 'run-finalizers sb-ext:*save-hooks*)
+
(defmacro at-init ((&rest keys) &body body)
"
@arg[keys]{list of expression}
`(progn (register-initializer (list ,@keys ',body) (lambda () ,@body))
,@body))
+(defmacro at-finalize ((&rest keys) &body body)
+ `(register-finalizer (list ,@keys ',body) (lambda () ,@body)))
+
(eval-when (:compile-toplevel :load-toplevel :execute)
(define-foreign-library glib
(:unix (:or "libglib-2.0.so.0" "libglib-2.0.so"))
(defvar *current-object-from-pointer* nil)
(defvar *currently-making-object-p* nil)
+(at-finalize ()
+ (clrhash *foreign-gobjects-weak*)
+ (clrhash *foreign-gobjects-strong*)
+ (setf *current-creating-object* nil
+ *current-object-from-pointer* nil
+ *currently-making-object-p* nil))
+
(defun ref-count (pointer)
(foreign-slot-value (if (pointerp pointer) pointer (pointer pointer)) 'g-object-struct :ref-count))
+++ /dev/null
-(in-package :glib)
-
-#+thread-support
-(progn
- (defun glib-stop-thread ()
- (setf *threads-initialized-p* nil))
- (pushnew 'glib-stop-thread sb-ext:*save-hooks*))
-
-(defun map-inherited-classes (class fn)
- (when (symbolp class) (setf class (find-class class)))
- (when class
- (funcall fn class)
- (iter (for subclass in (closer-mop:class-direct-subclasses class))
- (map-inherited-classes subclass fn))))
-
-(pushnew 'run-initializers sb-ext:*init-hooks*)
(:file "gtk.dialog.example")
(:file "gtk.demo")
- #+sbcl (:file "sbcl")
(:module "demo-files"
:pathname "demo"
:components ((:static-file "demo1.glade")
(error "Cannot initialize Gtk+"))
(foreign-free (mem-ref argv '(:pointer :string))))))
-(gtk-init)
+(at-init () (gtk-init))
(defcfun gtk-main :void)
(defvar *main-thread* nil)
#+thread-support
+(at-finalize ()
+ (when (and *main-thread* (bt:thread-alive-p *main-thread*))
+ (bt:destroy-thread *main-thread*)
+ (setf *main-thread* nil)))
+
+#+thread-support
(defun ensure-gtk-main ()
(when (and *main-thread* (not (bt:thread-alive-p *main-thread*)))
(setf *main-thread* nil))
(unless *main-thread*
- (setf *main-thread* (bt:make-thread (lambda () (gtk:gtk-main)) :name "cl-gtk2 main thread"))))
+ (setf *main-thread* (bt:make-thread (lambda () (gtk-main)) :name "cl-gtk2 main thread"))))
#+thread-support
(defun join-main-thread ()
(defmacro with-main-loop (&body body)
`(progn
,@body
- (gtk-main)))
+ (ensure-gtk-main)))
(export 'with-main-loop)
\ No newline at end of file
+++ /dev/null
-(in-package :gtk)
-
-#+thread-support
-(progn
- (defun stop-main-thread-on-save ()
- (when (and *main-thread* (bt:thread-alive-p *main-thread*))
- (within-main-loop-and-wait (gtk-main-quit))
- (bt:destroy-thread *main-thread*)
- (setf *main-thread* nil)))
- (defun cl-gtk2-sbcl-init ()
- (gtk-init))
- (pushnew 'cl-gtk2-sbcl-init sb-ext:*init-hooks*)
- (pushnew 'stop-main-thread-on-save sb-ext:*save-hooks*))
-