From 279a3e10e6d4de4c6a81e7f7ac3bda67bebe57fb Mon Sep 17 00:00:00 2001 From: dkmvs <67212386+dkmvs@users.noreply.github.com> Date: Sat, 27 Jun 2020 23:42:04 +0100 Subject: [PATCH] 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 --- terminatorlib/prefseditor.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index 28c358e0..50365bec 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -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)