我正在尝试通过CSS将键绑定添加到gtk3应用程序。这是我到目前为止所拥有的:
// add style provider
GtkCssProvider *css = gtk_css_provider_new();
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_css_provider_load_from_path(css, "bindings.css", NULL);
这是在上一个代码段中加载的'bindings.css':
@binding-set tree-view-bindings {
bind "j" { "move-cursor" (display-lines, 1) };
bind "k" { "move-cursor" (display-lines, -1) };
bind "slash" { "start-interactive-search" () };
}
GtkTreeView {
color: #F00;
gtk-key-bindings: tree-view-bindings;
}
颜色设置有效,因此不能完全损坏。但是,这些键绑定均无效。我想念什么?
如果我错了,请原谅我,但我相信您将分号放在错误的位置:)
@binding-set tree-view-bindings {
bind "j" { "move-cursor" (display-lines, 1); }
bind "k" { "move-cursor" (display-lines, -1); }
bind "slash" { "start-interactive-search" (); }
}
它为我以下工作:
treeview {
-gtk-key-bindings: tree-view-bindings;
}
所以GtkTreeView
变成treeview
,gtk-key-bindings
变成-gtk-key-bindings
备注:
GTK_DEBUG=interactive
启动您的应用程序>