orontee / argos

Light weight front-end for Mopidy music server
GNU General Public License v3.0
24 stars 4 forks source link

Make dialogs shortcuts be coherent #155

Closed orontee closed 11 months ago

orontee commented 11 months ago

Context

See #154

Current shortcuts aren't coherent between preferences, play random tracks, play stream, about, etc. dialog. They're not coherent with other Gnome applications.

Analysis

Goal (motivated by "coherence" with other Gnome applications):

Other goal (unfortunately abandonned, see below):

Reconfigurable keybindings

Reconfigurable keybindings in Gtk must be implemented using "keybinding signals".

For example there are "keybinding signals" to close dialogs and shortcuts window; Their default binding is the Escape key, see Dialog::close and ShortcutsWindow::close

But I found no way to get in Python the Gtk.BindingSet instance required as first argument of Gtk.binding_entry_add_signall() (BindingSet.by_class() isn't exposed to Python through gi according to its documentation, see https://docs.gtk.org/gtk3/type_func.BindingSet.by_class.html#description.

Thus:

orontee commented 11 months ago

Something like the following is possible to add a Ctrl+b key binding to close dialogs (play stream, play random tracks, etc.):

@binding-set CloseWindowFromDialogs {
  bind "<Primary>b" { "close" () };
}

dialog {
  -gtk-key-bindings: CloseWindowFromDialogs;
}

window#preferences-window {
  -gtk-key-bindings: CloseWindowFromDialogs;
}

when a "keybinding signal" named close has been created on the class PreferencesWindow:

    @GObject.Signal(
        flags=GObject.SignalFlags.RUN_LAST | GObject.SignalFlags.ACTION,
        arg_types=[],
        return_type=None,
    )
    def close(self, *args) -> None:
        super().close()

:warning: Not working with w char due to its use as accelerator in app.py... See https://lazka.github.io/pgi-docs/#Gtk-3.0/classes/Widget.html#Gtk.Widget.add_accelerator where it's said that such accelerators aren't editable at runtime.

My understanding is that BindingSet.by_class() is not exposed to Python, thus there's no way to define key bindings that are editable through CSS... See https://docs.gtk.org/gtk3/type_func.BindingSet.by_class.html#description