From 53ff9f5a0cc68bdef348b585120914476a9df848 Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Sun, 21 Feb 2021 09:59:01 +1100 Subject: Fix window geometry/state not being saved in some environments The window state and geometry are now saved either after app.exec() finished, or if closeEvent is emitted on the MainWindow. This allows the window geometry/state restoration to be a lot more reliable. E.g in my configuration (Fluxbox) - if I closed the window using my own defined keybinding, the state would not get saved --- src/main.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index d54ae22..f969834 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,7 @@ QString toFingerprintString(QSslCertificate const & certificate) static QSettings * app_settings_ptr; static QApplication * app; static MainWindow * main_window = nullptr; +static bool closing_state_saved = false; #define SSTR(X) STR(X) #define STR(X) #X @@ -317,12 +318,8 @@ int main(int argc, char *argv[]) int exit_code = app.exec(); - app_settings.beginGroup("Window State"); - app_settings.setValue("geometry", w.saveGeometry()); - app_settings.setValue("state", w.saveState()); - app_settings.endGroup(); - - kristall::saveSettings(); + if (!closing_state_saved) + kristall::saveWindowState(); return exit_code; } @@ -561,3 +558,15 @@ void kristall::setUiDensity(UIDensity density, bool previewing) assert(main_window != nullptr); main_window->setUiDensity(density, previewing); } + +void kristall::saveWindowState() +{ + closing_state_saved = true; + + app_settings_ptr->beginGroup("Window State"); + app_settings_ptr->setValue("geometry", main_window->saveGeometry()); + app_settings_ptr->setValue("state", main_window->saveState()); + app_settings_ptr->endGroup(); + + kristall::saveSettings(); +} -- cgit v1.2.3