Improved gtk threading: added with-* macros, functions to call gtk-main
[cl-gtk2.git] / gtk / gtk.main_loop_events.lisp
1 (in-package :gtk)
2
3 (defcfun gtk-init-check :boolean
4   (argc (:pointer :int))
5   (argv (:pointer (:pointer :string))))
6
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))))))
19
20 (gtk-init)
21
22 (defcfun gtk-test-register-all-types :void)
23
24 (gtk-test-register-all-types)
25
26 (defcfun gtk-events-pending :boolean)
27
28 (defcfun gtk-main :void)
29
30 #+thread-support
31 (defun ensure-gtk-main ()
32   (unless (find "gtk main thread" (bt:all-threads) :test 'string= :key 'bt:thread-name)
33     (bt:make-thread (lambda () (gtk:gtk-main)) :name "gtk main thread")))
34
35 #-thread-support
36 (defun ensure-gtk-main ()
37   (gtk-main))
38
39 (export 'ensure-gtk-main)
40
41 #+thread-support
42 (defun leave-gtk-main ()) ;noop on multithreading
43
44 #-thread-support
45 (defun leave-gtk-main ()
46   (gtk-main-quit))
47
48 (export 'leave-gtk-main)
49
50 (defcfun gtk-main-level :uint)
51
52 (defcfun gtk-main-quit :void)
53
54 (defcfun gtk-main-iteration :boolean)
55
56 (defcfun gtk-main-iteration-do :boolean
57   (blocking :boolean))
58
59 (defcfun gtk-grab-add :void
60   (widget g-object))
61
62 (defcfun gtk-grab-get-current g-object)
63
64 (defcfun gtk-grab-remove :void
65   (widget g-object))