From 724aa657f32f31f1cb3c1d9fae7cbe4e290d5d04 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 18 Feb 2023 13:19:25 +1000 Subject: [PATCH] Qt: Fix window geometry not saving on exit --- pcsx2-qt/MainWindow.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/pcsx2-qt/MainWindow.cpp b/pcsx2-qt/MainWindow.cpp index ee8aaeac2f..e847e9fb97 100644 --- a/pcsx2-qt/MainWindow.cpp +++ b/pcsx2-qt/MainWindow.cpp @@ -983,27 +983,28 @@ void MainWindow::saveStateToConfig() if (!isVisible()) return; + bool changed = false; + + const QByteArray geometry(saveGeometry()); + const QByteArray geometry_b64(geometry.toBase64()); + const std::string old_geometry_b64(Host::GetBaseStringSettingValue("UI", "MainWindowGeometry")); + if (old_geometry_b64 != geometry_b64.constData()) { - const QByteArray geometry = saveGeometry(); - const QByteArray geometry_b64 = geometry.toBase64(); - const std::string old_geometry_b64 = Host::GetBaseStringSettingValue("UI", "MainWindowGeometry"); - if (old_geometry_b64 != geometry_b64.constData()) - { - Host::SetBaseStringSettingValue("UI", "MainWindowGeometry", geometry_b64.constData()); - Host::CommitBaseSettingChanges(); - } + Host::SetBaseStringSettingValue("UI", "MainWindowGeometry", geometry_b64.constData()); + changed = true; } + const QByteArray state(saveState()); + const QByteArray state_b64(state.toBase64()); + const std::string old_state_b64(Host::GetBaseStringSettingValue("UI", "MainWindowState")); + if (old_state_b64 != state_b64.constData()) { - const QByteArray state = saveState(); - const QByteArray state_b64 = state.toBase64(); - const std::string old_state_b64 = Host::GetBaseStringSettingValue("UI", "MainWindowState"); - if (old_state_b64 != state_b64.constData()) - { - Host::SetBaseStringSettingValue("UI", "MainWindowState", state_b64.constData()); - Host::CommitBaseSettingChanges(); - } + Host::SetBaseStringSettingValue("UI", "MainWindowState", state_b64.constData()); + changed = true; } + + if (changed) + Host::CommitBaseSettingChanges(); } void MainWindow::restoreStateFromConfig() @@ -1979,6 +1980,7 @@ void MainWindow::closeEvent(QCloseEvent* event) // If there's no VM, we can just exit as normal. if (!s_vm_valid) { + saveStateToConfig(); QMainWindow::closeEvent(event); return; } @@ -1992,7 +1994,6 @@ void MainWindow::closeEvent(QCloseEvent* event) return; // Application will be exited in VM stopped handler. - saveStateToConfig(); m_is_closing = true; }