aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-08-05 09:49:33 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-08-05 20:12:19 +0200
commit0b1808975a62559e6dbaf92b5935856bb4f820a8 (patch)
tree0b17c53eb5734dcf0fc7c208183ba4604c6791f9 /ui
parentgo.mod: operate like a normal go module (diff)
downloadwireguard-windows-0b1808975a62559e6dbaf92b5935856bb4f820a8.tar.xz
wireguard-windows-0b1808975a62559e6dbaf92b5935856bb4f820a8.zip
ui: raise window more aggressively
Since we might now be shell-exec'ing from elsewhere, we probably want to do a bit of input attachment shuffling.
Diffstat (limited to 'ui')
-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)