Don't filter events if mainwindow is not focused

This commit is contained in:
Florian Bruhin 2014-05-07 17:20:01 +02:00
parent 19af445da0
commit 68b134b4a9
3 changed files with 7 additions and 10 deletions

2
TODO
View File

@ -11,8 +11,6 @@ Before 0.1
- Autosave feature (against segfaults/...)
- Save tabs feature
- More dwb keybindings
- Filter events in QMainWindow, not QApplication
or at least release them when opening other windows, e.g. print dialog
- Use :open engine searchterm syntax for searching
Crashes

View File

@ -135,6 +135,7 @@ class QuteBrowser(QApplication):
self._init_cmds()
self.mainwindow = MainWindow()
self.modeman.mainwindow = self.mainwindow
self.installEventFilter(self.modeman)
self.setQuitOnLastWindowClosed(False)
@ -399,13 +400,6 @@ class QuteBrowser(QApplication):
self._quit_status['crash'] = False
# Give key input back for crash dialog
try:
self.removeEventFilter(self.modeman)
except AttributeError:
# self.modeman could be None
pass
if exctype is BdbQuit or not issubclass(exctype, Exception):
# pdb exit, KeyboardInterrupt, ...
try:

View File

@ -62,6 +62,7 @@ class ModeManager(QObject):
Attributes:
mode: The current mode (readonly property).
passthrough: A list of modes in which to pass through events.
mainwindow: The mainwindow object
_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.
@ -84,6 +85,7 @@ class ModeManager(QObject):
def __init__(self, parent=None):
super().__init__(parent)
self.mainwindow = None
self._handlers = {}
self.passthrough = []
self._mode_stack = []
@ -248,7 +250,10 @@ class ModeManager(QObject):
logging.debug("Ignoring event {} for {}".format(
debug.EVENTS[typ], obj.__class__.__name__))
return False
if QApplication.instance().activeWindow() is not self.mainwindow:
# Some other window (print dialog, etc.) is focused so we pass
# the event through.
return False
logging.debug("Got event {} for {} in mode {}".format(
debug.EVENTS[typ], obj.__class__.__name__, self.mode))