Gtk3 keys bindings in css files
Asked Answered
F

5

13

Where can I find an exhaustive list of available keybindings that a user can define in a CSS file for GTK+ 3?

I have already checked those resources:

For example, how can a user make <Control>Space move the cursor to the end of the text in a GtkTextView?

Fulminant answered 27/5, 2015 at 16:17 Comment(2)
Control+Space for moving the cursor is probably not very friendly to users with input methods. For example, on Ubuntu the default key for changing to/from IBus input methods (for Japanese, Chinese etc) is Ctrl+Space.Unweighed
I try to contribute to github.com/ruby-gnome2 and I am updating this github.com/ruby-gnome2/ruby-gnome2/blob/master/gtk3/sample/misc/… that use <ctrl>Space . So I try to stay close to the old script. Furthermore I am not asking if this key binding is user friendly.Fulminant
F
10

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.

Fulminant answered 28/5, 2015 at 17:5 Comment(0)
G
3

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.

Gardiner answered 29/5, 2015 at 10:31 Comment(0)
J
2

I've also been looking for proper documentation of possible key bindings for quite a while now and just stumbled over these docs of the single-line text widget GtkEntry. In this particular case, one can scroll all the way down to the end of the menu to find all other "keybinding signals" the widget offers, like insert_at_cursor, paste_clipboard etc. including the parameters these signals accept (such as the DeleteType in case of delete_from_cursor). It now shouldn't be too hard to find the signals for other GTK widgets.

Update: If the Vala docs provide a detailed description of the keybinding signals, one might assume that the regular Gtk3 docs do, too. Indeed. It's always easier to find what you're looking for if you know what you're looking for. :)

Jason answered 8/12, 2017 at 1:45 Comment(0)
D
1

I think ultimately ntd has the most correct idea, but here is a more browsable solution, rather than grepping through the GIR file.

You should (assuming comprehensive documentation) be able to find this info by going to the documentation page for the widget of interest, then search that page for the term keybinding signal.

The available signals are documented along with the others on each widget's page and then qualified as whether or not they are for key bindings in the description.

Usually you can also identify them by the fact that their value in the 2nd column of the summary table of signals, i.e. signal type flags, is Action, as also pointed out by ntd.

For example, GtkComboBox:move-active:

[handler function signature]

The ::move-active signal is a keybinding signal which gets emitted to move the active selection.

[description of arguments]

As ntd indicated, this can probably be automated to a large extent. Like the GIR, the documentation is generated from the C source files, so if you lack a GIR file or just prefer this way, you can presumably do some clever use of grep, sed, et al. through those to pull out the info.

Dickey answered 4/7, 2017 at 14:11 Comment(0)
D
0

@ntd suggested looking at /usr/share/gir-1.0/Gtk-3.0.gir for <glib:signal action="1"> entities. I don't have a Gtk-3.0.gir but I do have a Gtk-2.0.gir and these are the unique results I found using that approach:

cat /usr/share/gir-1.0/Gtk-2.0.gir \
| sed -n '/.*<glib:signal name="\([^"]*\)".* action="1".*/s//\1/p' \
| sort -u
abort-column-resize
accept-position
activate
activate-current
activate-cursor-item
activate-default
activate-focus
backspace
cancel
cancel-position
change-current-page
change-focus-row-expansion
change-value
clicked
close
composited-changed
copy-clipboard
cut-clipboard
cycle-focus
delete-from-cursor
end-selection
expand-collapse-cursor-row
extend-selection
focus-home-or-end
focus-tab
grab-focus
insert-at-cursor
kill-char
kill-line
kill-word
move
move-active
move-current
move-cursor
move-focus
move-focus-out
move-handle
move-page
move-scroll
move-slider
move-to-column
move-to-row
move-viewport
move-word
page-horizontally
paste-clipboard
popdown
popup
popup-menu
reorder-tab
row-activated
scroll-child
scroll-horizontal
scroll-vertical
select-all
select-cursor-item
select-cursor-parent
select-cursor-row
select-page
set-anchor
set-editable
set-scroll-adjustments
show-help
start-interactive-search
start-selection
toggle-add-mode
toggle-cursor-item
toggle-cursor-row
toggle-cursor-visible
toggle-focus-row
toggle-overwrite
undo-selection
unselect-all
Deliberation answered 24/8, 2020 at 22:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.