Refactor gtype-from-id, gtype-from-name
[cl-gtk2.git] / gtk / gtk.main_loop_events.lisp
blob244a7d770f3c8fc5b617a6f9d24ac8673e75d6a4
1 (in-package :gtk)
3 (defcfun gtk-init-check :boolean
4 (argc (:pointer :int))
5 (argv (:pointer (:pointer :string))))
7 (defun gtk-init ()
8 (gtk-init-check (foreign-alloc :int :initial-element 0)
9 (foreign-alloc :string :initial-contents '("/usr/bin/sbcl")))
10 #+nil(with-foreign-objects ((argc :int)
11 (argv '(:pointer :string) 1))
12 (setf (mem-ref argc :int) 0
13 (mem-ref argv '(:pointer :string)) (foreign-alloc :string :count 1
14 :initial-element "/usr/bin/sbcl"))
15 (unwind-protect
16 (unless (gtk-init-check argc argv)
17 (error "Cannot initialize Gtk+"))
18 (foreign-free (mem-ref argv '(:pointer :string))))))
20 (at-init () (gtk-init))
22 (defcfun (%gtk-main "gtk_main") :void)
24 (defun gtk-main ()
25 (with-gdk-threads-lock (%gtk-main)))
27 #+thread-support
28 (progn
29 (defvar *main-thread* nil)
30 (defvar *main-thread-level* nil)
31 (defvar *main-thread-lock* (bt:make-lock "*main-thread* lock"))
33 (at-finalize ()
34 (when (and *main-thread* (bt:thread-alive-p *main-thread*))
35 (bt:destroy-thread *main-thread*)
36 (setf *main-thread* nil)))
38 (defun ensure-gtk-main ()
39 (bt:with-lock-held (*main-thread-lock*)
40 (when (and *main-thread* (not (bt:thread-alive-p *main-thread*)))
41 (setf *main-thread* nil))
42 (unless *main-thread*
43 (setf *main-thread* (bt:make-thread (lambda () (gtk-main)) :name "cl-gtk2 main thread")
44 *main-thread-level* 0))
45 (incf *main-thread-level*))
46 (values))
48 (defun join-gtk-main ()
49 (when *main-thread*
50 (bt:join-thread *main-thread*)))
52 (defun leave-gtk-main ()
53 (bt:with-lock-held (*main-thread-lock*)
54 (decf *main-thread-level*)
55 (when (zerop *main-thread-level*)
56 (gtk-main-quit)))))
58 #-thread-support
59 (progn
60 (defun ensure-gtk-main ()
61 (gtk-main)
62 (values))
64 (defun leave-gtk-main ()
65 (gtk-main-quit))
67 (defun join-gtk-main ()))
69 (export 'ensure-gtk-main)
71 (export 'leave-gtk-main)
73 (export 'join-gtk-main)
75 (defcfun gtk-main-level :uint)
77 (defcfun gtk-main-quit :void)
79 (defcfun gtk-grab-add :void
80 (widget g-object))
82 (defcfun gtk-grab-get-current g-object)
84 (defcfun gtk-grab-remove :void
85 (widget g-object))