
On Sat, 2004-01-10 at 11:00, bulia byak wrote:
- Is alt-x plus tab/shift-tab enough for navigating the toolbar, or
do we want each widget to have its own shortcut? Or will this be too much, with potentially tens of widgets in all tools? Of course such shortcuts would use consistent modifiers and would correspond to the widget labels, e.g. for the selector toolbar: ctrl-alt-x, ctrl-alt-y, ctrl-alt-w, ctrl-alt-h.
Save those combinations for other things, I think. Tab should be enough.
- Now alt-x is implemented very stupidly, through grab_focus of a
specific widget. I tried to use GTK "accelerators" but was unable to make them work. Does anyone know if Inkscape uses GTK accelerators? If not, how are the global verbs implemented? If I manage to add an accelerator group to the top-level document window, will it conflict with verbs? Can one point me to a not-too-complex GTK app that uses accelerators so I could figure it out? (The documentation is very scarce.)
Inkscape does not currently use GTK accelerators.
Here's a readers' digest summary of how Inkscape accelerators work:
A global mapping between key combinations and integer verb IDs (sp_verb_t) is maintained in shortcuts.cpp; these are registered using sp_shortcut_set().
Given an sp_verb_t and an SPView, you can get an SPAction which represents that action in that view. These mappings are currently hard-coded in verbs.cpp.
SPActions derive from NRActiveObject, which putatively provides a "lightweight" method of doing callbacks, versus GObject signals. I don't completely understand how it works.
[ SPActions also contain the label, image, etc, used for buttons and menuitems. ]
sp_shortcut_invoke() looks up the SPAction for a keypress and SPView and invokes it automatically. SPEventContexts call it for keypresses that they do not handle themselves.
Here's a readers' digest summary of how Gtk accelerators work:
A GtkAccelGroup object maintains a (non-global) mapping between key combinations and specific GClosures. These are registered via gtk_accel_group_connect()
A GClosure is an object containing a callback function pointer and some data (which is passed to the function whenever the closure is 'invoked'). From C/C++, you would create these using g_cclosure_new() [ note the double c ].
A mapping from a key combination to a GClosure may be added using gtk_accel_group_connect().
A GtkWindow may have one or more GtkAccelGroups attached to it by gtk_window_add_accel_group().
Calling gtk_accel_groups_activate(window, key, modifiers) invokes the first matching GClosure in any of the accel groups attached to a window. It returns TRUE if a match was found.
IIRC, GtkWindows call it in their default key press handler.
-mental