aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-05-08 12:46:33 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-08 19:47:08 +0200
commit22c131415e51470be734eb4e58905d7f937d4750 (patch)
treeb664f6b3587832bba30459638609db977a7350dd
parentui: confview: do not poll when minimized (diff)
downloadwireguard-windows-22c131415e51470be734eb4e58905d7f937d4750.tar.xz
wireguard-windows-22c131415e51470be734eb4e58905d7f937d4750.zip
ui: make window restoring and pop-up more aggressive
Signed-off-by: Simon Rozman <simon@rozman.si>
-rw-r--r--ui/aboutdialog.go2
-rw-r--r--ui/managewindow.go2
-rw-r--r--ui/raise.go25
-rw-r--r--ui/tray.go8
4 files changed, 23 insertions, 14 deletions
diff --git a/ui/aboutdialog.go b/ui/aboutdialog.go
index 22148ac1..fe0639d5 100644
--- a/ui/aboutdialog.go
+++ b/ui/aboutdialog.go
@@ -25,7 +25,7 @@ func onAbout(owner walk.Form) {
dlg, _ := walk.NewDialogWithFixedSize(owner)
dlg.SetTitle("About WireGuard")
dlg.SetLayout(vbl)
- wireguardIcon, err := walk.NewIconFromResourceWithSize("$wireguard.ico", walk.Size{dlg.DPI()/3, dlg.DPI()/3}) //TODO: calculate DPI dynamically
+ wireguardIcon, err := walk.NewIconFromResourceWithSize("$wireguard.ico", walk.Size{dlg.DPI() / 3, dlg.DPI() / 3}) //TODO: calculate DPI dynamically
if err == nil {
dlg.SetIcon(wireguardIcon)
}
diff --git a/ui/managewindow.go b/ui/managewindow.go
index 5b8279d9..54d6b1e9 100644
--- a/ui/managewindow.go
+++ b/ui/managewindow.go
@@ -36,7 +36,7 @@ func NewManageTunnelsWindow() (*ManageTunnelsWindow, error) {
}
disposables.Add(mtw)
- wireguardIcon, err := walk.NewIconFromResourceWithSize("$wireguard.ico", walk.Size{mtw.DPI()/3, mtw.DPI()/3}) //TODO: calculate DPI dynamically
+ wireguardIcon, err := walk.NewIconFromResourceWithSize("$wireguard.ico", walk.Size{mtw.DPI() / 3, mtw.DPI() / 3}) //TODO: calculate DPI dynamically
if err == nil {
mtw.SetIcon(wireguardIcon)
}
diff --git a/ui/raise.go b/ui/raise.go
index feb04323..f902546e 100644
--- a/ui/raise.go
+++ b/ui/raise.go
@@ -7,23 +7,34 @@ package ui
import (
"fmt"
+ "os"
+ "runtime"
+
"github.com/lxn/walk"
"github.com/lxn/win"
"golang.org/x/sys/windows"
- "os"
- "runtime"
)
const wireguardUIClass = "WireGuard UI - MainWindow"
+func raise(hwnd win.HWND) {
+ if win.IsIconic(hwnd) {
+ win.ShowWindow(hwnd, win.SW_RESTORE)
+ }
+
+ 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 RaiseUI() bool {
hwnd := win.FindWindow(windows.StringToUTF16Ptr(wireguardUIClass), nil)
if hwnd == 0 {
return false
}
- win.ShowWindow(hwnd, win.SW_NORMAL)
- win.BringWindowToTop(hwnd)
- win.SetForegroundWindow(hwnd)
+ raise(hwnd)
return true
}
@@ -37,9 +48,7 @@ func WaitForRaiseUIThenQuit() {
return 0
}
win.UnhookWinEvent(handle)
- win.ShowWindow(hwnd, win.SW_NORMAL)
- win.BringWindowToTop(hwnd)
- win.SetForegroundWindow(hwnd)
+ raise(hwnd)
os.Exit(0)
return 0
}, 0, 0, win.WINEVENT_SKIPOWNPROCESS|win.WINEVENT_OUTOFCONTEXT)
diff --git a/ui/tray.go b/ui/tray.go
index 3cf0f8bc..64c58a8a 100644
--- a/ui/tray.go
+++ b/ui/tray.go
@@ -156,7 +156,7 @@ func (tray *Tray) addTunnelAction(tunnel *service.Tunnel) {
oldState, err := tclosure.Toggle()
if err != nil {
tray.mtw.Synchronize(func() {
- tray.mtw.Show()
+ raise(tray.mtw.Handle())
tray.mtw.tunnelsPage.listView.selectTunnel(tclosure.Name)
tray.mtw.tabs.SetCurrentIndex(0)
if oldState == service.TunnelUnknown {
@@ -321,7 +321,7 @@ func (tray *Tray) UpdateFound() {
tray.mtw.tunnelsPage.listView.SelectFirstActiveTunnel()
}
tray.mtw.tabs.SetCurrentIndex(2)
- tray.mtw.Show()
+ raise(tray.mtw.Handle())
}
action.Triggered().Attach(showUpdateTab)
tray.clicked = showUpdateTab
@@ -348,7 +348,7 @@ func (tray *Tray) onManageTunnels() {
tray.mtw.tunnelsPage.listView.SelectFirstActiveTunnel()
tray.mtw.tabs.SetCurrentIndex(0)
}
- tray.mtw.Show()
+ raise(tray.mtw.Handle())
}
func (tray *Tray) onAbout() {
@@ -360,6 +360,6 @@ func (tray *Tray) onAbout() {
}
func (tray *Tray) onImport() {
- tray.mtw.Show()
+ raise(tray.mtw.Handle())
tray.mtw.tunnelsPage.onImport()
}