From bcceb5c33df936b91a823868d1b4ebc935b1e96a Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Tue, 24 Mar 2020 12:01:04 +0100 Subject: [PATCH] [Gui] Implement raiseDialog on Windows Issue: #7774 --- src/gui/owncloudgui.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index d650b96e4..c70c57bd7 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -614,6 +614,22 @@ void ownCloudGui::raiseDialog(QWidget *raiseWidget) False, // propagate SubstructureRedirectMask | SubstructureNotifyMask, &e); + +#elif defined(Q_OS_WIN) + // Windows disallows raising a Window when you're not the active application. + // Use a common hack to attach to the active application + const auto activeProcessId = GetWindowThreadProcessId(GetForegroundWindow(), nullptr); + if (activeProcessId != qApp->applicationPid()) { + const auto threadId = GetCurrentThreadId(); + // don't step here with a debugger... + if (AttachThreadInput(threadId, activeProcessId, true)) + { + const auto hwnd = reinterpret_cast(raiseWidget->winId()); + SetForegroundWindow(hwnd); + SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + AttachThreadInput(threadId, activeProcessId, false); + } + } #endif } } -- 2.30.2