From e26eaaddc2c2de006c9bc9108cac512f9f2df65d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 28 Feb 2018 12:52:19 +0100 Subject: [PATCH] Add keyutils.is_modifier_key() --- qutebrowser/keyinput/basekeyparser.py | 14 ++------------ qutebrowser/keyinput/keyutils.py | 16 ++++++++++------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/qutebrowser/keyinput/basekeyparser.py b/qutebrowser/keyinput/basekeyparser.py index 27f671dcd..2c934617b 100644 --- a/qutebrowser/keyinput/basekeyparser.py +++ b/qutebrowser/keyinput/basekeyparser.py @@ -128,20 +128,10 @@ class BaseKeyParser(QObject): txt = str(keyutils.KeyInfo.from_event(e)) self._debug_log("Got key: 0x{:x} / text: '{}'".format(key, txt)) - if not txt: - self._debug_log("Ignoring, no text char") + if keyutils.is_modifier_key(key): + self._debug_log("Ignoring, only modifier") return QKeySequence.NoMatch - # if len(txt) == 1: - # category = unicodedata.category(txt) - # is_control_char = (category == 'Cc') - # else: - # is_control_char = False - - # if (not txt) or is_control_char: - # self._debug_log("Ignoring, no text char") - # return QKeySequence.NoMatch - if (txt.isdigit() and self._supports_count and not (not self._count and txt == '0')): assert len(txt) == 1, txt diff --git a/qutebrowser/keyinput/keyutils.py b/qutebrowser/keyinput/keyutils.py index 1bd9ee737..b1d1cec45 100644 --- a/qutebrowser/keyinput/keyutils.py +++ b/qutebrowser/keyinput/keyutils.py @@ -34,6 +34,14 @@ def is_printable(key): return key <= 0xff +def is_modifier_key(key): + # FIXME docs + return key in (Qt.Key_Control, Qt.Key_Alt, Qt.Key_Shift, Qt.Key_Meta, + Qt.Key_AltGr, Qt.Key_Super_L, Qt.Key_Super_R, + Qt.Key_Hyper_L, Qt.Key_Hyper_R, Qt.Key_Direction_L, + Qt.Key_Direction_R) + + def _key_to_string(key): """Convert a Qt::Key member to a meaningful name. @@ -216,13 +224,9 @@ class KeyInfo: (Qt.ShiftModifier, 'Shift'), ]) - modifier_keys = (Qt.Key_Control, Qt.Key_Alt, Qt.Key_Shift, Qt.Key_Meta, - Qt.Key_AltGr, Qt.Key_Super_L, Qt.Key_Super_R, - Qt.Key_Hyper_L, Qt.Key_Hyper_R, Qt.Key_Direction_L, - Qt.Key_Direction_R) - if self.key in modifier_keys: - # Only modifier pressed + if is_modifier_key(self.key): return '' + parts = [] for (mask, s) in modmask2str.items():