Skip to content

Truly independent web browser

UI/Qt: Leave a quit’s window activations out of the restore order

sideshowbarkerf8f6d1d07628
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index bbb23671562..3db88d05351 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -1095,6 +1095,11 @@ void Application::cancel_quit()
if (auto* window = as_if<BrowserWindow>(widget))
window->cancel_window_close_preflight();
}
+
+ // No activation was reported during the quit, and the window the quit left active gets no new WindowActivate while
+ // it stays active, so it's reported here as the most recent window.
+ if (m_active_window && m_active_window->isActiveWindow())
+ m_active_window->report_activation_to_session_store();
}
bool Application::confirm_stop_active_downloads(QWidget* parent)
diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h
index d7552c7b3ba..902e8db53e4 100644
--- a/UI/Qt/Application.h
+++ b/UI/Qt/Application.h
@@ -69,6 +69,7 @@ public:
// Asks every window's pages if they may unload, one window at a time. Once all of them agree, it confirms stopping
// the downloads and quits; if a page refuses or the downloads are kept, the quit is canceled and no window closes.
void quit();
+ bool is_quit_in_progress() const { return m_quit_in_progress; }
bool is_finishing_quit() const { return m_quit_is_finishing; }
bool confirm_stop_active_downloads(QWidget* parent = nullptr);
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index 4547154096a..e363a986022 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -1355,8 +1355,9 @@ bool BrowserWindow::event(QEvent* event)
if (event->type() == QEvent::WindowActivate) {
Application::the().set_active_window(*this);
WebView::Application::the().update_actions_for_active_web_view();
- if (m_session_window_id.has_value())
- m_session->session_store->window_activated(*m_session_window_id);
+ // A quit raises and closes windows in its own order, so the restore order keeps how they were used before it.
+ if (!Application::the().is_quit_in_progress())
+ report_activation_to_session_store();
QTimer::singleShot(0, this, [this] {
refresh_resize_cursor_at_current_position(true);
Application::the().crash_report_notifier().show_pending();
@@ -1789,6 +1790,12 @@ void BrowserWindow::raise_for_close_prompt()
activateWindow();
}
+void BrowserWindow::report_activation_to_session_store()
+{
+ if (m_session_window_id.has_value())
+ m_session->session_store->window_activated(*m_session_window_id);
+}
+
void BrowserWindow::begin_window_close_preflight(Function<void(bool approved)> on_complete)
{
m_window_close_active_tab_index = static_cast<i64>(max(m_tabs_container->current_index(), 0));
diff --git a/UI/Qt/BrowserWindow.h b/UI/Qt/BrowserWindow.h
index b0984896fd2..bfbd7013389 100644
--- a/UI/Qt/BrowserWindow.h
+++ b/UI/Qt/BrowserWindow.h
@@ -172,6 +172,7 @@ public:
// Brings the window forward for a page's beforeunload prompt during an application-wide close check.
void raise_for_close_prompt();
bool is_window_close_approved() const { return m_window_close_approved; }
+ void report_activation_to_session_store();
void cancel_window_close_preflight();
void on_tab_load_start(Tab&);
FullscreenMode& fullscreen_mode();