Re: reading event in signal handler callback



Marc Santhoff wrote:
Hi,

I need to know how i can get access to the event, that caused the signal
handler to be called.

The handler is (of course) defined as GtkSignalFunc. In the handler I
want to discriminate different event types, not only emitters.

How can this be done?
See:
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html

A GdkEvent is a union of structures, all of which have the first member
"GdkEventType" (which is also one of the union members).

So, upon recieval of, for example, a GdkEventKey; you can cast it
to a GdkEventType and check for GDK_KEY_PRESS/GDK_KEY_RELEASE.
you can also simply check the value of event->type (it is the first
member in any of those structures).

Note that this only applies to signals that dispatch events (i.e. signals
definied by the GtkWidgetClass). It is logical to say that a "pressed"
signal of the GtkButtonClass was a result of mouse clicks, but IMO, it's
incorrect, the GtkButtonClass is the sole responsable actor who decides
when its button is "pressed" (it could also be a result of the programmer
calling the function gtk_button_pressed() for example).

Cheers,
                                              -Tristan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]