aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Skec <skec@protonmail.ch>2021-02-21 09:59:01 +1100
committerFelix Queißner <felix@ib-queissner.de>2021-02-23 11:31:33 +0100
commit53ff9f5a0cc68bdef348b585120914476a9df848 (patch)
treed9eaa3ff36d82fffbe82b9d6488e6b95166dad7c /src
parent3170b38373f19eb1f1d0712c682cb170a1b10ceb (diff)
downloadkristall-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')
-rw-r--r--src/kristall.hpp2
-rw-r--r--src/main.cpp21
-rw-r--r--src/mainwindow.cpp7
-rw-r--r--src/mainwindow.hpp2
4 files changed, 26 insertions, 6 deletions
diff --git a/src/kristall.hpp b/src/kristall.hpp
index b692e75..8ae8cb2 100644
--- a/src/kristall.hpp
+++ b/src/kristall.hpp
@@ -152,6 +152,8 @@ namespace kristall
void setUiDensity(UIDensity density, bool previewing);
+ void saveWindowState();
+
extern QString default_font_family, default_font_family_fixed;
}
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();
+}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 64f5fab..8594f7a 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -296,6 +296,13 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
}
}
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ kristall::saveWindowState();
+
+ event->accept();
+}
+
void MainWindow::on_browser_tabs_currentChanged(int index)
{
if(index >= 0) {
diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp
index a252daa..7113587 100644
--- a/src/mainwindow.hpp
+++ b/src/mainwindow.hpp
@@ -47,6 +47,8 @@ public:
void mousePressEvent(QMouseEvent *event) override;
+ void closeEvent(QCloseEvent *event) override;
+
private slots:
void on_browser_tabs_currentChanged(int index);