From 4da684b95ca9b1f80b72d33d57bf52d9802ec3d7 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 --- changelog/unreleased/7774 | 5 +++++ src/gui/owncloudgui.cpp | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 changelog/unreleased/7774 diff --git a/changelog/unreleased/7774 b/changelog/unreleased/7774 new file mode 100644 index 0000000000..e69e81b037 --- /dev/null +++ b/changelog/unreleased/7774 @@ -0,0 +1,5 @@ +Bugfix: On Windows the share dialog somtimes does not open as the top most window + +We now ensure that the our dialogs are correctly raised. + +https://github.com/owncloud/client/issues/7774 diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 7516c8ed88..46763415a8 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -1088,6 +1088,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 } }