From d3121034dfd568f335332af0ef44e99ca43e3019 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 5 Oct 2014 23:09:35 +0200 Subject: [PATCH] Revert "Store window registries in objreg." This reverts commit dfd3b3d9c446601fa30ba94488b683a72dd25673. It turns out this makes it very hard to remove the window from the window registry at the right time. --- qutebrowser/keyinput/modeman.py | 6 ++---- qutebrowser/utils/objreg.py | 20 ++++++++++++-------- qutebrowser/widgets/mainwindow.py | 8 ++------ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/qutebrowser/keyinput/modeman.py b/qutebrowser/keyinput/modeman.py index 350057cb7..cf172b8a5 100644 --- a/qutebrowser/keyinput/modeman.py +++ b/qutebrowser/keyinput/modeman.py @@ -359,10 +359,8 @@ class ModeManager(QObject): # We already handled this same event at some point earlier, so # we're not interested in it anymore. return False - win = QApplication.instance().activeWindow() - if win is None: - return False - if win.objectName() != 'MainWindow': + 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 diff --git a/qutebrowser/utils/objreg.py b/qutebrowser/utils/objreg.py index 481eec7e6..8ac8282fc 100644 --- a/qutebrowser/utils/objreg.py +++ b/qutebrowser/utils/objreg.py @@ -115,19 +115,22 @@ def _get_tab_registry(): raise RegistryUnavailableError('tab') -def _get_window_registry(win_id): +def _get_window_registry(window): """Get the registry of a window.""" - if win_id is None: - raise TypeError("win_id is None with scope window!") - if win_id == 'current': + if window is None: + raise TypeError("window is None with scope window!") + if window is 'current': app = get('app') win = app.activeWindow() if win is None or not hasattr(win, 'win_id'): raise RegistryUnavailableError('window') - else: - win_id = win.win_id + else: + try: + win = window_registry[window] + except KeyError: + raise RegistryUnavailableError('window') try: - return window_registry[win_id] + return win.registry except AttributeError: raise RegistryUnavailableError('window') @@ -196,7 +199,8 @@ def dump_objects(): blocks = [] lines = [] blocks.append(('global', global_registry.dump_objects())) - for win_id, registry in window_registry.items(): + for win_id in window_registry: + registry = _get_registry('window', window=win_id) blocks.append(('window-{}'.format(win_id), registry.dump_objects())) # FIXME: Add tab registries for name, data in sorted(blocks, key=lambda e: e[0]): diff --git a/qutebrowser/widgets/mainwindow.py b/qutebrowser/widgets/mainwindow.py index c216828e9..c3376ad68 100644 --- a/qutebrowser/widgets/mainwindow.py +++ b/qutebrowser/widgets/mainwindow.py @@ -72,15 +72,11 @@ class MainWindow(QWidget): def __init__(self, win_id, parent=None): super().__init__(parent) - # Note the objectname is used in the event filter to filter keypresses - # not intended for the mainwindow. If this is changed, the event filter - # needs to be changed as well! - self.setObjectName('MainWindow') self.setAttribute(Qt.WA_DeleteOnClose) self._commandrunner = None self.win_id = win_id - registry = objreg.ObjectRegistry() - objreg.window_registry[win_id] = registry + self.registry = objreg.ObjectRegistry() + objreg.window_registry[win_id] = self objreg.register('main-window', self, scope='window', window=win_id) message_bridge = message.MessageBridge(self)