Re: [gtk-list] Re: Strange behaviour of key-event handler.



Owen replied to my plea:
> > Sorry about this. I'm having a problem receiving key-press and key-release
> > events from a drawing_area...
> 
> OK, there are various things going on here, some which are
> documented and some are pretty obscure.
> 
> > static void
> > keyevent_callback(GtkWidget *widget, GdkEventKey *event, gpointer data)
> 
> All signals handlers for events have a boolean return value that
> indicates whether the event was handled or not. You are returning
> random garbage, so the handling of focus navigation keys may
> happen or it may not.
> 

True. Actually I had already discovered that one, though as it happens
whether or not the key events propagated wasn't the problem here. But I've
fixed it anyway... thanks for the reminder.


> > 	gtk_signal_connect (GTK_OBJECT (drawing_area), "key_press_event",
> > 				(GtkSignalFunc) keyevent_callback, NULL);
> > 	gtk_signal_connect (GTK_OBJECT (drawing_area), "key_release_event",
> > 				(GtkSignalFunc) keyevent_callback, NULL);
> 
> It also turns out that you need to use gtk_signal_connect_after()
> so that the return value from your signal handler actually takes
> effect. There is a default handler for key presses in GtkWidget
> that will override your return value if it runs after your key
> press handler, so you need to make sure that your key press
> handler is run after this.
>

'gtk_signal_connect_after()' fixed the problem. Many thanks Owen.

Now *this* is what I call an obscure issue! Especially when getting it
wrong still partially worked (navigation keys got through - other ones got
blocked after the first navigation key was hit). Maybe this ought to
be in the tutorial or the FAQ, or maybe just some keyboard handling code
should appear in 'testgtk.c' so that people like me would tend to cut-and-
paste it and therefore get working solutions without having to jam up
this list with queries?
 

> When I embed your code into a test program and make the various changes
> suggested above, things seem to act as I would expect.
> 
> Regards,
>                                         Owen

Again, many thanks.

--

Steve                                       | Steve's law of House Rewiring:
S.Hosgood@swansea.ac.uk                     | "No matter how many power sockets
Phone: +44 1792 297292 + ask for Steve      |  you fit in a room, you will run
Fax:   +44 1792 295811                      |  out within the first week of use
--------------------------------------------+  even if you took Steve's law of
http://iiit.swan.ac.uk/~iisteve/steve.html  |  House Rewiring into account"




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