Allow `Shift+Tab` Key Binding Accelerator

This commit allows to assign the `Shift+Tab` key binding to an action in
`Preferences>Keybindings`.

In GTK the Tab key can be modified by the Shift key. Such a key combination
has a special key value - `Gdk.KEY_ISO_Left_Tab`.
To allow it, `key = key_with_shift.keyval` was added to the code.

However, `Gdk.KEY_ISO_Left_Tab` key value is displayed as `Left Tab` in
`Preferences>Keybindings`, which is confusing as it is not obvious that it
corresponds to the `Shift+Tab` key combination. To make sure that `Shift+Tab`
is displayed as `Shift+Tab`, the `Shift+Tab` case is treated as if no Shift
was pressed at all.
This commit is contained in:
dkmvs 2020-09-14 04:26:13 +03:00
parent a93609da8f
commit 6c404d0355
1 changed files with 4 additions and 1 deletions

View File

@ -1673,7 +1673,9 @@ class PrefsEditor:
def on_cellrenderer_accel_edited(self, liststore, path, key, mods, _code): def on_cellrenderer_accel_edited(self, liststore, path, key, mods, _code):
"""Handle an edited keybinding""" """Handle an edited keybinding"""
if mods & Gdk.ModifierType.SHIFT_MASK: # Ignore `Gdk.KEY_Tab` so that `Shift+Tab` is displayed as `Shift+Tab`
# in `Preferences>Keybindings` and NOT `Left Tab` (see `Gdk.KEY_ISO_Left_Tab`).
if mods & Gdk.ModifierType.SHIFT_MASK and key != Gdk.KEY_Tab:
key_with_shift = Gdk.Keymap.translate_keyboard_state( key_with_shift = Gdk.Keymap.translate_keyboard_state(
self.keybindings.keymap, self.keybindings.keymap,
hardware_keycode=_code, hardware_keycode=_code,
@ -1687,6 +1689,7 @@ class PrefsEditor:
# Shift key. # Shift key.
if key_with_shift.level != 0 and keyval_lower == keyval_upper: if key_with_shift.level != 0 and keyval_lower == keyval_upper:
mods = Gdk.ModifierType(mods & ~Gdk.ModifierType.SHIFT_MASK) mods = Gdk.ModifierType(mods & ~Gdk.ModifierType.SHIFT_MASK)
key = key_with_shift.keyval
accel = Gtk.accelerator_name(key, mods) accel = Gtk.accelerator_name(key, mods)
current_binding = liststore.get_value(liststore.get_iter(path), 0) current_binding = liststore.get_value(liststore.get_iter(path), 0)