#:g-strdup
#:g-string
#:gslist
- #:g-quark))
+ #:g-quark
+ #:+g-priority-high+
+ #:+g-priority-default+
+ #:+g-priority-high-idle+
+ #:+g-priority-default-idle+
+ #:+g-priority-low+
+ #:g-idle-add-full))
(in-package :glib)
(defcfun (g-thread-init "g_thread_init") :void
(vtable :pointer))
-(g-thread-init (null-pointer))
+(defvar *threads-initialized-p* nil)
+
+(unless *threads-initialized-p*
+ (g-thread-init (null-pointer))
+ (setf *threads-initialized-p* t))
(defcenum g-thread-priority
:g-thread-priority-low
(defcfun (get-clipboard "gtk_clipboard_get") g-object
(selection gdk-atom-as-string))
-(export 'get-clipboard)
\ No newline at end of file
+(export 'get-clipboard)
+
+(defcallback call-from-main-loop-callback :boolean
+ ((data :pointer))
+ (restart-case
+ (progn (funcall (get-stable-pointer-value data))
+ nil)
+ (return-from-callback () nil)))
+
+(defun call-from-gtk-main-loop (function &key (priority +g-priority-default-idle+))
+ (g-idle-add-full priority
+ (callback call-from-main-loop-callback)
+ (allocate-stable-pointer function)
+ (callback stable-pointer-free-destroy-notify-callback)))
+
+(export 'call-from-gtk-main-loop)
+
+(defmacro within-main-loop (&body body)
+ `(call-from-gtk-main-loop (lambda () ,@body)))
+
+(export 'within-main-loop)
\ No newline at end of file