diff options
author | Florian Bruhin <me@the-compiler.org> | 2022-12-12 14:23:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-12 14:23:09 +0100 |
commit | ac761234c9de65bd6b25ae8b2eeae0828c98a99c (patch) | |
tree | 753b1d02f3114caeee04d1c87a64a7dc968b2bb2 | |
parent | ce51fc522688cc8d644aaaea0b8cc6a8d81ddacc (diff) | |
parent | a00a14c87cb4d1e39b3b5ec0660b26276d9651f2 (diff) | |
download | qutebrowser-ac761234c9de65bd6b25ae8b2eeae0828c98a99c.tar.gz qutebrowser-ac761234c9de65bd6b25ae8b2eeae0828c98a99c.zip |
Merge pull request #7510 from qutebrowser/qt6-delay-window-show
qt6: Delay showing windows
-rw-r--r-- | qutebrowser/app.py | 77 | ||||
-rw-r--r-- | qutebrowser/browser/commands.py | 28 | ||||
-rw-r--r-- | qutebrowser/browser/navigate.py | 2 | ||||
-rw-r--r-- | qutebrowser/browser/shared.py | 24 | ||||
-rw-r--r-- | qutebrowser/browser/webelem.py | 2 | ||||
-rw-r--r-- | qutebrowser/mainwindow/mainwindow.py | 32 | ||||
-rw-r--r-- | qutebrowser/mainwindow/prompt.py | 16 | ||||
-rw-r--r-- | qutebrowser/mainwindow/tabbedbrowser.py | 9 | ||||
-rw-r--r-- | qutebrowser/mainwindow/tabwidget.py | 77 | ||||
-rw-r--r-- | qutebrowser/mainwindow/windowundo.py | 2 | ||||
-rw-r--r-- | qutebrowser/misc/quitter.py | 37 | ||||
-rw-r--r-- | qutebrowser/misc/sessions.py | 3 |
12 files changed, 141 insertions, 168 deletions
diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 6b5c35914..db7eea608 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -200,6 +200,7 @@ def _process_args(args): if not args.override_restore: sessions.load_default(args.session) + new_window = None if not sessions.session_manager.did_load: log.init.debug("Initializing main window...") private = args.target == 'private-window' @@ -210,15 +211,17 @@ def _process_args(args): error.handle_fatal_exc(err, 'Cannot start in private mode', no_err_windows=args.no_err_windows) sys.exit(usertypes.Exit.err_init) - window = mainwindow.MainWindow(private=private) - if not args.nowindow: - window.show() - objects.qapp.setActiveWindow(window) + + new_window = mainwindow.MainWindow(private=private) process_pos_args(args.command) _open_startpage() _open_special_pages(args) + if new_window is not None and not args.nowindow: + new_window.show() + objects.qapp.setActiveWindow(new_window) + delta = datetime.datetime.now() - earlyinit.START_TIME log.init.debug("Init finished after {}s".format(delta.total_seconds())) @@ -242,26 +245,30 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None): if command_target in {'window', 'private-window'}: command_target = 'tab-silent' - win_id: Optional[int] = None + window: Optional[mainwindow.MainWindow] = None if via_ipc and (not args or args == ['']): - win_id = mainwindow.get_window(via_ipc=via_ipc, - target=new_window_target) - _open_startpage(win_id) + window = mainwindow.get_window(via_ipc=via_ipc, target=new_window_target) + _open_startpage(window) + window.show() + window.maybe_raise() return for cmd in args: if cmd.startswith(':'): - if win_id is None: - win_id = mainwindow.get_window(via_ipc=via_ipc, - target=command_target) + if window is None: + window = mainwindow.get_window(via_ipc=via_ipc, target=command_target) + # FIXME preserving old behavior, but we probably shouldn't be + # doing this... + # See https://github.com/qutebrowser/qutebrowser/issues/5094 + window.maybe_raise() + log.init.debug("Startup cmd {!r}".format(cmd)) - commandrunner = runners.CommandRunner(win_id) + commandrunner = runners.CommandRunner(window.win_id) commandrunner.run_safely(cmd[1:]) elif not cmd: log.init.debug("Empty argument") - win_id = mainwindow.get_window(via_ipc=via_ipc, - target=new_window_target) + window = mainwindow.get_window(via_ipc=via_ipc, target=new_window_target) else: if via_ipc and target_arg and target_arg != 'auto': open_target = target_arg @@ -275,7 +282,7 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None): message.error("Error in startup argument '{}': {}".format( cmd, e)) else: - win_id = open_url(url, target=open_target, via_ipc=via_ipc) + window = open_url(url, target=open_target, via_ipc=via_ipc) def open_url(url, target=None, no_raise=False, via_ipc=True): @@ -288,39 +295,37 @@ def open_url(url, target=None, no_raise=False, via_ipc=True): via_ipc: Whether the arguments were transmitted over IPC. Return: - ID of a window that was used to open URL + The MainWindow of a window that was used to open the URL. """ target = target or config.val.new_instance_open_target background = target in {'tab-bg', 'tab-bg-silent'} - win_id = mainwindow.get_window(via_ipc=via_ipc, target=target, - no_raise=no_raise) - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=win_id) + window = mainwindow.get_window(via_ipc=via_ipc, target=target, no_raise=no_raise) log.init.debug("About to open URL: {}".format(url.toDisplayString())) - tabbed_browser.tabopen(url, background=background, related=False) - return win_id + window.tabbed_browser.tabopen(url, background=background, related=False) + window.show() + window.maybe_raise() + return window -def _open_startpage(win_id=None): +def _open_startpage(window: Optional[mainwindow.MainWindow] = None) -> None: """Open startpage. The startpage is never opened if the given windows are not empty. Args: - win_id: If None, open startpage in all empty windows. + window: If None, open startpage in all empty windows. If set, open the startpage in the given window. """ - if win_id is not None: - window_ids: Iterable[int] = [win_id] + if window is not None: + windows: Iterable[mainwindow.MainWindow] = [window] else: - window_ids = objreg.window_registry - for cur_win_id in list(window_ids): # Copying as the dict could change - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=cur_win_id) - if tabbed_browser.widget.count() == 0: + windows = objreg.window_registry.values() + + for cur_window in list(windows): # Copying as the dict could change + if cur_window.tabbed_browser.widget.count() == 0: log.init.debug("Opening start pages") for url in config.val.url.start_pages: - tabbed_browser.tabopen(url) + cur_window.tabbed_browser.tabopen(url) def _open_special_pages(args): @@ -425,10 +430,10 @@ def on_focus_changed(_old, new): def open_desktopservices_url(url): """Handler to open a URL via QDesktopServices.""" target = config.val.new_instance_open_target - win_id = mainwindow.get_window(via_ipc=True, target=target) - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=win_id) - tabbed_browser.tabopen(url) + window = mainwindow.get_window(via_ipc=True, target=target) + window.tabbed_browser.tabopen(url) + window.show() + window.maybe_raise() # This is effectively a @config.change_filter diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 7929ae005..4fbfe9e08 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -70,9 +70,7 @@ class CommandDispatcher: raise cmdutils.CommandError("Private windows are unavailable with " "the single-process process model.") - new_window = mainwindow.MainWindow(private=private) - new_window.show() - return new_window.tabbed_browser + return mainwindow.MainWindow(private=private).tabbed_browser def _count(self) -> int: """Convenience method to get the widget count.""" @@ -109,8 +107,15 @@ class CommandDispatcher: raise cmdutils.CommandError("No WebView available yet!") return widget - def _open(self, url, tab=False, background=False, window=False, - related=False, private=None): + def _open( + self, + url: QUrl, + tab: bool = False, + background: bool = False, + window: bool = False, + related: bool = False, + private: Optional[bool] = None, + ) -> None: """Helper function to open a page. Args: @@ -123,13 +128,15 @@ class CommandDispatcher: """ urlutils.raise_cmdexc_if_invalid(url) tabbed_browser = self._tabbed_browser - cmdutils.check_exclusive((tab, background, window, private), 'tbwp') + cmdutils.check_exclusive((tab, background, window, private or False), 'tbwp') if window and private is None: private = self._tabbed_browser.is_private if window or private: + assert isinstance(private, bool) tabbed_browser = self._new_tabbed_browser(private) tabbed_browser.tabopen(url) + tabbed_browser.window().show() elif tab: tabbed_browser.tabopen(url, background=False, related=related) elif background: @@ -403,14 +410,17 @@ class CommandDispatcher: except browsertab.WebTabError as e: raise cmdutils.CommandError(e) - # The new tab could be in a new tabbed_browser (e.g. because of - # tabs.tabs_are_windows being set) if window or private: new_tabbed_browser = self._new_tabbed_browser( private=self._tabbed_browser.is_private or private) else: new_tabbed_browser = self._tabbed_browser + newtab = new_tabbed_browser.tabopen(background=bg) + new_tabbed_browser.window().show() + + # The new tab could be in a new tabbed_browser (e.g. because of + # tabs.tabs_are_windows being set) new_tabbed_browser = objreg.get('tabbed-browser', scope='window', window=newtab.win_id) idx = new_tabbed_browser.widget.indexOf(newtab) @@ -498,6 +508,8 @@ class CommandDispatcher: "The window with id {} is not private".format(win_id)) tabbed_browser.tabopen(self._current_url()) + tabbed_browser.window().show() + if not keep: self._tabbed_browser.close_tab(self._current_widget(), add_undo=False, diff --git a/qutebrowser/browser/navigate.py b/qutebrowser/browser/navigate.py index d2783e349..148f0f6e9 100644 --- a/qutebrowser/browser/navigate.py +++ b/qutebrowser/browser/navigate.py @@ -219,10 +219,10 @@ def prevnext(*, browsertab, win_id, baseurl, prev=False, if window: new_window = mainwindow.MainWindow( private=cur_tabbed_browser.is_private) - new_window.show() tabbed_browser = objreg.get('tabbed-browser', scope='window', window=new_window.win_id) tabbed_browser.tabopen(url, background=False) + new_window.show() elif tab: cur_tabbed_browser.tabopen(url, background=background) else: diff --git a/qutebrowser/browser/shared.py b/qutebrowser/browser/shared.py index a2313a219..92ed99584 100644 --- a/qutebrowser/browser/shared.py +++ b/qutebrowser/browser/shared.py @@ -360,23 +360,19 @@ def get_tab(win_id, target): win_id: The window ID to open new tabs in target: A usertypes.ClickTarget """ - if target == usertypes.ClickTarget.tab: - bg_tab = False - elif target == usertypes.ClickTarget.tab_bg: - bg_tab = True - elif target == usertypes.ClickTarget.window: - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=win_id) + tabbed_browser = objreg.get('tabbed-browser', scope='window', window=win_id) + if target == usertypes.ClickTarget.window: window = mainwindow.MainWindow(private=tabbed_browser.is_private) + tab = window.tabbed_browser.tabopen(url=None, background=False) window.show() - win_id = window.win_id - bg_tab = False - else: - raise ValueError("Invalid ClickTarget {}".format(target)) + return tab + elif target in [usertypes.ClickTarget.tab, usertypes.ClickTarget.tab_bg]: + return tabbed_browser.tabopen( + url=None, + background=target == usertypes.ClickTarget.tab_bg, + ) - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=win_id) - return tabbed_browser.tabopen(url=None, background=bg_tab) + raise ValueError(f"Invalid ClickTarget {target}") def get_user_stylesheet(searching=False): diff --git a/qutebrowser/browser/webelem.py b/qutebrowser/browser/webelem.py index 91e82ae0c..672c73fdb 100644 --- a/qutebrowser/browser/webelem.py +++ b/qutebrowser/browser/webelem.py @@ -405,8 +405,8 @@ class AbstractWebElement(collections.abc.MutableMapping): # type: ignore[type-a elif click_target == usertypes.ClickTarget.window: from qutebrowser.mainwindow import mainwindow window = mainwindow.MainWindow(private=tabbed_browser.is_private) - window.show() window.tabbed_browser.tabopen(url) + window.show() else: raise ValueError("Unknown ClickTarget {}".format(click_target)) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 769f03794..2c6cd673f 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -48,7 +48,7 @@ win_id_gen = itertools.count(0) def get_window(*, via_ipc: bool, target: str, - no_raise: bool = False) -> int: + no_raise: bool = False) -> "MainWindow": """Helper function for app.py to get a window id. Args: @@ -58,32 +58,27 @@ def get_window(*, via_ipc: bool, no_raise: suppress target window raising Return: - ID of a window that was used to open URL + The MainWindow that was used to open URL """ if not via_ipc: # Initial main window - return 0 + return objreg.get("main-window", scope="window", window=0) window = None - should_raise = False # Try to find the existing tab target if opening in a tab if target not in {'window', 'private-window'}: window = get_target_window() - should_raise = target not in {'tab-silent', 'tab-bg-silent'} + window.should_raise = target not in {'tab-silent', 'tab-bg-silent'} and not no_raise is_private = target == 'private-window' # Otherwise, or if no window was found, create a new one if window is None: window = MainWindow(private=is_private) - window.show() - should_raise = True + window.should_raise = not no_raise - if should_raise and not no_raise: - raise_window(window) - - return window.win_id + return window def raise_window(window, alert=True): @@ -95,10 +90,11 @@ def raise_window(window, alert=True): QCoreApplication.processEvents( QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents | QEventLoop.ProcessEventsFlag.ExcludeSocketNotifiers) - if not sip.isdeleted(window): + if sip.isdeleted(window): # Could be deleted by the events run above - window.activateWindow() + return + window.activateWindow() if alert: objects.qapp.alert(window) @@ -132,6 +128,8 @@ class MainWindow(QWidget): status: The StatusBar widget. tabbed_browser: The TabbedBrowser widget. state_before_fullscreen: window state before activation of fullscreen. + should_raise: Whether the window should be raised/activated when maybe_raise() + gets called. _downloadview: The DownloadView widget. _download_model: The DownloadModel instance. _vbox: The main QVBoxLayout. @@ -279,6 +277,8 @@ class MainWindow(QWidget): self._set_decoration(config.val.window.hide_decoration) self.state_before_fullscreen = self.windowState() + self.should_raise: bool = False + stylesheet.set_register(self) def _init_geometry(self, geometry): @@ -665,6 +665,12 @@ class MainWindow(QWidget): return True + def maybe_raise(self) -> None: + """Raise the window if self.should_raise is set.""" + if self.should_raise: + raise_window(self) + self.should_raise = False + def closeEvent(self, e): """Override closeEvent to display a confirmation if needed.""" if crashsignal.crash_handler.is_crashing: diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 279721b2a..db7553e7e 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -131,20 +131,12 @@ class PromptQueue(QObject): """Cancel all blocking questions. Quits and removes all running event loops. - - Return: - True if loops needed to be aborted, - False otherwise. """ - log.prompt.debug("Shutting down with loops {}".format(self._loops)) + log.prompt.debug(f"Shutting down with loops {self._loops}") self._shutting_down = True - if self._loops: - for loop in self._loops: - loop.quit() - loop.deleteLater() - return True - else: - return False + for loop in self._loops: + loop.quit() + loop.deleteLater() @pyqtSlot(usertypes.Question, bool) def ask_question(self, question, blocking): diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index bcd07f088..ca6409ba0 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -34,7 +34,7 @@ from qutebrowser.config import config from qutebrowser.keyinput import modeman from qutebrowser.mainwindow import tabwidget, mainwindow from qutebrowser.browser import signalfilter, browsertab, history -from qutebrowser.utils import (log, usertypes, utils, qtutils, objreg, +from qutebrowser.utils import (log, usertypes, utils, qtutils, urlutils, message, jinja, version) from qutebrowser.misc import quitter, objects @@ -639,11 +639,10 @@ class TabbedBrowser(QWidget): if config.val.tabs.tabs_are_windows and self.widget.count() > 0: window = mainwindow.MainWindow(private=self.is_private) + tab = window.tabbed_browser.tabopen( + url=url, background=background, related=related) window.show() - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=window.win_id) - return tabbed_browser.tabopen(url=url, background=background, - related=related) + return tab tab = browsertab.create(win_id=self._win_id, private=self.is_private, diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index b157fc07a..5e4f519fa 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -26,9 +26,9 @@ from typing import Optional, Dict, Any from qutebrowser.qt.core import (pyqtSignal, pyqtSlot, Qt, QSize, QRect, QPoint, QTimer, QUrl) -from qutebrowser.qt.widgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle, +from qutebrowser.qt.widgets import (QTabWidget, QTabBar, QSizePolicy, QProxyStyle, QStyle, QStylePainter, QStyleOptionTab, - QStyleFactory) + QCommonStyle) from qutebrowser.qt.gui import QIcon, QPalette, QColor from qutebrowser.utils import qtutils, objreg, utils, usertypes, log @@ -775,7 +775,7 @@ class Layouts: indicator: QRect -class TabBarStyle(QCommonStyle): +class TabBarStyle(QProxyStyle): """Qt style used by TabBar to fix some issues with the default one. @@ -783,45 +783,10 @@ class TabBarStyle(QCommonStyle): - Remove the focus rectangle Ubuntu draws on tabs. - Force text to be left-aligned even though Qt has "centered" hardcoded. - - Unfortunately PyQt doesn't support QProxyStyle, so we need to do this the - hard way... - - Based on: - - https://stackoverflow.com/a/17294081 - https://code.google.com/p/makehuman/source/browse/trunk/makehuman/lib/qtgui.py """ ICON_PADDING = 4 - def __init__(self): - """Initialize all functions we're not overriding. - - This simply calls the corresponding function in self._style. - """ - self._style = QStyleFactory.create('Fusion') - for method in ['drawComplexControl', 'drawItemPixmap', - 'generatedIconPixmap', 'hitTestComplexControl', - 'itemPixmapRect', 'itemTextRect', 'polish', 'styleHint', - 'subControlRect', 'unpolish', 'drawItemText', - 'sizeFromContents', 'drawPrimitive']: - setattr(self, method, functools.partial(self._fusion_call, method)) - super().__init__() - - def _fusion_call(self, method: str, *args: Any) -> Any: - """Wrap a call to self._style to log RuntimeErrors. - - WORKAROUND for https://github.com/qutebrowser/qutebrowser/issues/5124 - """ - target = getattr(self._style, method) - try: - return target(*args) - except RuntimeError: - info = f"self._style.{method}{args}" - log.misc.warning(f"Got RuntimeError while calling {info}") - raise - def _draw_indicator(self, layouts, opt, p): """Draw the tab indicator. @@ -849,7 +814,7 @@ class TabBarStyle(QCommonStyle): icon_state = (QIcon.State.On if opt.state & QStyle.StateFlag.State_Selected else QIcon.State.Off) icon = opt.icon.pixmap(opt.iconSize, icon_mode, icon_state) - self._style.drawItemPixmap(p, layouts.icon, Qt.AlignmentFlag.AlignCenter, icon) + self.baseStyle().drawItemPixmap(p, layouts.icon, Qt.AlignmentFlag.AlignCenter, icon) def drawControl(self, element, opt, p, widget=None): """Override drawControl to draw odd tabs in a different color. @@ -866,7 +831,7 @@ class TabBarStyle(QCommonStyle): if element not in [QStyle.ControlElement.CE_TabBarTab, QStyle.ControlElement.CE_TabBarTabShape, QStyle.ControlElement.CE_TabBarTabLabel]: # Let the real style draw it. - self._style.drawControl(element, opt, p, widget) + self.baseStyle().drawControl(element, opt, p, widget) return layouts = self._tab_layout(opt) @@ -881,21 +846,23 @@ class TabBarStyle(QCommonStyle): elif element == QStyle.ControlElement.CE_TabBarTabShape: p.fillRect(opt.rect, opt.palette.window()) self._draw_indicator(layouts, opt, p) - # We use super() rather than self._style here because we don't want + # We use QCommonStyle rather than self.baseStyle() here because we don't want # any sophisticated drawing. - super().drawControl(QStyle.ControlElement.CE_TabBarTabShape, opt, p, widget) + QCommonStyle.drawControl(self, QStyle.ControlElement.CE_TabBarTabShape, opt, p, widget) elif element == QStyle.ControlElement.CE_TabBarTabLabel: if not opt.icon.isNull() and layouts.icon.isValid(): self._draw_icon(layouts, opt, p) alignment = (config.cache['tabs.title.alignment'] | Qt.AlignmentFlag.AlignVCenter | Qt.TextFlag.TextHideMnemonic) - self._style.drawItemText(p, - layouts.text, - int(alignment), - opt.palette, - bool(opt.state & QStyle.StateFlag.State_Enabled), - opt.text, - QPalette.ColorRole.WindowText) + self.baseStyle().drawItemText( + p, + layouts.text, + int(alignment), + opt.palette, + bool(opt.state & QStyle.StateFlag.State_Enabled), + opt.text, + QPalette.ColorRole.WindowText + ) else: raise ValueError("Invalid element {!r}".format(element)) @@ -917,7 +884,7 @@ class TabBarStyle(QCommonStyle): QStyle.PixelMetric.PM_TabBarScrollButtonWidth]: return 0 else: - return self._style.pixelMetric(metric, option, widget) + return self.baseStyle().pixelMetric(metric, option, widget) def subElementRect(self, sr, opt, widget=None): """Override subElementRect to use our own _tab_layout implementation. @@ -942,12 +909,12 @@ class TabBarStyle(QCommonStyle): # aligned properly. Otherwise, empty space will be shown after the # last tab even though the button width is set to 0 # - # Need to use super() because we also use super() to render + # Need to use QCommonStyle here because we also use it to render # element in drawControl(); otherwise, we may get bit by # style differences... - return super().subElementRect(sr, opt, widget) + return QCommonStyle.subElementRect(self, sr, opt, widget) else: - return self._style.subElementRect(sr, opt, widget) + return self.baseStyle().subElementRect(sr, opt, widget) def _tab_layout(self, opt): """Compute the text/icon rect from the opt rect. @@ -994,7 +961,7 @@ class TabBarStyle(QCommonStyle): text_rect.adjust( icon_rect.width() + TabBarStyle.ICON_PADDING, 0, 0, 0) - text_rect = self._style.visualRect(opt.direction, opt.rect, text_rect) + text_rect = self.baseStyle().visualRect(opt.direction, opt.rect, text_rect) return Layouts(text=text_rect, icon=icon_rect, indicator=indicator_rect) @@ -1029,5 +996,5 @@ class TabBarStyle(QCommonStyle): icon_top = text_rect.center().y() + 1 - tab_icon_size.height() // 2 icon_rect = QRect(QPoint(text_rect.left(), icon_top), tab_icon_size) - icon_rect = self._style.visualRect(opt.direction, opt.rect, icon_rect) + icon_rect = self.baseStyle().visualRect(opt.direction, opt.rect, icon_rect) return icon_rect diff --git a/qutebrowser/mainwindow/windowundo.py b/qutebrowser/mainwindow/windowundo.py index 0104a8187..80f47aaaa 100644 --- a/qutebrowser/mainwindow/windowundo.py +++ b/qutebrowser/mainwindow/windowundo.py @@ -83,9 +83,9 @@ class WindowUndoManager(QObject): private=False, geometry=entry.geometry, ) - window.show() window.tabbed_browser.undo_stack = entry.tab_stack window.tabbed_browser.undo() + window.show() def init(): diff --git a/qutebrowser/misc/quitter.py b/qutebrowser/misc/quitter.py index 3169e8bfa..a849aec70 100644 --- a/qutebrowser/misc/quitter.py +++ b/qutebrowser/misc/quitter.py @@ -221,21 +221,18 @@ class Quitter(QObject): status, session)) sessions.shutdown(session, last_window=last_window) - - if prompt.prompt_queue.shutdown(): - # If shutdown was called while we were asking a question, we're in - # a still sub-eventloop (which gets quit now) and not in the main - # one. - # This means we need to defer the real shutdown to when we're back - # in the real main event loop, or we'll get a segfault. - log.destroy.debug("Deferring real shutdown because question was " - "active.") - QTimer.singleShot(0, functools.partial(self._shutdown_2, status, - is_restart=is_restart)) - else: - # If we have no questions to shut down, we are already in the real - # event loop, so we can shut down immediately. - self._shutdown_2(status, is_restart=is_restart) + prompt.prompt_queue.shutdown() + + # If shutdown was called while we were asking a question, we're in + # a still sub-eventloop (which gets quit now) and not in the main + # one. + # But there's also other situations where it's problematic to shut down + # immediately (e.g. when we're just starting up). + # This means we need to defer the real shutdown to when we're back + # in the real main event loop, or we'll get a segfault. + log.destroy.debug("Deferring shutdown stage 2") + QTimer.singleShot( + 0, functools.partial(self._shutdown_2, status, is_restart=is_restart)) def _shutdown_2(self, status: int, is_restart: bool) -> None: """Second stage of shutdown.""" @@ -282,12 +279,10 @@ def quit_(save: bool = False, """ if session is not None and not save: raise cmdutils.CommandError("Session name given without --save!") - if save: - if session is None: - session = sessions.default - instance.shutdown(session=session) - else: - instance.shutdown() + if save and session is None: + session = sessions.default + + instance.shutdown(session=session) @cmdutils.register() diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py index bfb2d4347..53f7bf3d3 100644 --- a/qutebrowser/misc/sessions.py +++ b/qutebrowser/misc/sessions.py @@ -467,7 +467,6 @@ class SessionManager(QObject): """Turn yaml data into windows.""" window = mainwindow.MainWindow(geometry=win['geometry'], private=win.get('private', None)) - window.show() tabbed_browser = objreg.get('tabbed-browser', scope='window', window=window.win_id) tab_to_focus = None @@ -480,6 +479,8 @@ class SessionManager(QObject): new_tab.set_pinned(True) if tab_to_focus is not None: tabbed_browser.widget.setCurrentIndex(tab_to_focus) + + window.show() if win.get('active', False): QTimer.singleShot(0, tabbed_browser.widget.activateWindow) |