aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/raise.go
diff options
context:
space:
mode:
Diffstat (limited to 'ui/raise.go')
-rw-r--r--ui/raise.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/ui/raise.go b/ui/raise.go
index b74b5ed6..42509994 100644
--- a/ui/raise.go
+++ b/ui/raise.go
@@ -20,19 +20,33 @@ func raise(hwnd win.HWND) {
}
win.SetActiveWindow(hwnd)
-
win.SetWindowPos(hwnd, win.HWND_TOPMOST, 0, 0, 0, 0, win.SWP_NOMOVE|win.SWP_NOSIZE|win.SWP_SHOWWINDOW)
win.SetForegroundWindow(hwnd)
win.SetWindowPos(hwnd, win.HWND_NOTOPMOST, 0, 0, 0, 0, win.SWP_NOMOVE|win.SWP_NOSIZE|win.SWP_SHOWWINDOW)
}
+func raiseRemote(hwnd win.HWND) {
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+ win.SendMessage(hwnd, raiseMsg, 0, 0)
+ currentForegroundHwnd := win.GetForegroundWindow()
+ currentForegroundThreadId := win.GetWindowThreadProcessId(currentForegroundHwnd, nil)
+ currentThreadId := win.GetCurrentThreadId()
+ win.AttachThreadInput(int32(currentForegroundThreadId), int32(currentThreadId), true)
+ win.SetWindowPos(hwnd, win.HWND_TOPMOST, 0, 0, 0, 0, win.SWP_NOMOVE|win.SWP_NOSIZE|win.SWP_SHOWWINDOW)
+ win.SetWindowPos(hwnd, win.HWND_NOTOPMOST, 0, 0, 0, 0, win.SWP_NOMOVE|win.SWP_NOSIZE|win.SWP_SHOWWINDOW)
+ win.SetForegroundWindow(hwnd)
+ win.AttachThreadInput(int32(currentForegroundThreadId), int32(currentThreadId), false)
+ win.SetFocus(hwnd)
+ win.SetActiveWindow(hwnd)
+}
+
func RaiseUI() bool {
hwnd := win.FindWindow(windows.StringToUTF16Ptr(manageWindowWindowClass), nil)
if hwnd == 0 {
return false
}
- win.SendMessage(hwnd, raiseMsg, 0, 0)
- win.SetForegroundWindow(hwnd)
+ raiseRemote(hwnd)
return true
}
@@ -47,8 +61,7 @@ func WaitForRaiseUIThenQuit() {
return 0
}
win.UnhookWinEvent(handle)
- win.SendMessage(hwnd, raiseMsg, 0, 0)
- win.SetForegroundWindow(hwnd)
+ raiseRemote(hwnd)
os.Exit(0)
return 0
}, 0, 0, win.WINEVENT_SKIPOWNPROCESS|win.WINEVENT_OUTOFCONTEXT)