Re: Using gtk_widget_set_extension_events() for a button?



On Thu, 2003-10-16 at 22:56, David Bourguignon wrote:
> Hi all,
> 
> I'm trying to get extension events information from a button widget. This is 
> useful, for example, to know which input device caused the button to emit a 
> "button_press_event" signal. To test this feature, I modified the 
> scribble-xinput.c example given with the distribution by adding another signal 
> handler before the "clicked" signal handler for the quit button:
> 
> g_signal_connect (G_OBJECT (button), "button_press_event",
>                    G_CALLBACK (quit_button_press_event), NULL);
> 
> and setting the events and extension events masks for the button:
> 
> gtk_widget_set_events (button, GDK_BUTTON_PRESS_MASK);
> gtk_widget_set_extension_events (button, GDK_EXTENSION_EVENTS_CURSOR);
> 
> I finally defined the following basic callback:
> 
> static gint
> quit_button_press_event (GtkWidget *widget, GdkEventButton *event)
> {
>    print_button_press (event->device);
>    return FALSE;
> }
> 
> After setting up devices, I used the drawing area with my tablet stylus, getting 
> expected messages such as "Button press on device 'stylus'" from the drawing 
> area "button_press_event" signal handler (see the original code). However, after 
> clicking on the quit button to exit the program, I got only "Button press on 
> device 'Core Pointer'" from the quit_button_press_event callback.
> 
> According to this example, it seems that the quit button cannot be setup to emit 
> extension events... Is it true or am I missing something?

Not all widgets honor gtk_widget_set_extension_events(). If you look at
the code for gtk_widget_realize(), you'll see how it is handled there.
This default realize() handler is inherited by GtkDrawingArea, but most
widgets aren't going to do anything with it.

(Generally, catching ::button-press-event on a widget like GtkButton
is discouraged, since by doing that you are assuming you know exactly
how GtkButton is going to handle button presses and safely override it.)

Regards,
						Owen





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