[Gui] Implement raiseDialog on Windows
authorHannah von Reth <hannah.vonreth@owncloud.com>
Tue, 24 Mar 2020 11:01:04 +0000 (12:01 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:09 +0000 (10:59 +0100)
Issue: #7774

src/gui/owncloudgui.cpp

index d650b96e48f3d3dc52dec8911b0424d713003e65..c70c57bd7ffb1af790f74eca991c72223ed59ad2 100644 (file)
@@ -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<HWND>(raiseWidget->winId());
+                SetForegroundWindow(hwnd);
+                SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+                AttachThreadInput(threadId, activeProcessId, false);
+            }
+        }
 #endif
     }
 }