From: Hannah von Reth Date: Tue, 24 Mar 2020 11:01:04 +0000 (+0100) Subject: [Gui] Implement raiseDialog on Windows X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~123 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=bcceb5c33df936b91a823868d1b4ebc935b1e96a;p=nextcloud-desktop.git [Gui] Implement raiseDialog on Windows Issue: #7774 --- 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 } }