From 219d124b5000b39d90482f575b6ceb838c037ebc Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sun, 18 Nov 2018 20:50:25 +0100 Subject: [PATCH] qa: Simplify main window activation logic Remove code duplication, avoid a warning about unreachable code. --- src/uisupport/graphicalui.cpp | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/uisupport/graphicalui.cpp b/src/uisupport/graphicalui.cpp index 73affbf7..33b0d87b 100644 --- a/src/uisupport/graphicalui.cpp +++ b/src/uisupport/graphicalui.cpp @@ -144,38 +144,26 @@ bool GraphicalUi::eventFilter(QObject* obj, QEvent* event) bool GraphicalUi::checkMainWidgetVisibility(bool perform) { + bool needsActivation{true}; + #ifdef Q_OS_WIN // the problem is that we lose focus when the systray icon is activated // and we don't know the former active window // therefore we watch for activation event and use our stopwatch :) if (GetTickCount() - _dwTickCount < 300) { // we were active in the last 300ms -> hide it - if (perform) - minimizeRestore(false); - return false; - } - else { - if (perform) - minimizeRestore(true); - return true; + needsActivation = false; } - #else - - if (!mainWidget()->isVisible() || mainWidget()->isMinimized() || !mainWidget()->isActiveWindow()) { - if (perform) - minimizeRestore(true); - return true; + if (mainWidget()->isVisible() && !mainWidget()->isMinimized() && mainWidget()->isActiveWindow()) { + needsActivation = false; } - else { - if (perform) - minimizeRestore(false); - return false; - } - #endif - return true; + if (perform) { + minimizeRestore(needsActivation); + } + return needsActivation; } bool GraphicalUi::isMainWidgetVisible() -- 2.20.1