Fix: Allow Key Bindings with Shift-Modified Keys
This commit allows to set key bindings that contain a key modified by a Shift key (e.g. `Ctrl + {`). For example, after pressing `Ctrl + Shift + [`, a key binding will be set to `Ctrl + {` as opposed to `Ctrl + Shift + {` as before. This is achieved by checking whether a key changes its value when a Shift key is down. If it does, then the Shift modifier is removed from `mods`. One exception: if a key binding contains a letter then the Shift modifier is not removed. This is because, for some reason, a key value of a letter is never modified by the Shift modifier and always corresponds to a key value of a lowercase character. This is already handled in `terminatorlib/keybindings.py`. Resolves: #149
This commit is contained in:
parent
6affbf5b0c
commit
279a3e10e6
|
@ -1550,6 +1550,21 @@ class PrefsEditor:
|
|||
|
||||
def on_cellrenderer_accel_edited(self, liststore, path, key, mods, _code):
|
||||
"""Handle an edited keybinding"""
|
||||
if mods & Gdk.ModifierType.SHIFT_MASK:
|
||||
key_with_shift = Gdk.Keymap.translate_keyboard_state(
|
||||
self.keybindings.keymap,
|
||||
hardware_keycode=_code,
|
||||
state=Gdk.ModifierType.SHIFT_MASK,
|
||||
group=0,
|
||||
)
|
||||
keyval_lower, keyval_upper = Gdk.keyval_convert_case(key)
|
||||
|
||||
# Remove the Shift modifier from `mods` if a new key binding doesn't
|
||||
# contain a letter and its key value (`key`) can't be modified by a
|
||||
# Shift key.
|
||||
if key_with_shift.level != 0 and keyval_lower == keyval_upper:
|
||||
mods = Gdk.ModifierType(mods & ~Gdk.ModifierType.SHIFT_MASK)
|
||||
|
||||
celliter = liststore.get_iter_from_string(path)
|
||||
liststore.set(celliter, 2, key, 3, mods)
|
||||
|
||||
|
|
Loading…
Reference in New Issue