From 5ee6b2adfaab4439f5bc930b7c080d66bdf8aae0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 25 Apr 2014 08:40:46 +0200 Subject: [PATCH] Revert "Remove setting forward_unbound_keys." This reverts commit d07e22bd91593714a81e8e24463fb9ceb0c86192. --- qutebrowser/app.py | 2 +- qutebrowser/config/configdata.py | 4 ++++ qutebrowser/keyinput/modes.py | 22 +++++++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index f4ac3aabb..7772ddd00 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -291,7 +291,7 @@ class QuteBrowser(QApplication): # config self.config.style_changed.connect(style.invalidate_caches) for obj in [tabs, completion, self.mainwindow, config.cmd_history, - websettings, kp["normal"]]: + websettings, kp["normal"], modes.manager]: self.config.changed.connect(obj.on_config_changed) # statusbar diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 652ae0376..77b6d2b0a 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -196,6 +196,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/keyinput/modes.py b/qutebrowser/keyinput/modes.py index c052aa731..f0e75c9e9 100644 --- a/qutebrowser/keyinput/modes.py +++ b/qutebrowser/keyinput/modes.py @@ -75,6 +75,7 @@ class ModeManager(QObject): _handlers: A dictionary of modes and their handlers. _mode_stack: A list of the modes we're currently in, with the active one on the right. + _forward_unbound_keys: If we should forward unbound keys. Signals: entered: Emitted when a mode is entered. @@ -93,6 +94,8 @@ class ModeManager(QObject): self._handlers = {} self.passthrough = [] self._mode_stack = [] + self._forward_unbound_keys = config.get('general', + 'forward_unbound_keys') @property def mode(self): @@ -158,6 +161,13 @@ class ModeManager(QObject): raise ValueError("Can't leave normal mode!") self.leave(self.mode) + @pyqtSlot(str, str) + def on_config_changed(self, section, option): + """Update local setting when config changed.""" + if (section, option) == ('general', 'forward_unbound_keys'): + self._forward_unbound_keys = config.get('general', + 'forward_unbound_keys') + def eventFilter(self, obj, evt): """Filter all events based on the currently set mode. @@ -204,11 +214,17 @@ class ModeManager(QObject): # KeyPress in a non-passthrough mode - call handler and filter # event from widgets (unless unhandled and configured to pass # unhandled events through) - logging.debug("KeyPress, calling handler {} and " - "filtering".format(handler)) + logging.debug("KeyPress, calling handler {}".format(handler)) self.key_pressed.emit(evt) handled = handler(evt) if handler is not None else False - return True + logging.debug("handled: {}, forward_unbound_keys: {} -> " + "filtering: {}".format( + handled, self._forward_unbound_keys, + handled or not self._forward_unbound_keys)) + if handled or not self._forward_unbound_keys: + return True + else: + return False else: # KeyRelease in a non-passthrough mode - filter event and # ignore it entirely.