GNOME Bugzilla – Bug 679795
Unclear "event" argument on Gtk.Widget "motion-nofity-event" signal
Last modified: 2017-08-14 23:21:58 UTC
Hello, I'm reading this page[1] and I noticed the argument "event" in the definition says: GdkEvent *event but in the description it says: event: the GdkEventMotion which triggered this signal. [type Gdk.EventMotion] So, I think it is unclear because I'm not sure if I should pass a Gdk.EventMotion or a Gdk.Event Thanks, [1] http://developer.gnome.org/gtk3/3.5/GtkWidget.html#GtkWidget-motion-notify-event
This is done in various places, not just the one you quoted. GdkEvent is a union that contains all the different possible types of GdkEvent[Derived], as well as a way to determine which is really present: https://developer.gnome.org/gdk3/stable/gdk3-Event-Structures.html#GdkEvent You can trust the parameter type given against the parameter name in the documentation; it is explicitly specified, by authors who know what they're doing. :) The more basal type in the example function declaration has a long and boring reason for existing, involve GType... Anyway, should you have a rationale for manually passing something to a handler, it should be a GtkEventMotion. Moreover, your handler itself can declare itself as taking a GtkEventMotion, if you like; see gtkwidget.c:gtk_widget_real_motion_event(), which does just that, and even drops the user_data argument. Read up on GCallback to understand how this all works. :)
...and, of course, the fact that GdkEvent is a union containing all the other types, means you can safely cast between them - if your passing them to a function that can't (or you don't want to make it) receive a 'derived' event type directly.