From cd5f2562aabaa44cff0b641202a986b3a201e6d4 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 23 Apr 2014 23:24:46 +0200 Subject: [PATCH] Adjust eventFilter to use new features --- qutebrowser/utils/modemanager.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/qutebrowser/utils/modemanager.py b/qutebrowser/utils/modemanager.py index 1fb262cb5..bc5fc7f10 100644 --- a/qutebrowser/utils/modemanager.py +++ b/qutebrowser/utils/modemanager.py @@ -102,12 +102,29 @@ class ModeManager(QObject): self.entered.emit(mode) def eventFilter(self, obj, evt): - if evt.type() not in [QEvent.KeyPress, QEvent.KeyRelease]: + """Filter all events based on the currently set mode. + + Also calls the real keypress handler. + """ + typ = evt.type() + handler = self._handlers[self.mode] + if typ not in [QEvent.KeyPress, QEvent.KeyRelease]: + # We're not interested in non-key-events so we pass them through. return False - elif self.mode == "insert": + elif self.mode in self._passthrough: + # We're currently in a passthrough mode so we pass everything + # through.*and* let the passthrough keyhandler know. + # FIXME what if we leave the passthrough mode right here? + if handler is not None: + handler(evt) return False - elif evt.type() == QEvent.KeyPress: - self._handlers[self.mode](evt) + elif typ == QEvent.KeyPress: + # KeyPress in a non-passthrough mode - call handler and filter + # event from widgets + if handler is not None: + handler(evt) return True else: + # KeyRelease in a non-passthrough mode - filter event and ignore it + # entirely. return True