From 5cc77ac1863533aa56d48bd91022cf23083edff4 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 15 Sep 2026 23:44:44 +1000 Subject: [PATCH] Qt: Persist debugger window state --- src/duckstation-qt/debuggerwindow.cpp | 25 ++++++++++++++++++++++++- src/duckstation-qt/debuggerwindow.h | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/duckstation-qt/debuggerwindow.cpp b/src/duckstation-qt/debuggerwindow.cpp index abfb6569b..01070decb 100644 --- a/src/duckstation-qt/debuggerwindow.cpp +++ b/src/duckstation-qt/debuggerwindow.cpp @@ -8,6 +8,7 @@ #include "qtutils.h" #include "core/bus.h" +#include "core/core.h" #include "core/cpu_code_cache.h" #include "core/cpu_core_private.h" #include "core/cpu_disasm.h" @@ -45,12 +46,15 @@ LOG_CHANNEL(Host); static constexpr int TIMER_REFRESH_INTERVAL_MS = 100; static constexpr const char* BREAKPOINTS_SECTION = "Breakpoints"; +static constexpr const char* WINDOW_STATE_SECTION = "UI"; +static constexpr const char* WINDOW_STATE_KEY = "DebuggerWindowState"; DebuggerWindow::DebuggerWindow(QWidget* parent /* = nullptr */) : QMainWindow(parent), m_active_memory_region(Bus::MemoryRegion::Count) { m_ui.setupUi(this); setupAdditionalUi(); + restoreWindowState(); connectSignals(); createModels(); setMemoryViewRegion(Bus::MemoryRegion::RAM); @@ -65,7 +69,9 @@ DebuggerWindow::DebuggerWindow(QWidget* parent /* = nullptr */) onSystemStarted(); } else + { onSystemDestroyed(); + } } DebuggerWindow::~DebuggerWindow() = default; @@ -674,12 +680,29 @@ void DebuggerWindow::closeEvent(QCloseEvent* event) { g_core_thread->disconnect(this); Host::RunOnCoreThread([]() { CPU::ClearBreakpoints(true, false); }); - QtUtils::SaveWindowGeometry(this); + saveWindowState(); saveGameSettings(); QMainWindow::closeEvent(event); emit closed(); } +void DebuggerWindow::saveWindowState() +{ + QtUtils::SaveWindowGeometry(this, false); + + const QByteArray state = QMainWindow::saveState().toBase64(); + Core::SetBaseStringSettingValue(WINDOW_STATE_SECTION, WINDOW_STATE_KEY, state.constData()); + Host::CommitBaseSettingChanges(); +} + +void DebuggerWindow::restoreWindowState() +{ + // NOTE: Geometry restored in QtUtils::ShowOrRaiseWindow(). + const std::string state = Core::GetBaseStringSettingValue(WINDOW_STATE_SECTION, WINDOW_STATE_KEY); + if (!state.empty()) + QMainWindow::restoreState(QByteArray::fromBase64(QByteArray::fromStdString(state))); +} + void DebuggerWindow::setupAdditionalUi() { const QFont& fixed_font = QtHost::GetFixedFont(); diff --git a/src/duckstation-qt/debuggerwindow.h b/src/duckstation-qt/debuggerwindow.h index a1c5cca37..49b9f443f 100644 --- a/src/duckstation-qt/debuggerwindow.h +++ b/src/duckstation-qt/debuggerwindow.h @@ -42,6 +42,8 @@ protected: void closeEvent(QCloseEvent* event) override; private: + void saveWindowState(); + void restoreWindowState(); void setupAdditionalUi(); void connectSignals(); void createModels();