In addition to the signal mechanism described above, there is a set of events that reflect the Window event mechanism. Callbacks may also be attached to these events. These events are: (see event_signals)
In order to connect a callback function to one of these events you use the #event#connect method, using one of the above event names as the event_signal_name like this:
widget#event#connect#event_signal_name ~callback:(event -> bool) -> GtkSignal.id
The callback function for events has a slightly different form than that for signals as you can see.
The argument of the callback function event may have various type which will depend upon which of the above events has occurred. The components of the event structure will depend upon the type of the event. The possible types of event are: (see event_signals)
Gtk.Tags.event_type Gdk.event
[`DELETE] Gdk.event
[`DESTROY] Gdk.event
[`MAP] Gdk.event
[`UNMAP] Gdk.event
GdkEvent.Button.t
GdkEvent.Crossing.t
GdkEvent.Configure.t
GdkEvent.Expose.t
GdkEvent.Focus.t
GdkEvent.Key.t
GdkEvent.Motion.t
GdkEvent.Proximity.t
GdkEvent.Selection.t
...
So, to connect a callback function to one of these events we would use something like:
button#event#connect#button_press ~callback:button_pressed;
This assumes that button is a Button widget. Now, when the mouse is over the button and a mouse button is pressed, the function button_pressed will be called. This function may be declared as:
button_pressed (ev:GdkEvent.Button.t) =
...
true (* or false *)
Note that the argument has a type GdkEvent.Button.t as we know what type of event will occur for this function to be called.
The value 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: