diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index 788f5d32e..719683e7f 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -54,8 +54,7 @@ BrowserService::BrowserService(DatabaseTabWidget* parent) : m_dbTabWidget(parent) , m_dialogActive(false) , m_bringToFrontRequested(false) - , m_wasMinimized(false) - , m_wasHidden(false) + , m_prevWindowState(WindowState::Normal) , m_keepassBrowserUUID(Tools::hexToUuid("de887cc3036343b8974b5911b8816224")) { // Don't connect the signals when used from DatabaseSettingsWidgetBrowser (parent is nullptr) @@ -1009,29 +1008,42 @@ bool BrowserService::checkLegacySettings() void BrowserService::hideWindow() const { - if (m_wasMinimized) { + if (m_prevWindowState == WindowState::Minimized) { getMainWindow()->showMinimized(); } else { #ifdef Q_OS_MACOS - if (m_wasHidden) { + if (m_prevWindowState == WindowState::Hidden) { macUtils()->hideOwnWindow(); } else { macUtils()->raiseLastActiveWindow(); } #else - getMainWindow()->lower(); + if (m_prevWindowState == WindowState::Hidden) { + getMainWindow()->hideWindow(); + } else { + getMainWindow()->lower(); + } #endif } } void BrowserService::raiseWindow(const bool force) { - m_wasMinimized = getMainWindow()->isMinimized(); + m_prevWindowState = WindowState::Normal; + if (getMainWindow()->isMinimized()) { + m_prevWindowState = WindowState::Minimized; + } #ifdef Q_OS_MACOS - m_wasHidden = macUtils()->isHidden(); + if (macUtils()->isHidden()) { + m_prevWindowState = WindowState::Hidden; + } macUtils()->raiseOwnWindow(); Tools::wait(500); #else + if (getMainWindow()->isHidden()) { + m_prevWindowState = WindowState::Hidden; + } + if (force) { getMainWindow()->bringToFront(); } diff --git a/src/browser/BrowserService.h b/src/browser/BrowserService.h index 240fe232c..b002a9b9a 100644 --- a/src/browser/BrowserService.h +++ b/src/browser/BrowserService.h @@ -97,6 +97,13 @@ private: Allowed }; + enum WindowState + { + Normal, + Minimized, + Hidden + }; + private: QList sortEntries(QList& pwEntries, const QString& host, const QString& submitUrl); bool confirmEntries(QList& pwEntriesToConfirm, @@ -125,8 +132,7 @@ private: DatabaseTabWidget* const m_dbTabWidget; bool m_dialogActive; bool m_bringToFrontRequested; - bool m_wasMinimized; - bool m_wasHidden; + WindowState m_prevWindowState; QUuid m_keepassBrowserUUID; }; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index d7aa36e2c..b3a5a9aad 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1162,7 +1162,7 @@ void MainWindow::hideYubiKeyPopup() void MainWindow::bringToFront() { ensurePolished(); - setWindowState(windowState() & ~Qt::WindowMinimized); + setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); show(); raise(); activateWindow();