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.
This commit is contained in:
John Lindgren 2017-03-01 21:08:10 -05:00 committed by Jonathan White
parent 93c212f28d
commit ac0178d2c7
2 changed files with 16 additions and 10 deletions

View File

@ -301,7 +301,7 @@ MainWindow::MainWindow()
connect(m_ui->welcomeWidget, SIGNAL(importKeePass1Database()), SLOT(switchToKeePass1Database())); connect(m_ui->welcomeWidget, SIGNAL(importKeePass1Database()), SLOT(switchToKeePass1Database()));
connect(m_ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutDialog())); connect(m_ui->actionAbout, SIGNAL(triggered()), SLOT(showAboutDialog()));
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
setUnifiedTitleAndToolBarOnMac(true); setUnifiedTitleAndToolBarOnMac(true);
#endif #endif
@ -612,7 +612,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
if (minimizeOnClose && !appExitCalled) if (minimizeOnClose && !appExitCalled)
{ {
event->ignore(); event->ignore();
toggleWindow(); hideWindow();
if (config()->get("security/lockdatabaseminimize").toBool()) { if (config()->get("security/lockdatabaseminimize").toBool()) {
m_ui->tabWidget->lockDatabases(); 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() void MainWindow::toggleWindow()
{ {
if ((QApplication::activeWindow() == this) && isVisible() && !isMinimized()) { if ((QApplication::activeWindow() == this) && isVisible() && !isMinimized()) {
setWindowState(windowState() | Qt::WindowMinimized); hideWindow();
QTimer::singleShot(0, this, SLOT(hide()));
if (config()->get("security/lockdatabaseminimize").toBool()) {
m_ui->tabWidget->lockDatabases();
}
} else { } else {
ensurePolished(); ensurePolished();
setWindowState(windowState() & ~Qt::WindowMinimized); setWindowState(windowState() & ~Qt::WindowMinimized);
show(); show();
raise(); raise();
activateWindow(); activateWindow();
#if defined(Q_OS_LINUX) && ! defined(QT_NO_DBUS) #if defined(Q_OS_LINUX) && ! defined(QT_NO_DBUS)
// re-register global D-Bus menu (needed on Ubuntu with Unity) // re-register global D-Bus menu (needed on Ubuntu with Unity)
// see https://github.com/keepassxreboot/keepassxc/issues/271 // see https://github.com/keepassxreboot/keepassxc/issues/271
@ -832,7 +837,7 @@ void MainWindow::repairDatabase()
if (fileName.isEmpty()) { if (fileName.isEmpty()) {
return; return;
} }
QScopedPointer<QDialog> dialog(new QDialog(this)); QScopedPointer<QDialog> dialog(new QDialog(this));
DatabaseRepairWidget* dbRepairWidget = new DatabaseRepairWidget(dialog.data()); DatabaseRepairWidget* dbRepairWidget = new DatabaseRepairWidget(dialog.data());
connect(dbRepairWidget, SIGNAL(success()), dialog.data(), SLOT(accept())); connect(dbRepairWidget, SIGNAL(success()), dialog.data(), SLOT(accept()));

View File

@ -72,6 +72,7 @@ private Q_SLOTS:
void rememberOpenDatabases(const QString& filePath); void rememberOpenDatabases(const QString& filePath);
void applySettingsChanges(); void applySettingsChanges();
void trayIconTriggered(QSystemTrayIcon::ActivationReason reason); void trayIconTriggered(QSystemTrayIcon::ActivationReason reason);
void hideWindow();
void toggleWindow(); void toggleWindow();
void lockDatabasesAfterInactivity(); void lockDatabasesAfterInactivity();
void repairDatabase(); void repairDatabase();