diff --git a/src/duckstation-qt/logwindow.cpp b/src/duckstation-qt/logwindow.cpp index c81d4508c..b286a226c 100644 --- a/src/duckstation-qt/logwindow.cpp +++ b/src/duckstation-qt/logwindow.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #include "logwindow.h" @@ -216,7 +216,7 @@ LogWindow::LogWindow(bool attach_to_main) : QMainWindow(), m_attached_to_main_wi LogWindow::~LogWindow() = default; -void LogWindow::updateSettings() +void LogWindow::updateSettings(bool defer_show) { const bool new_enabled = Core::GetBoolSettingValue("Logging", "LogToWindow", false); const bool attach_to_main = Core::GetBoolSettingValue("Logging", "AttachLogWindowToMainWindow", true); @@ -236,10 +236,8 @@ void LogWindow::updateSettings() if (new_enabled) { g_log_window = new LogWindow(attach_to_main); - if (attach_to_main && g_main_window && g_main_window->isVisible()) - g_log_window->reattachToMainWindow(); - - g_log_window->show(); + if (!defer_show) + g_log_window->deferredShow(); } else if (g_log_window) { @@ -274,6 +272,21 @@ void LogWindow::reattachToMainWindow() move(new_pos); } +bool LogWindow::deferredShow() +{ + if (!g_log_window) + return false; + + if (g_log_window->isVisible()) + return true; + + if (g_log_window->m_attached_to_main_window && g_main_window->isVisible()) + g_log_window->reattachToMainWindow(); + + g_log_window->show(); + return true; +} + void LogWindow::updateWindowTitle() { QString title; diff --git a/src/duckstation-qt/logwindow.h b/src/duckstation-qt/logwindow.h index 5cf30b7db..08bb99250 100644 --- a/src/duckstation-qt/logwindow.h +++ b/src/duckstation-qt/logwindow.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #pragma once @@ -48,7 +48,8 @@ public: LogWindow(bool attach_to_main); ~LogWindow(); - static void updateSettings(); + static void updateSettings(bool defer_show); + static bool deferredShow(); static void destroy(); ALWAYS_INLINE bool isAttachedToMainWindow() const { return m_attached_to_main_window; } diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 00ad04d9a..3b521df82 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -788,7 +788,7 @@ void MainWindow::recreate() new_main_window->setGeometry(geometry()); // Recreate log window as well. Then make sure we're still on top. - LogWindow::updateSettings(); + LogWindow::updateSettings(true); // Qt+XCB will ignore the raise request of the settings window if we raise the main window. // So skip that if we're going to be re-opening the settings window. @@ -797,6 +797,8 @@ void MainWindow::recreate() else new_main_window->show(); + LogWindow::deferredShow(); + if (was_display_created) { g_core_thread->recreateRenderWindow(); @@ -828,6 +830,10 @@ void MainWindow::recreate() dlg->setCategoryRow(settings_window_row); QtUtils::ShowOrRaiseWindow(dlg); } + else + { + QtUtils::RaiseWindow(new_main_window); + } notifyRAIntegrationOfWindowChange(); } @@ -3077,7 +3083,7 @@ void MainWindow::checkForSettingChanges() updateLogWidget(); } - LogWindow::updateSettings(); + LogWindow::updateSettings(false); // don't refresh window state while setup wizard is running, i.e. no game and hidden if (isVisible() || s_locals.system_valid || s_locals.system_starting) diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 93a63452e..9166fc89d 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #include "qthost.h" @@ -166,7 +166,7 @@ struct State bool cleanup_after_update = false; #ifdef __linux__ - bool display_container_needed = false; + bool wayland_workarounds = false; #endif }; } // namespace @@ -319,7 +319,7 @@ bool QtHost::InNoGUIMode() bool QtHost::IsDisplayWidgetContainerNeeded() { #ifdef __linux__ - return s_state.display_container_needed; + return s_state.wayland_workarounds; #else return false; #endif @@ -372,7 +372,7 @@ void QtHost::ApplyWaylandWorkarounds() // When rendering fullscreen or to a separate window on Wayland, because we take over the surface we need // to wrap the widget in a container because GNOME is stupid and refuses to ever support server-side // decorations. There's no sign of this ever changing. Fuck Wayland. - s_state.display_container_needed = true; + s_state.wayland_workarounds = true; // On Wayland, turning any window into a native window causes DPI scaling to break, as well as window // updates, creating a complete mess of a window. Setting this attribute isn't ideal, since you'd think @@ -3324,14 +3324,18 @@ int main(int argc, char* argv[]) // Build warning. AutoUpdaterDialog::warnAboutUnofficialBuild(); - // Start logging early. - LogWindow::updateSettings(); - // Create core thread object, but don't start it yet. That way the main window can connect to it, // and ensures that no signals are lost. Then we create and connect the main window. g_core_thread = new CoreThread(); + + // Make sure the main window is the first window created. new MainWindow(); + // Start logging early, but don't show the window yet. + // We want to catch the early messages, but if the window is shown the Windows taskbar will use + // the log window icon as the application icon because it's the first window shown. + LogWindow::updateSettings(true); + // Now we can actually start the CPU thread. QtHost::HookSignals(); g_core_thread->start(); @@ -3348,6 +3352,22 @@ int main(int argc, char* argv[]) if (!s_state.batch_mode) g_main_window->refreshGameList(false); +#ifdef __linux__ + // I hate this so much. Because GNOME are arrogant uncooperative assholes who refuse to let applications + // raise their own windows, we have to show the log window before the main window, otherwise the main + // window will appear behind the log window. And it'll block it, because we're not allowed to attach it + // to the main window by setting its position either. + if (s_state.wayland_workarounds) + { + LogWindow::deferredShow(); + + // And of course this turd of a desktop environment can't even open windows in order. + // Force it to be displayed. This is completely fucking ridiculous. + QApplication::sync(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); + } +#endif + // Don't bother showing the window in no-gui mode. if (!s_state.nogui_mode) QtUtils::ShowOrRaiseWindow(g_main_window, nullptr, true); @@ -3364,6 +3384,10 @@ int main(int argc, char* argv[]) if (autoboot) g_core_thread->bootSystem(std::move(autoboot)); + // Bring the log window up last, so that its icon does not take precedence. + if (LogWindow::deferredShow()) + QtUtils::RaiseWindow(g_main_window); + // This doesn't return until we exit. result = app.exec(); diff --git a/src/duckstation-qt/qtutils.cpp b/src/duckstation-qt/qtutils.cpp index cde7ef9fb..3d3470a44 100644 --- a/src/duckstation-qt/qtutils.cpp +++ b/src/duckstation-qt/qtutils.cpp @@ -88,6 +88,16 @@ void QtUtils::ShowOrRaiseWindow(QWidget* window, const QWidget* parent_window, b } } +void QtUtils::RaiseWindow(QWidget* window) +{ + if (!window->isVisible()) + return; + + window->raise(); + window->activateWindow(); + window->setFocus(); +} + template static void SetColumnWidthForView(T* const view, QHeaderView* const header, const std::initializer_list& widths) { diff --git a/src/duckstation-qt/qtutils.h b/src/duckstation-qt/qtutils.h index ae8b30990..4ae6073f7 100644 --- a/src/duckstation-qt/qtutils.h +++ b/src/duckstation-qt/qtutils.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #pragma once @@ -51,6 +51,10 @@ QFrame* CreateHorizontalLine(QWidget* parent); /// If the window was hidden and parent_window is provided, the window is centered on parent_window. void ShowOrRaiseWindow(QWidget* window, const QWidget* parent_window = nullptr, bool restore_geometry = false); +/// Raises a window (brings it to the front) iff the window is already visible. +/// Does not work on GNOME because they're fucking stupid. +void RaiseWindow(QWidget* window); + /// Closes and deletes a window later, outside of this event pump. template inline void CloseAndDeleteWindow(T*& window)