Ignore double close event on macOS, resolves #430

This commit is contained in:
Janek Bevendorff 2017-05-17 10:05:45 +02:00
parent c69a978589
commit 00dc4b9ace
No known key found for this signature in database
GPG Key ID: CFEC2F6850BFFA53
2 changed files with 14 additions and 5 deletions

View File

@ -103,9 +103,9 @@ const QString MainWindow::BaseWindowTitle = "KeePassXC";
MainWindow::MainWindow() MainWindow::MainWindow()
: m_ui(new Ui::MainWindow()) : m_ui(new Ui::MainWindow())
, m_trayIcon(nullptr) , m_trayIcon(nullptr)
, m_appExitCalled(false)
, m_appExiting(false)
{ {
appExitCalled = false;
m_ui->setupUi(this); m_ui->setupUi(this);
// Setup the search widget in the toolbar // Setup the search widget in the toolbar
@ -347,7 +347,7 @@ MainWindow::~MainWindow()
void MainWindow::appExit() void MainWindow::appExit()
{ {
appExitCalled = true; m_appExitCalled = true;
close(); close();
} }
@ -663,9 +663,15 @@ void MainWindow::databaseTabChanged(int tabIndex)
void MainWindow::closeEvent(QCloseEvent* event) void MainWindow::closeEvent(QCloseEvent* event)
{ {
// ignore double close events (happens on macOS when closing from the dock)
if (m_appExiting) {
event->accept();
return;
}
bool minimizeOnClose = isTrayIconEnabled() && bool minimizeOnClose = isTrayIconEnabled() &&
config()->get("GUI/MinimizeOnClose").toBool(); config()->get("GUI/MinimizeOnClose").toBool();
if (minimizeOnClose && !appExitCalled) if (minimizeOnClose && !m_appExitCalled)
{ {
event->ignore(); event->ignore();
hideWindow(); hideWindow();
@ -680,6 +686,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
bool accept = saveLastDatabases(); bool accept = saveLastDatabases();
if (accept) { if (accept) {
m_appExiting = true;
saveWindowInformation(); saveWindowInformation();
event->accept(); event->accept();

View File

@ -40,6 +40,7 @@ class MainWindow : public QMainWindow
public: public:
MainWindow(); MainWindow();
~MainWindow(); ~MainWindow();
enum StackedWidgetIndex enum StackedWidgetIndex
{ {
DatabaseTabScreen = 0, DatabaseTabScreen = 0,
@ -118,7 +119,8 @@ private:
Q_DISABLE_COPY(MainWindow) Q_DISABLE_COPY(MainWindow)
bool appExitCalled; bool m_appExitCalled;
bool m_appExiting;
}; };
#define KEEPASSXC_MAIN_WINDOW (qobject_cast<Application*>(qApp) ? \ #define KEEPASSXC_MAIN_WINDOW (qobject_cast<Application*>(qApp) ? \