From 0e3e5880381a564f49a3c65afabeeeb9e45ba43b Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 24 Apr 2014 16:53:16 +0200 Subject: [PATCH] Add forward_unbound_keys setting --- TODO | 1 - qutebrowser/commands/keys.py | 7 +++++-- qutebrowser/config/configdata.py | 4 ++++ qutebrowser/utils/keyparser.py | 10 ++++++++-- qutebrowser/utils/modemanager.py | 16 +++++++++++++--- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/TODO b/TODO index c2a1df38b..972c80736 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ keyparser foo ============= - Handle keybind to get out of insert mode (e.g. esc) -- Add passthrough-keys option to pass through unmapped keys - Add more element-selection-detection code (with options?) based on: -> javascript: http://stackoverflow.com/a/2848120/2085149 -> microFocusChanged and check active element via: diff --git a/qutebrowser/commands/keys.py b/qutebrowser/commands/keys.py index 83727e6bd..512d60f0b 100644 --- a/qutebrowser/commands/keys.py +++ b/qutebrowser/commands/keys.py @@ -85,12 +85,15 @@ class CommandKeyParser(KeyParser): Emit: set_cmd_text: If the keystring should be shown in the statusbar. + + Return: + True if event has been handled, False otherwise. """ txt = e.text().strip() if not self._keystring and any(txt == c for c in STARTCHARS): self.set_cmd_text.emit(txt) - return - super()._handle_single_key(e) + return True + return super()._handle_single_key(e) def execute(self, cmdstr, count=None): """Handle a completed keychain.""" diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 5d18bd43e..c8c90b6d9 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -176,6 +176,10 @@ DATA = OrderedDict([ SettingValue(types.Bool(), "true"), "Whether to automatically enter insert mode if an editable element " "is focused after page load."), + + ('forward_unbound_keys', + SettingValue(types.Bool(), "false"), + "Whether to forward unbound keys to the website in normal mode."), )), ('tabbar', sect.KeyValue( diff --git a/qutebrowser/utils/keyparser.py b/qutebrowser/utils/keyparser.py index a8e3ae7b7..a5b76cf60 100644 --- a/qutebrowser/utils/keyparser.py +++ b/qutebrowser/utils/keyparser.py @@ -116,12 +116,15 @@ class KeyParser(QObject): Args: e: the KeyPressEvent from Qt. + + Return: + True if event has been handled, False otherwise. """ logging.debug('Got key: {} / text: "{}"'.format(e.key(), e.text())) txt = e.text().strip() if not txt: logging.debug('Ignoring, no text') - return + return False self._stop_delayed_exec() self._keystring += txt @@ -135,7 +138,8 @@ class KeyParser(QObject): count = None if not cmd_input: - return + # Only a count, no command yet, but we handled it + return True (match, binding) = self._match_key(cmd_input) @@ -151,6 +155,8 @@ class KeyParser(QObject): logging.debug('Giving up with "{}", no matches'.format( self._keystring)) self._keystring = '' + return False + return True def _match_key(self, cmd_input): """Try to match a given keystring with any bound keychain. diff --git a/qutebrowser/utils/modemanager.py b/qutebrowser/utils/modemanager.py index 87632c766..75a16486a 100644 --- a/qutebrowser/utils/modemanager.py +++ b/qutebrowser/utils/modemanager.py @@ -25,6 +25,8 @@ import logging from PyQt5.QtCore import pyqtSignal, QObject, QEvent +import qutebrowser.config.config as config + manager = None @@ -168,11 +170,19 @@ class ModeManager(QObject): return False elif typ == QEvent.KeyPress: # KeyPress in a non-passthrough mode - call handler and filter - # event from widgets + # event from widgets (unless unhandled and configured to pass + # unhandled events through) self.key_pressed.emit(evt) if handler is not None: - handler(evt) - return True + handled = handler(evt) + else: + handled = False + if handled: + return True + elif config.get('general', 'forward_unbound_keys'): + return False + else: + return True else: # KeyRelease in a non-passthrough mode - filter event and ignore it # entirely.