diff options
author | Florian Bruhin <git@the-compiler.org> | 2015-03-16 22:30:06 +0100 |
---|---|---|
committer | Florian Bruhin <git@the-compiler.org> | 2015-03-19 06:21:08 +0100 |
commit | 44dd4da33f6fe9520e6b7442fb9eaebd9ed78788 (patch) | |
tree | d71c19d707752e69cb9d088045372366302a6552 | |
parent | f69470ddcd6fd1189f04e710753769e676ca784f (diff) | |
download | qutebrowser-44dd4da33f6fe9520e6b7442fb9eaebd9ed78788.tar.gz qutebrowser-44dd4da33f6fe9520e6b7442fb9eaebd9ed78788.zip |
Discard uninteresting events early in eventFilter.
Before, we ran quite a lot of code (e.g. objreg) on every event, even if it
turns out to not be a keypress/release event at all.
-rw-r--r-- | qutebrowser/keyinput/modeman.py | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/qutebrowser/keyinput/modeman.py b/qutebrowser/keyinput/modeman.py index 1d4aca57a..e44cc2319 100644 --- a/qutebrowser/keyinput/modeman.py +++ b/qutebrowser/keyinput/modeman.py @@ -107,15 +107,29 @@ class EventFilter(QObject): def eventFilter(self, obj, event): """Forward events to the correct modeman.""" - if not self._activated: - return False try: - modeman = objreg.get('mode-manager', scope='window', - window='current') - return modeman.eventFilter(obj, event) - except objreg.RegistryUnavailableError: - # No window available yet, or not a MainWindow - return False + if not self._activated: + return False + if event.type() not in [QEvent.KeyPress, QEvent.KeyRelease]: + # We're not interested in non-key-events so we pass them + # through. + return False + if not isinstance(obj, QWindow): + # We already handled this same event at some point earlier, so + # we're not interested in it anymore. + return False + if (QApplication.instance().activeWindow() not in + objreg.window_registry.values()): + # Some other window (print dialog, etc.) is focused so we pass + # the event through. + return False + try: + modeman = objreg.get('mode-manager', scope='window', + window='current') + return modeman.eventFilter(event) + except objreg.RegistryUnavailableError: + # No window available yet, or not a MainWindow + return False except: # If there is an exception in here and we leave the eventfilter # activated, we'll get an infinite loop and a stack overflow. @@ -317,7 +331,7 @@ class ModeManager(QObject): self._forward_unbound_keys = config.get( 'input', 'forward-unbound-keys') - def eventFilter(self, obj, event): + def eventFilter(self, event): """Filter all events based on the currently set mode. Also calls the real keypress handler. @@ -331,21 +345,7 @@ class ModeManager(QObject): if self.mode is None: # We got events before mode is set, so just pass them through. return False - typ = event.type() - if typ not in [QEvent.KeyPress, QEvent.KeyRelease]: - # We're not interested in non-key-events so we pass them through. - return False - if not isinstance(obj, QWindow): - # We already handled this same event at some point earlier, so - # we're not interested in it anymore. - return False - if (QApplication.instance().activeWindow() not in - objreg.window_registry.values()): - # Some other window (print dialog, etc.) is focused so we pass - # the event through. - return False - - if typ == QEvent.KeyPress: + if event.type() == QEvent.KeyPress: return self._eventFilter_keypress(event) else: return self._eventFilter_keyrelease(event) |