Re: [gtk-list] Re: Problem: no key press/release events.



Tomi Ollila wrote:
> 
> Monday Aug 16 11:28:48 -0400 1999 Havoc Pennington <hp@redhat.com> wrote:
> >
> > On Mon, 16 Aug 1999, Tomi Ollila wrote:
> > >
> > > OK. I read the sample manual at: http://pobox.com/~hp/gnome-app-devel.html
> > > and noticed the problem is w/ `keyboard' focus. If I understood right,
> > > W/ G[DT]K only toplevel window receives keyboard events and it redirects
> > > the data to the widget in question.
> > >
> > > I reorganized by code a bit to test this, and indeed -- when I add the
> > > keypress/release masks to the toplevel window and connect the signals
> > > accorginfly, I get the events...
> > >
> > > Now one thing I yet not know: How to add my eventbox widget to the list
> > > of widgets where the toplevel window enters focus?
> > >
> >
> > You just have to gtk_widget_add_events() to add KEY_PRESS_MASK to your
> > event box, then set the GTK_CAN_FOCUS flag:
> >
> >  GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS)
> 
> > HTH,
> > Havoc
> 
> Whoo-oo, at last I got It working. For a long time whatever I did I could
> not get keypress/release events to my fixed widget (removed eventbox
> since It was unnecessary...) I changed the order of lines in hope that
> it would solve the problem...
> 
> At last I tried to press <TAB> and then I started getting keypress events.
> 
> Now, next saga was to find how to set focus to the widget by default
> (Already tried GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_FOCUS) without help).
> Browsing through gtkwindow.c I found the solution:
> 
> gtk_window_set_focus(GTK_WINDOW(window), fixed).
> 
> Next thing was to make button press over the fixed widget to `focus' the
> widget unless already focused. What is the "right" way to chech such
> a condition. I used the following:
>         if (GTK_WINDOW(window)->focus_widget != fixed)...
> Does not look as future-compatible as it could... but is it ?
> 
> I have one unresolved problem as well..
> 
> When pressing key and hold it pressed, many systems starts to generate
> a stream of keypress/key release events. The key release event seems to
> have the same timestamp as the next key press event...
> 
> I wanted the most simple way to regognize that the key is still pressed
> in these conditions. First I tried to call `gdk_events_peek()' to peek
> the next event... but it would never have anything available. I checked
> the code and noticed that It only checks the gdk event queue, but not
> from X connection. (Next I tried to call gdk_queue_events(), but that is
> static function)... nothing in the gdk interface I explored gave me
> the functionality to solve this...
> 
> The approach above is hacky, I know...
> 
> Does anyone have a good (or even bad) solution how to simply do the feature
> I wanted above. I could setup a short timeout or use idle function (and
> eventually do if there is no other solutions), but that would complicate
> the code further...
> 
> (I know, this won't work on all hardware, but is a advantage on those
>  systems that it works).
> 
> Tomi

I'm not sure if this is what you're looking for but I'm using 

gdk_key_repeat_disable() 

in my key_press event handler and

gdk_key_repeat_restore()

in the key_release handler so that other widgets and apps get the normal
behavior from the keyboard. I don't know if that's the best way to do it
but it seems to work ok for me. If that's not a proper use of these
functions someone please correct me.

	Stephen



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