diff --git a/Desktop/src/gui/application.cpp b/Desktop/src/gui/application.cpp index c19b6cff..25844be4 100644 --- a/Desktop/src/gui/application.cpp +++ b/Desktop/src/gui/application.cpp @@ -53,6 +53,7 @@ #include #include #include +#include using namespace Qt::Literals::StringLiterals; using namespace OCC; @@ -283,6 +284,9 @@ void Application::showSettings() ensureWindowIntersectsAvailableScreen(window); window->raise(); window->activateWindow(); + if (auto *windowHandle = window->windowHandle()) { + windowHandle->requestActivate(); + } #if defined(Q_OS_WIN) // Windows disallows raising a Window when you're not the active application. @@ -294,7 +298,9 @@ void Application::showSettings() foregroundThreadId != 0 && foregroundThreadId != currentThreadId && AttachThreadInput(currentThreadId, foregroundThreadId, true); const auto hwnd = reinterpret_cast(window->winId()); - ShowWindow(hwnd, SW_RESTORE); + ShowWindow(hwnd, IsIconic(hwnd) ? SW_RESTORE : SW_SHOW); + SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); + SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); SetForegroundWindow(hwnd); SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); diff --git a/Desktop/src/gui/systray.cpp b/Desktop/src/gui/systray.cpp index eab53e30..2df28697 100644 --- a/Desktop/src/gui/systray.cpp +++ b/Desktop/src/gui/systray.cpp @@ -24,17 +24,19 @@ #include #include #include -#include +#include using namespace Qt::Literals::StringLiterals; namespace OCC { namespace { + constexpr auto showSettingsAfterTrayEventDelay = 100; + void showSettingsAfterTrayEvent() { auto *app = ocApp(); - QMetaObject::invokeMethod(app, [app] { app->showSettings(); }, Qt::QueuedConnection); + QTimer::singleShot(showSettingsAfterTrayEventDelay, app, [app] { app->showSettings(); }); } }