diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-02-21 09:59:01 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-02-23 11:31:33 +0100 |
| commit | 53ff9f5a0cc68bdef348b585120914476a9df848 (patch) | |
| tree | d9eaa3ff36d82fffbe82b9d6488e6b95166dad7c /src/main.cpp | |
| parent | 3170b38373f19eb1f1d0712c682cb170a1b10ceb (diff) | |
| download | kristall-53ff9f5a0cc68bdef348b585120914476a9df848.tar.gz | |
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
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
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(); +} |
