GNOME Bugzilla – Bug 766166
key bindings in gtk.css are ignored
Last modified: 2017-04-20 23:05:18 UTC
On a Debian/unstable machine with Gtk+ 3.20.3, I have the following in the .config/gtk-3.0/gtk.css file: @binding-set text-entry { bind "<Control>a" { "move-cursor" (paragraph-ends, -1, 0) }; bind "<Control>e" { "move-cursor" (paragraph-ends, 1, 0) }; bind "<Control>k" { "delete-from-cursor" (paragraph-ends, 1) }; bind "<Control>u" { "move-cursor" (paragraph-ends, -1, 0) "delete-from-cursor" (paragraph-ends, 1) }; bind "<Control>w" { "delete-from-cursor" (word-ends, -1) }; } GtkEntry { -gtk-key-bindings: text-entry; } GtkTextView { -gtk-key-bindings: text-entry; } However these bindings are ignored. Note that the .config/gtk-3.0/gtk.css file is read and parsed because if I introduce an error, I get a Gtk-WARNING in the terminal about it. Tested with both Firefox and gtk3-widget-factory. For instance, Ctrl-a still does a Select All instead of moving the cursor to the beginning of the line as configured. Ctrl-e and Ctrl-k have no effect.
Try using: entry { -gtk-key-bindings: text-entry; } textview { -gtk-key-bindings: text-entry; } instead. The selectors for widgets have been changed in GTK 3.20: https://developer.gnome.org/gtk3/stable/chap-css-overview.html https://developer.gnome.org/gtk3/stable/chap-css-properties.html
(In reply to Emmanuele Bassi (:ebassi) from comment #1) > Try using: > > entry { -gtk-key-bindings: text-entry; } > textview { -gtk-key-bindings: text-entry; } > > instead. Thanks. This works. > The selectors for widgets have been changed in GTK 3.20: > > https://developer.gnome.org/gtk3/stable/chap-css-overview.html > https://developer.gnome.org/gtk3/stable/chap-css-properties.html Then the documentation is wrong: https://developer.gnome.org/gtk3/3.20/gtk3-Bindings.html still gives examples with GtkEntry: @binding-set MoveCursor3 { bind "<Control>Right" { "move-cursor" (visual-positions, 3, 0) }; bind "<Control>Left" { "move-cursor" (visual-positions, -3, 0) }; } GtkEntry { -gtk-key-bindings: MoveCursor3; }
(In reply to Vincent Lefevre from comment #2) > (In reply to Emmanuele Bassi (:ebassi) from comment #1) > > Try using: > > > > entry { -gtk-key-bindings: text-entry; } > > textview { -gtk-key-bindings: text-entry; } > > > > instead. > > Thanks. This works. > > > The selectors for widgets have been changed in GTK 3.20: > > > > https://developer.gnome.org/gtk3/stable/chap-css-overview.html > > https://developer.gnome.org/gtk3/stable/chap-css-properties.html > > Then the documentation is wrong: > > https://developer.gnome.org/gtk3/3.20/gtk3-Bindings.html > > still gives examples with GtkEntry: Indeed, good catch. I've fixed this in master and backported to the gtk-3-20 branch; the fix will be in the next release. Thanks!
In treeview or flowbox the Control key is ignored. gtk version 3.22.10 (and master git) css file: @binding-set move { bind "<Control>f" { "move-cursor" (visual-position, 1) }; bind "<Alt>f" { "move-cursor" (visual-position, 1) }; bind "f" { "move-cursor" (visual-position, 1) }; } treeview { -gtk-key-bindings: move; } flowbox { -gtk-key-bindings: move; } The "<Control>key" is ignored in treeview or flowbox. In GtkEntry is Ok