Package: gobject

Function g-signal-connect

Lambda List

g-signal-connect (instance signal handler &key after)

Arguments

instance -- a g-object instance to connect to
signal -- a string of the form "signal-name::detail"
handler -- a Lisp callback function to connect
after -- if true the handler is called after the default handler

Return Value

A unsigned long integer with the handler ID.

Details

Connects a Lisp callback function to a signal for a particular object. The handler will be called before the default handler of the signal. If the after keyword argument is true, the handler will be called after the default handler of the signal.

Lisp implmentation

The C library knows in addition the g_signal_connect_after() function, which is implemented as the g-signal-connect-after function and is equivalent to this function with a true value for the after keyword argument.

Example

Connect a Lisp lambda function to the signal "destroy" of a window:
(g-signal-connect window "destroy"
                  (lambda (widget)
                    (declare (ignore widget))
                    (leave-gtk-main)))    
Connect a Lisp lambda function to the signal "toggled" of a toggle button:
(g-signal-connect button "toggled"
   (lambda (widget)
     (if (gtk-toggle-button-active widget)
         (progn
           ;; If control reaches here, the toggle button is down
         )
        (progn
           ;; If control reaches here, the toggle button is up
         ))))    
If it is necessary to have a separate function which needs user data, the following implementation is possible:
(defun separate-event-handler (widget arg1 arg2 arg3)
  [ here is the code of the event handler ] )

(g-signal-connect window destroy" (lambda (widget) (separate-event-handler widget arg1 arg2 arg3)))
If no extra data is needed, but the callback function should be separated out than it is also possible to implement something like:
(g-signal-connect window "destroy" #'separate-event-handler)    
 

See also

*2021-12-14