Gtk3 keys bindings in css files

It seems that there is no exhaustive documentation. Here is what I have found so far:

The list of the possible actions (from /usr/share/themes/Emacs/gtk-3.0/gtk-keys.css) :

  • move-cursor
  • delete-from-cursor
  • cut-clipboard
  • past-clipboard
  • start-interactive-search
  • move-current

Get the gtk+ code :

git clone git://git.gnome.org/gtk+

For example, the "move-cursor action":

bind  "<ctrl>b" { "move-cursor" (logical-positions, -1, 0) };

If you do a :

grep -i logical gtk+/gtk/gtkenums.h

You will find a match and see that there are others possibilities :

/**
 * GtkMovementStep:
 * @GTK_MOVEMENT_LOGICAL_POSITIONS: Move forward or back by graphemes
 * @GTK_MOVEMENT_VISUAL_POSITIONS:  Move left or right by graphemes
 * @GTK_MOVEMENT_WORDS:             Move forward or back by words
 * @GTK_MOVEMENT_DISPLAY_LINES:     Move up or down lines (wrapped lines)
 * @GTK_MOVEMENT_DISPLAY_LINE_ENDS: Move to either end of a line
 * @GTK_MOVEMENT_PARAGRAPHS:        Move up or down paragraphs (newline-ended lines)
 * @GTK_MOVEMENT_PARAGRAPH_ENDS:    Move to either end of a paragraph
 * @GTK_MOVEMENT_PAGES:             Move by pages
 * @GTK_MOVEMENT_BUFFER_ENDS:       Move to ends of the buffer
 * @GTK_MOVEMENT_HORIZONTAL_PAGES:  Move horizontally by pages
 */

For example the binding I wanted to do (move the cursor to the end of the text in a Gtk::TextView)

bind "<Control>KP_Space" { "move-cursor" (buffer-ends, 1, 0) }

The "template" is :

bind "key_combination" { "action" (action_param1, action_param2, ...)}

For the move-cursor action, the parameters are (step, count, extend_selection), where step is one of the above enum values. To note that for line-ends, paragraph-ends and buffer-ends a negative count means "beginning" and a positive value means "end". And extend_selection is simply 0 or 1 (for C-style "False" and "True").

In the same way, the options for the action "delete-from-cursor" are :

/**
 * GtkDeleteType:
 * @GTK_DELETE_CHARS: Delete characters.
 * @GTK_DELETE_WORD_ENDS: Delete only the portion of the word to the
 *   left/right of cursor if we’re in the middle of a word.
 * @GTK_DELETE_WORDS: Delete words.
 * @GTK_DELETE_DISPLAY_LINES: Delete display-lines. Display-lines
 *   refers to the visible lines, with respect to to the current line
 *   breaks. As opposed to paragraphs, which are defined by line
 *   breaks in the input.
 * @GTK_DELETE_DISPLAY_LINE_ENDS: Delete only the portion of the
 *   display-line to the left/right of cursor.
 * @GTK_DELETE_PARAGRAPH_ENDS: Delete to the end of the
 *   paragraph. Like C-k in Emacs (or its reverse).
 * @GTK_DELETE_PARAGRAPHS: Delete entire line. Like C-k in pico.
 * @GTK_DELETE_WHITESPACE: Delete only whitespace. Like M-\ in Emacs.
 *
 * See also: #GtkEntry::delete-from-cursor.
 */

Now if you want all to see all the possible actions that are hard coded, then here is a way :

find ./gtk+/ -type f | xargs grep -A 2 gtk_binding_entry_add_signal

You will see lot of things like this :

./gtk+/gtk/gtklabel.c:  gtk_binding_entry_add_signal (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK,
./gtk+/gtk/gtklabel.c-              "move-cursor", 3,
./gtk+/gtk/gtklabel.c-              G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS,
--
./gtk+/gtk/gtklabel.c:  gtk_binding_entry_add_signal (binding_set, GDK_KEY_c, GDK_CONTROL_MASK,
./gtk+/gtk/gtklabel.c-              "copy-clipboard", 0);
./gtk+/gtk/gtklabel.c-
./gtk+/gtk/gtklabel.c:  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
./gtk+/gtk/gtklabel.c-              "activate-current-link", 0);
./gtk+/gtk/gtklabel.c:  gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
./gtk+/gtk/gtklabel.c-              "activate-current-link", 0);
./gtk+/gtk/gtklabel.c:  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
./gtk+/gtk/gtklabel.c-              "activate-current-link", 0);
./gtk+/gtk/gtklabel.c-
--
./gtk+/gtk/gtkdialog.c:  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);

Then it should be easy to find what you were looking for.


My guess is you should find any signal with the G_SIGNAL_ACTION flag enabled. You could get this list programmatically from the Gtk gir file (/usr/share/gir-1.0/Gtk-3.0.gir on my system) by looking for every <glib:signal> entity with the action attribute set to 1.

I am not so fond on XPath to come out with a one-line solution though.