After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 766166 - key bindings in gtk.css are ignored
key bindings in gtk.css are ignored
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
3.20.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-05-09 10:37 UTC by Vincent Lefevre
Modified: 2017-04-20 23:05 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Vincent Lefevre 2016-05-09 10:37:33 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.
Comment 1 Emmanuele Bassi (:ebassi) 2016-05-09 10:50:46 UTC
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
Comment 2 Vincent Lefevre 2016-05-09 11:36:13 UTC
(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;
}
Comment 3 Emmanuele Bassi (:ebassi) 2016-05-09 11:47:12 UTC
(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!
Comment 4 athrunbug 2017-04-20 23:05:18 UTC
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