3. Events

In addition to the signal mechanism described above, there is a set of events that reflect the X event mechanism. Callbacks may also be attached to these events. These events are:

In order to connect a callback function to one of these events you use the function g_signal_connect(), as described above, using one of the above event names as the name parameter. The callback function for events has a slightly different form than that for signals:

sub callback_func
	my ($widget, $event, $data) = @_;

	return $ret;

$event is a blessed reference which inherits from Gtk2::Gdk::Event and whose package name type will depend upon which of the above events has occurred. In order for us to tell which event has been issued each of the possible alternatives has a type method that reflects the event being issued. The other components of the event object will depend ipon the type of the event. Possible values for the type are:

'nothing' / 'GDK_NOTHING'
'delete' / 'GDK_DELETE'
'destroy' / 'GDK_DESTROY'
'expose' / 'GDK_EXPOSE'
'motion-notify' / 'GDK_MOTION_NOTIFY'
'button-press' / 'GDK_BUTTON_PRESS'
'2button-press' / 'GDK_2BUTTON_PRESS'
'3button-press' / 'GDK_3BUTTON_PRESS'
'button-release' / 'GDK_BUTTON_RELEASE'
'key-press' / 'GDK_KEY_PRESS'
'key-release' / 'GDK_KEY_RELEASE'
'enter-notify' / 'GDK_ENTER_NOTIFY'
'leave-notify' / 'GDK_LEAVE_NOTIFY'
'focus-change' / 'GDK_FOCUS_CHANGE'
'configure' / 'GDK_CONFIGURE'
'map' / 'GDK_MAP'
'unmap' / 'GDK_UNMAP'
'property-notify' / 'GDK_PROPERTY_NOTIFY'
'selection-clear' / 'GDK_SELECTION_CLEAR'
'selection-request' / 'GDK_SELECTION_REQUEST'
'selection-notify' / 'GDK_SELECTION_NOTIFY'
'proximity-in' / 'GDK_PROXIMITY_IN'
'proximity-out' / 'GDK_PROXIMITY_OUT'
'drag-enter' / 'GDK_DRAG_ENTER'
'drag-leave' / 'GDK_DRAG_LEAVE'
'drag-motion' / 'GDK_DRAG_MOTION'
'drag-status' / 'GDK_DRAG_STATUS'
'drop-start' / 'GDK_DROP_START'
'drop-finished' / 'GDK_DROP_FINISHED'
'client-event' / 'GDK_CLIENT_EVENT'
'visibility-notify' / 'GDK_VISIBILITY_NOTIFY'
'no-expose' / 'GDK_NO_EXPOSE'
'scroll' / 'GDK_SCROLL'
'window-state' / 'GDK_WINDOW_STATE'
'setting' / 'GDK_SETTING'

So, to connect a callback function to one of these events we would use something like:

$button->signal_connect(button_press_event => \&button_press_callback);

This assumes that button is a Gtk2::Button widget. Now, when the mouse is over the button and a mouse button is pressed, the sub button_press_callback() will be called.

The value $ret returned from this function indicates whether the event should be propagated further by the GTK event handling mechanism. Returning TRUE indicates that the event has been handled, and that it should not propagate further. Returning FALSE continues the normal event handling. See the section on Advanced Event and Signal Handling for more details on this propagation process.

For details on the GdkEvent data types, see the appendix entitled GDK Event Types.

The GDK selection and drag-and-drop APIs also emit a number of events which are reflected in GTK by the signals. See Signals on the source widget and Signals on the destination widget for details on the signatures of the callback functions for these signals: