Re: key bindings - gtk2



Dennis,

(with apologies to Owen Taylor for stealing ideas and words from him; any errors 
are my own)

There are two widgets involved for every key press. The first is the top 
level widget in which the key press occurs. The second is the focus widget 
within the toplevel widget. This is the widget which appears to receive the
user's keystrokes. All keystrokes are sent to the focus widget until the user 
explicitly moves the focus elsewhere by clicking in another widget or using 
the Tab key to move the focus.

All keystrokes received by GTK+ are first sent to the toplevel widget. So, 
the way to make sure you get a keystroke before anybody else is to attach 
to the "key-press-event" signal on the top level widget. The default handler 
for key presses in a top level window does a number of things. First, 
it checks whether the keypress corresponds to a mnemonic or accelerator 
defined for the top level window, and if so, activates it. Second, it checks 
whether there is a focus widget for the toplevel and if so, forwards the
keystroke to that widget. If that widget does not handle the keystroke, the 
keystroke is forwarded to tha parent of the widget until the keystroke is 
handled or the toplevel is reached. If the keystroke has still not been handled
the toplevel checks for key bindings.

Within a widget the handling of the keystroke will call key-press-event
handlers defined for that widget. These should, among other things, check for 
key bindings defined for the widget.

I have not said anything about accessibility (atk) as I do not see its relevance 
to the topic. If you are further questions, I will try to help.

Padraig

> 
> I need some documentation about key bindings in gtk2. By looking at the
> api-reference I can not tell what is the correct way to use it.
> 
> Or maybe someone could just write a little about keyboard navigation,
> accel groups, binding sets, mnemonics, accessibility (atk). What happens
> when you press a button, and in what order is the event handled?
> 
> 
> One thing I want to do is to have a gtk_scrolled_window that is operated
> with the arrows instead of ctrl-arrow that is the default. And I want
> ctrl-arrow to bind to something else. The user is going to scroll with the
> arrows most of the time, so in this case it is better to use arrow and not
> ctrl-arrow.
> 
> In a gtk1 version of the program I simply made a solution that worked, but
> now when I rewrite my code I want a solution that is sound and that works
> the way it's intended to work.
> 
> -- 
> /Dennis
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list




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