css 个文件中的 Gtk3 键绑定

Gtk3 keys bindings in css files

在哪里可以找到用户可以在 GTK+ 3 的 CSS 文件中定义的可用键绑定的详尽列表?

我已经查看了那些资源:

例如,用户如何使 <Control>Space 将光标移动到 GtkTextView 中文本的末尾?

好像没有详尽的文档。以下是我目前的发现:

可能的操作列表(来自/usr/share/themes/Emacs/gtk-3.0/gtk-keys.css):

  • 移动光标
  • 从光标中删除
  • 剪切剪贴板
  • 过去剪贴板
  • 开始互动搜索
  • 移动电流

获取 gtk+ 代码:

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

例如 "move-cursor action":

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

如果你做一个:

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

您会找到一个匹配项并发现还有其他可能性:

/**
 * 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
 */

比如我想做的绑定(移动光标到文末Gtk::TextView)

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

"template" 是:

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

对于move-cursor动作,参数为(step, count, extend_selection),其中step是上述枚举值之一。请注意,对于 line-endsparagraph-endsbuffer-ends,负值 count 表示 "beginning",正值表示 "end"。 extend_selection 只是 0 或 1(对于 C 风格 "False" 和 "True")。

同理,动作"delete-from-cursor"的选项是:

/**
 * 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.
 */

现在如果你想让所有人看到所有可能的硬编码操作,那么 这是一个方法:

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

你会看到很多这样的东西:

./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);

那么应该很容易找到你要找的东西。

我的猜测是您应该找到启用了 G_SIGNAL_ACTION 标志的任何信号。您可以通过查找 action 属性设置为 1.

的每个 <glib:signal> 实体,以编程方式从 Gtk gir 文件(/usr/share/gir-1.0/Gtk-3.0.gir 在我的系统上)获取此列表

虽然我不太喜欢 XPath 提出单线解决方案。

我认为最终 ntd 的想法是最正确的,但这里有一个更易于浏览的解决方案,而不是 grepping GIR 文件。

您应该(假设有全面的文档)通过转到感兴趣的小部件的文档页面找到此信息,然后在该页面中搜索术语 keybinding signal

可用信号与其他信号一起记录在每个小部件的页面上,然后在说明中确定它们是否用于键绑定。

通常您还可以通过以下事实来识别它们:它们在信号摘要 table 的第 2 列中的值,即信号类型标志,是 Actionntd.

也指出

例如,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]

ntd 所示,这可能在很大程度上是自动化的。与 GIR 一样,文档是从 C 源文件生成的,因此如果您缺少 GIR 文件或只是喜欢这种方式,您可以巧妙地使用 grepsed等人通过那些提取信息。

我也一直在寻找可能的键绑定的适当文档已经有一段时间了,只是偶然发现 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 以找到其他 GTK 小部件的信号。

更新:如果 Vala 文档提供了键绑定信号的详细描述,那么人们可能会认为常规的 Gtk3 文档也有。 Indeed。如果您知道您要查找的内容,那么总是更容易找到您要查找的内容。 :)

@ntd 建议查看 /usr/share/gir-1.0/Gtk-3.0.gir <glib:signal action="1"> 个实体。我没有 Gtk-3.0.gir 但我有 Gtk-2.0.gir 这些是我使用该方法发现的独特结果:

cat /usr/share/gir-1.0/Gtk-2.0.gir \
| sed -n '/.*<glib:signal name="\([^"]*\)".* action="1".*/s///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