From 72de3cf9ca9bca925f788588bf4c12b9c3a68dc8 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Tue, 11 Jun 2019 18:25:17 -0400 Subject: [PATCH] Fix clicking tray icon to toggle window on Linux (#3258) KDE does not take focus from the current active window when the tray icon is clicked. This prevented toggling the window (always called bringToFront). Checking if the window is active corrects this issue. Fixes #3256, fixes #3214. --- src/gui/MainWindow.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 8d187bc29..7ee6aadea 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "config-keepassx.h" @@ -1088,9 +1089,16 @@ void MainWindow::processTrayIconTrigger() toggleWindow(); } else if (m_trayIconTriggerReason == QSystemTrayIcon::Trigger || m_trayIconTriggerReason == QSystemTrayIcon::MiddleClick) { - // On single/middle click focus the window if it is not hidden - // and did not have focus less than a second ago, otherwise toggle - if (isHidden() || (Clock::currentSecondsSinceEpoch() - m_lastFocusOutTime) <= 1) { + // Toggle window if hidden + // If on windows, check if focus switched within the last second because + // clicking the tray icon removes focus from main window + // If on Linux or macOS, check if the window is active + if (isHidden() +#ifdef Q_OS_WIN + || (Clock::currentSecondsSinceEpoch() - m_lastFocusOutTime) <= 1) { +#else + || windowHandle()->isActive()) { +#endif toggleWindow(); } else { bringToFront();