From a8aaf01ff0fe2597c856c8efa5a192f640c42e6d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 28 Dec 2017 23:03:59 +0100 Subject: [PATCH] Fix some more stuff (and break some :D) --- qutebrowser/config/config.py | 16 +++++++++------- qutebrowser/config/configcommands.py | 8 ++++---- qutebrowser/keyinput/basekeyparser.py | 22 +++++++++++++--------- qutebrowser/keyinput/keyparser.py | 3 ++- qutebrowser/misc/keyhintwidget.py | 1 - qutebrowser/misc/miscwidgets.py | 2 -- qutebrowser/utils/utils.py | 17 ++++++++++++++++- 7 files changed, 44 insertions(+), 25 deletions(-) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index c170d0705..1f910f549 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -136,9 +136,10 @@ class KeyConfig: """Make sure the given mode exists and normalize the key.""" if mode not in configdata.DATA['bindings.default'].default: raise configexc.KeybindingError("Invalid mode {}!".format(mode)) - if utils.is_special_key(key): - # , , and should be considered equivalent - return utils.normalize_keystr(key) + # FIXME needed? + # if utils.is_special_key(key): + # # , , and should be considered equivalent + # return utils.normalize_keystr(key) return key def get_bindings_for(self, mode): @@ -160,10 +161,11 @@ class KeyConfig: cmd = cmd.strip() cmd_to_keys.setdefault(cmd, []) # put special bindings last - if utils.is_special_key(key): - cmd_to_keys[cmd].append(key) - else: - cmd_to_keys[cmd].insert(0, key) + # FIXME update + # if utils.is_special_key(key): + # cmd_to_keys[cmd].append(key) + # else: + cmd_to_keys[cmd].insert(0, key.toString()) return cmd_to_keys def get_command(self, key, mode, default=False): diff --git a/qutebrowser/config/configcommands.py b/qutebrowser/config/configcommands.py index 7d9adb475..711fe861c 100644 --- a/qutebrowser/config/configcommands.py +++ b/qutebrowser/config/configcommands.py @@ -117,10 +117,10 @@ class ConfigCommands: return # No --default -> print binding - if utils.is_special_key(key): - # self._keyconfig.get_command does this, but we also need it - # normalized for the output below - key = utils.normalize_keystr(key) + #if utils.is_special_key(key): + # # self._keyconfig.get_command does this, but we also need it + # # normalized for the output below + # key = utils.normalize_keystr(key) with self._handle_config_error(): cmd = self._keyconfig.get_command(key, mode) if cmd is None: diff --git a/qutebrowser/keyinput/basekeyparser.py b/qutebrowser/keyinput/basekeyparser.py index ef902c82a..95149df3e 100644 --- a/qutebrowser/keyinput/basekeyparser.py +++ b/qutebrowser/keyinput/basekeyparser.py @@ -173,20 +173,24 @@ class BaseKeyParser(QObject): Return: A self.Match member. """ - txt = e.text() key = e.key() + txt = utils.keyevent_to_string(e) self._debug_log("Got key: 0x{:x} / text: '{}'".format(key, txt)) - 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: + if txt is None: self._debug_log("Ignoring, no text char") 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 + count, cmd_input = self._split_count(self._keystring + txt) match, binding = self._match_key(cmd_input) if match == QKeySequence.NoMatch: @@ -233,7 +237,7 @@ class BaseKeyParser(QObject): return (None, None) for seq, cmd in self.bindings.items(): - match = seq.matches(utils.parse_keystring(cmd_input)) + match = seq.matches(cmd_input) if match != QKeySequence.NoMatch: return (match, cmd) diff --git a/qutebrowser/keyinput/keyparser.py b/qutebrowser/keyinput/keyparser.py index 8fcb53035..3df8ab193 100644 --- a/qutebrowser/keyinput/keyparser.py +++ b/qutebrowser/keyinput/keyparser.py @@ -56,7 +56,8 @@ class PassthroughKeyParser(CommandKeyParser): _mode: The mode this keyparser is for. """ - do_log = False + # FIXME + # do_log = False passthrough = True def __init__(self, win_id, mode, parent=None, warn=True): diff --git a/qutebrowser/misc/keyhintwidget.py b/qutebrowser/misc/keyhintwidget.py index 46d1d3f24..600095e0f 100644 --- a/qutebrowser/misc/keyhintwidget.py +++ b/qutebrowser/misc/keyhintwidget.py @@ -106,7 +106,6 @@ class KeyHintView(QLabel): bindings_dict = config.key_instance.get_bindings_for(modename) bindings = [(k, v) for (k, v) in sorted(bindings_dict.items()) if k.startswith(prefix) and - not utils.is_special_key(k) and not blacklisted(k) and (takes_count(v) or not countstr)] diff --git a/qutebrowser/misc/miscwidgets.py b/qutebrowser/misc/miscwidgets.py index 5d3e9b5ca..c52600bb1 100644 --- a/qutebrowser/misc/miscwidgets.py +++ b/qutebrowser/misc/miscwidgets.py @@ -293,8 +293,6 @@ class FullscreenNotification(QLabel): bindings = all_bindings.get('fullscreen --leave') if bindings: key = bindings[0] - if utils.is_special_key(key): - key = key.strip('<>').capitalize() self.setText("Press {} to exit fullscreen.".format(key)) else: self.setText("Page is now fullscreen.") diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index eb6ebe901..29d9c6671 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -33,6 +33,7 @@ import functools import contextlib import socket import shlex +import unicodedata import attr from PyQt5.QtCore import Qt, QUrl @@ -418,10 +419,22 @@ def keyevent_to_string(e): return None mod = e.modifiers() parts = [] + for (mask, s) in modmask2str.items(): if mod & mask and s not in parts: parts.append(s) - parts.append(key_to_string(e.key())) + + key_string = key_to_string(e.key()) + if len(key_string) == 1: + category = unicodedata.category(key_string) + is_control_char = (category == 'Cc') + else: + is_control_char = False + + if e.modifiers() == Qt.ShiftModifier and not is_control_char: + parts = [] + + parts.append(key_string) return normalize_keystr('+'.join(parts)) @@ -466,6 +479,8 @@ def is_special_key(keystr): def _parse_single_key(keystr): """Convert a single key string to a (Qt.Key, Qt.Modifiers, text) tuple.""" + # FIXME remove + if is_special_key(keystr): # Special key keystr = keystr[1:-1]