;; License along with this library; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-;; $Id: gcallback.lisp,v 1.5 2002-01-20 14:52:04 espen Exp $
+;; $Id: gcallback.lisp,v 1.9 2004-10-27 14:58:59 espen Exp $
(in-package "GLIB")
(defbinding lisp-callback-closure-new () gclosure
(callback-id unsigned-int))
+(defun register-callback-function (function)
+ (check-type function (or null symbol function))
+ (register-user-data function))
+(defun make-callback-closure (function)
+ (lisp-callback-closure-new (register-callback-function function)))
-;;;; Callback mechanism
-(defun register-callback-function (function)
- (check-type function (or null symbol function))
- (lisp-callback-closure-new (register-user-data function)))
+;;;; Callback mechanism
(defun callback-trampoline (callback-id params return-value)
(let* ((return-type (unless (null-pointer-p return-value)
- (type-from-number (gvalue-type return-value))))
+ (gvalue-type return-value)))
(args nil)
(callback-function (find-user-data callback-id)))
(after-gc-hook)
+;;;; Timeouts and idle functions
-;;;; Signals
+(defvar *source-callback-marshal*
+ (system:foreign-symbol-address "source_callback_marshal"))
+(defvar *destroy-notify*
+ (system:foreign-symbol-address "destroy_notify"))
-(defun signal-name-to-string (name)
- (substitute #\_ #\- (string-downcase (string name))))
+(defbinding (timeout-add "g_timeout_add_full")
+ (function interval &optional (priority 0)) unsigned-int
+ (priority int)
+ (interval unsigned-int)
+ (*source-callback-marshal* pointer)
+ ((register-callback-function function) unsigned-long)
+ (*destroy-notify* pointer))
+
+(defbinding (idle-add "g_idle_add_full")
+ (function &optional (priority 0)) unsigned-int
+ (priority int)
+ (*source-callback-marshal* pointer)
+ ((register-callback-function function) unsigned-long)
+ (*destroy-notify* pointer))
+
+
+
+;;;; Signals
(defbinding signal-lookup (name itype) unsigned-int
((signal-name-to-string name) string)
(handler unsigned-int))
-(defmethod signal-connect ((gobject gobject) signal function &rest args &key after object)
- (declare (ignore signal args after))
- (cond
- ((or (eq object t) (eq object gobject)) function)
- ((not object)
- #'(lambda (&rest args) (apply function (cdr args))))
- (t
- #'(lambda (&rest args) (apply function object (rest args))))))
-
-
-(defmethod signal-connect :around ((gobject gobject) signal function
- &key after object)
- (declare (ignore object))
- (let ((callback-id (register-callback-function (call-next-method))))
+(defmethod signal-connect ((gobject gobject) signal function &key after object)
+"Connects a callback function to a signal for a particular object. If :OBJECT
+ is T, the object connected to is passed as the first argument to the callback
+ function, or if :OBJECT is any other non NIL value, it is passed as the first
+ argument instead. If :AFTER is non NIL, the handler will be called after the
+ default handler of the signal."
+ (let ((callback-id
+ (make-callback-closure
+ (cond
+ ((or (eq object t) (eq object gobject)) function)
+ ((not object)
+ #'(lambda (&rest args) (apply function (cdr args))))
+ (t
+ #'(lambda (&rest args) (apply function object (rest args))))))))
(signal-connect-closure gobject signal callback-id :after after)))