Skip to content

Commit

Permalink
[Gui] Implement raiseDialog on Windows
Browse files Browse the repository at this point in the history
Issue: #7774
  • Loading branch information
TheOneRing committed Mar 25, 2020
1 parent 56a25ed commit 4da684b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/7774
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<HWND>(raiseWidget->winId());
SetForegroundWindow(hwnd);
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
AttachThreadInput(threadId, activeProcessId, false);
}
}
#endif
}
}
Expand Down

0 comments on commit 4da684b

Please sign in to comment.