index

gtk-keys

How GTK processes Key events:

X event arrives, marked by a X/GDK window.

gtk_main_do_event() is given it, and does this:

In the following we assume there is not any (global) grab_widget.

So the processing follows in

GDK_KEY_PRESS -> gtk_propagate_event (grab_widget, event);

 * Sends an event to a widget, propagating the event to parent widgets
 * if the event remains unhandled. Events received by GTK+ from GDK
 * normally begin in gtk_main_do_event(). Depending on the type of
 * event, existence of modal dialogs, grabs, etc., the event may be
 * propagated; if so, this function is used. gtk_propagate_event()
 * calls gtk_widget_event() on each widget it decides to send the
 * event to.  So gtk_widget_event() is the lowest-level function; it
 * simply emits the "event" and possibly an event-specific signal on a
 * widget.  gtk_propagate_event() is a bit higher-level, and
 * gtk_main_do_event() is the highest level.

  /* If there is a grab within the window, give the grab widget
   * a first crack at the key event

   gtk_widget_event (window, event);

So, i correctly talked about global grab_widget in previous paragraph. Here we have a window-local grab widget.

Let's assume there is no grab widget in the top window, so what follows:

First we see the general:

what any widget does:

its gtk_widget_event is:

  g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
  g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
                                        KEY_PRESS_EVENT;
  g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);

??? G_STRUCT_OFFSET (GtkWidgetClass, key_press_event), which is: ((glong) ((guint8*) &((struct_type*) 0)->member))

widgets do:

klass->key_press_event = static gboolean gtk_widget_real_key_press_event (GtkWidget *widget, GdkEventKey *event) { return gtk_bindings_activate_event (GTK_OBJECT (widget), event); }

Once searching for the "widget_class->key_press_event" we see which widgets override the default: gtk_text_key_press; gtk_entry_key_press; gtk_tree_view_key_press;

Now, we return to the case of the Top Window:

what the (top) GtkWindow does?

widget_class->key_press_event = gtk_window_key_press_event;

so let's look at

gtk_window_key_press_event

gtk_window_activate_key .... either gtk_window_mnemonic_activate or gtk_accel_groups_activate

gtk_window_mnemonic_activate

gtk_accel_groups_activate

there is a sort of abuse of signal "detail".

what is mnemonics

focus widget

gtk-hash-key

keycode -> slist of GtkKeyHashEntry-s each should correspond to a keyval/modifierss. And each one: has an slist of (keycode, group, level)

Bugs: keyval -> keycode is not complete. Sometime we find the lowest keycode. Ambiguity: group is not interpreted (in some occastion ... it depends on the order of insertion!?)

binding sets

key hash is carried by the GdkKeymap of the display!, in a user data "gtk-binding-key-hash"

Global: binding_key_hashes an slist. the one for display gkkKeymap is just one of them.

binding_entry_hash_table global for all displays. key (what is it?) ---> slist of GtkBindingEntry

So, we keep a central hash: keyval & modifiers (xor) -> GtkBindingEntry and propagate all from this one into all key_hashes (one per display?).

Now, binding_set is:

top window

gtk_window_activate_key -> gtk_window_get_key_hash window -> screen -> key-hash!!!! the window may have been moved between displays!!!

how are mnemonics entered in the global hash window+keyval -> widget ?

in gtklabel.c ?

i need indeed to keep the key sequence. B/c on failure, i will retry on the parent widgets!

Note: there are (many) hash tables, where key and value are always the same pointer. Could i shrink such h-tables (by half)?

todo:

1/ use alt, hyper etc. 2/ multi-keyevent sequences in binding-sets, and in accelerator groups.