How to disable/block/override keybinding in GTK3 widget?

Hi. I’d like some help to to the Right Thing.

GtkTreeView has a keybinding for CtrlA which, as expected, select all rows.

However, there are certain circumstances where I don’t want this keyboard shortcut to do this.

So, I would like to handle this keyboard shortcut from the application side. But it’s not obvious to me how to disable a keybinding in a non-terrible way.

Some hypothesis:

  1. Subclass GtkTreeView and override the ::select-all default signal handler. But subclassing seems excessive for only this.

  2. Use custom CSS to unbind the keybinding.

  3. Block the keybinding signal emission and handle the keyboard shortcut on app code.

     g_signal_connect (view->details->tree_view, "select-all",
                       G_CALLBACK (g_signal_stop_emission_by_name), "select-all"); 

    This works but relies on GtkTreeView::select-all being G_SIGNAL_RUN_LAST signal, which I believe to be an implementation detail (is it?).

Thanks in advance for any advice!

Two more hypothesis:

  1. gtk_binding_entry_add_signal_from_string (binding_set , "unbind <Ctrl>A"); but I’m not sure if this can be done per-widget instead of for the whole widget class.
  2. gtk_binding_entry_skip () which I suppose is the same as the previous one.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.