Correct issues with hiding and minimizing the MainWindow

The GUI features depend on windowing system used, not just OS.

There is an issue with the WM sometimes producing an event that keepassxc interprets as request to hide the main window just after it is shown. A workaround with immediately firing a timer was implemented. However, there is no guarantee on execution ordering of the timer callback and other application code. Remove the timer and override
show() and hide() on main window to only hide if the window has not been shown recently.

The user can set an option to hide window instead of minimizing when tray icon is enabled. This is not honored in most places where the main windows is minimized. Fix it. This also allows using the tray icon as a workaround for minimization not working under some circumstances in X11.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
This commit is contained in:
Michal Suchanek 2020-02-24 12:33:43 +01:00 committed by Jonathan White
parent eb88b8cc0c
commit b9daed2055
7 changed files with 67 additions and 19 deletions

View file

@ -49,6 +49,7 @@
#include "gui/EntryPreviewWidget.h"
#include "gui/FileDialog.h"
#include "gui/KeePass1OpenWidget.h"
#include "gui/MainWindow.h"
#include "gui/MessageBox.h"
#include "gui/OpVaultOpenWidget.h"
#include "gui/TotpDialog.h"
@ -677,7 +678,7 @@ void DatabaseWidget::setClipboardTextAndMinimize(const QString& text)
clipboard()->setText(text);
if (config()->get("HideWindowOnCopy").toBool()) {
if (config()->get("MinimizeOnCopy").toBool()) {
window()->showMinimized();
getMainWindow()->minimizeOrHide();
} else if (config()->get("DropToBackgroundOnCopy").toBool()) {
window()->lower();
}
@ -782,7 +783,7 @@ void DatabaseWidget::openUrlForEntry(Entry* entry)
QProcess::startDetached(cmdString.mid(6));
if (config()->get("MinimizeOnOpenUrl").toBool()) {
window()->showMinimized();
getMainWindow()->minimizeOrHide();
}
}
} else {
@ -791,7 +792,7 @@ void DatabaseWidget::openUrlForEntry(Entry* entry)
QDesktopServices::openUrl(url);
if (config()->get("MinimizeOnOpenUrl").toBool()) {
window()->showMinimized();
getMainWindow()->minimizeOrHide();
}
}
}
@ -972,7 +973,7 @@ void DatabaseWidget::loadDatabase(bool accepted)
m_saveAttempts = 0;
emit databaseUnlocked();
if (config()->get("MinimizeAfterUnlock").toBool()) {
window()->showMinimized();
getMainWindow()->minimizeOrHide();
}
} else {
if (m_databaseOpenWidget->database()) {