summaryrefslogtreecommitdiff
path: root/qutebrowser/mainwindow/mainwindow.py
diff options
context:
space:
mode:
Diffstat (limited to 'qutebrowser/mainwindow/mainwindow.py')
-rw-r--r--qutebrowser/mainwindow/mainwindow.py32
1 files changed, 19 insertions, 13 deletions
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: