From ac0178d2c7a397cfb0d5be66fecec94ed8b1085d Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 1 Mar 2017 21:08:10 -0500 Subject: [PATCH] closeEvent() should always hide the window, never raise it. This fixes an issue on X11 where Alt-F4 would not close the window, due to toggleWindow() believing the window is inactive and trying to raise it. Avoid the problem by closing the window unconditionally. --- src/gui/MainWindow.cpp | 25 +++++++++++++++---------- src/gui/MainWindow.h | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index f263a0014..763ada1ae 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -301,7 +301,7 @@ MainWindow::MainWindow() connect(m_ui->welcomeWidget, SIGNAL(importKeePass1Database()), SLOT(switchToKeePass1Database())); connect(m_ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutDialog())); - + #ifdef Q_OS_MAC setUnifiedTitleAndToolBarOnMac(true); #endif @@ -612,7 +612,7 @@ void MainWindow::closeEvent(QCloseEvent* event) if (minimizeOnClose && !appExitCalled) { event->ignore(); - toggleWindow(); + hideWindow(); if (config()->get("security/lockdatabaseminimize").toBool()) { m_ui->tabWidget->lockDatabases(); @@ -777,22 +777,27 @@ void MainWindow::trayIconTriggered(QSystemTrayIcon::ActivationReason reason) } } +void MainWindow::hideWindow() +{ + setWindowState(windowState() | Qt::WindowMinimized); + QTimer::singleShot(0, this, SLOT(hide())); + + if (config()->get("security/lockdatabaseminimize").toBool()) { + m_ui->tabWidget->lockDatabases(); + } +} + void MainWindow::toggleWindow() { if ((QApplication::activeWindow() == this) && isVisible() && !isMinimized()) { - setWindowState(windowState() | Qt::WindowMinimized); - QTimer::singleShot(0, this, SLOT(hide())); - - if (config()->get("security/lockdatabaseminimize").toBool()) { - m_ui->tabWidget->lockDatabases(); - } + hideWindow(); } else { ensurePolished(); setWindowState(windowState() & ~Qt::WindowMinimized); show(); raise(); activateWindow(); - + #if defined(Q_OS_LINUX) && ! defined(QT_NO_DBUS) // re-register global D-Bus menu (needed on Ubuntu with Unity) // see https://github.com/keepassxreboot/keepassxc/issues/271 @@ -832,7 +837,7 @@ void MainWindow::repairDatabase() if (fileName.isEmpty()) { return; } - + QScopedPointer dialog(new QDialog(this)); DatabaseRepairWidget* dbRepairWidget = new DatabaseRepairWidget(dialog.data()); connect(dbRepairWidget, SIGNAL(success()), dialog.data(), SLOT(accept())); diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 694b38e7a..5c7ccad8e 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -72,6 +72,7 @@ private Q_SLOTS: void rememberOpenDatabases(const QString& filePath); void applySettingsChanges(); void trayIconTriggered(QSystemTrayIcon::ActivationReason reason); + void hideWindow(); void toggleWindow(); void lockDatabasesAfterInactivity(); void repairDatabase();