5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 20:11:27 +08:00

[v3 Windows] Support application hide/show. Add WebviewWindow.IsVisible().

This commit is contained in:
Lea Anthony 2023-05-01 11:34:06 +10:00 committed by Misite Bao
parent 6e92a4f71e
commit d56bb59b72
6 changed files with 60 additions and 9 deletions

View File

@ -82,8 +82,8 @@ Webview Window Interface Methods
| Feature | Windows | Linux | Mac | Notes | | Feature | Windows | Linux | Mac | Notes |
|---------|---------|-------|-----|-------| |---------|---------|-------|-----|-------|
| Quit | | | Y | | | Quit | | | Y | |
| Hide | | | Y | | | Hide | Y | | Y | |
| Show | | | Y | | | Show | Y | | Y | |
### Dialogs ### Dialogs

View File

@ -23,6 +23,10 @@ type windowsApp struct {
mainThreadID w32.HANDLE mainThreadID w32.HANDLE
mainThreadWindowHWND w32.HWND mainThreadWindowHWND w32.HWND
// Windows hidden by application.Hide()
hiddenWindows []*windowsWebviewWindow
focusedWindow w32.HWND
// system theme // system theme
isDarkMode bool isDarkMode bool
} }
@ -38,9 +42,29 @@ func (m *windowsApp) getScreens() ([]*Screen, error) {
} }
func (m *windowsApp) hide() { func (m *windowsApp) hide() {
// Get the current focussed window
m.focusedWindow = w32.GetForegroundWindow()
// Iterate over all windows and hide them if they aren't already hidden
for _, window := range m.windowMap {
if window.isVisible() {
// Add to hidden windows
m.hiddenWindows = append(m.hiddenWindows, window)
window.hide()
}
}
// Switch focus to the next application
hwndNext := w32.GetWindow(m.mainThreadWindowHWND, w32.GW_HWNDNEXT)
w32.SetForegroundWindow(hwndNext)
} }
func (m *windowsApp) show() { func (m *windowsApp) show() {
// Iterate over all windows and show them if they were previously hidden
for _, window := range m.hiddenWindows {
window.show()
}
// Show the foreground window
w32.SetForegroundWindow(m.focusedWindow)
} }
func (m *windowsApp) on(eventID uint) { func (m *windowsApp) on(eventID uint) {

View File

@ -53,7 +53,7 @@ type (
isMaximised() bool isMaximised() bool
isFullscreen() bool isFullscreen() bool
isNormal() bool isNormal() bool
disableSizeConstraints() isVisible() bool
setFullscreenButtonEnabled(enabled bool) setFullscreenButtonEnabled(enabled bool)
show() show()
hide() hide()
@ -360,6 +360,14 @@ func (w *WebviewWindow) IsMinimised() bool {
return w.impl.isMinimised() return w.impl.isMinimised()
} }
// IsVisible returns true if the window is visible
func (w *WebviewWindow) IsVisible() bool {
if w.impl == nil {
return false
}
return w.impl.isVisible()
}
// IsMaximised returns true if the window is maximised // IsMaximised returns true if the window is maximised
func (w *WebviewWindow) IsMaximised() bool { func (w *WebviewWindow) IsMaximised() bool {
if w.impl == nil { if w.impl == nil {

View File

@ -260,6 +260,7 @@ func (w *windowsWebviewWindow) setPosition(x int, y int) {
w32.SetWindowPos(w.hwnd, w32.HWND_TOP, int(workRect.Left)+x, int(workRect.Top)+y, 0, 0, w32.SWP_NOSIZE) w32.SetWindowPos(w.hwnd, w32.HWND_TOP, int(workRect.Left)+x, int(workRect.Top)+y, 0, 0, w32.SWP_NOSIZE)
} }
// on is used to indicate that a particular event should be listened for
func (w *windowsWebviewWindow) on(eventID uint) { func (w *windowsWebviewWindow) on(eventID uint) {
//TODO implement me //TODO implement me
panic("implement me") panic("implement me")
@ -320,14 +321,13 @@ func (w *windowsWebviewWindow) isNormal() bool {
return !w.isMinimised() && !w.isMaximised() && !w.isFullscreen() return !w.isMinimised() && !w.isMaximised() && !w.isFullscreen()
} }
func (w *windowsWebviewWindow) disableSizeConstraints() { func (w *windowsWebviewWindow) isVisible() bool {
//TODO implement me style := uint32(w32.GetWindowLong(w.hwnd, w32.GWL_STYLE))
panic("implement me") return style&w32.WS_VISIBLE != 0
} }
func (w *windowsWebviewWindow) setFullscreenButtonEnabled(enabled bool) { func (w *windowsWebviewWindow) setFullscreenButtonEnabled(_ bool) {
//TODO implement me // Unused in Windows
panic("implement me")
} }
func (w *windowsWebviewWindow) show() { func (w *windowsWebviewWindow) show() {

View File

@ -276,6 +276,16 @@ const (
GWLP_USERDATA = -21 GWLP_USERDATA = -21
) )
const (
GW_HWNDFIRST = 0
GW_HWNDLAST = 1
GW_HWNDNEXT = 2
GW_HWNDPREV = 3
GW_OWNER = 4
GW_CHILD = 5
GW_ENABLEDPOPUP = 6
)
// Window style constants // Window style constants
const ( const (
WS_OVERLAPPED = 0x00000000 WS_OVERLAPPED = 0x00000000

View File

@ -41,6 +41,7 @@ var (
procGetWindowText = moduser32.NewProc("GetWindowTextW") procGetWindowText = moduser32.NewProc("GetWindowTextW")
procGetWindowRect = moduser32.NewProc("GetWindowRect") procGetWindowRect = moduser32.NewProc("GetWindowRect")
procGetWindowInfo = moduser32.NewProc("GetWindowInfo") procGetWindowInfo = moduser32.NewProc("GetWindowInfo")
procGetWindow = moduser32.NewProc("GetWindow")
procSetWindowCompositionAttribute = moduser32.NewProc("SetWindowCompositionAttribute") procSetWindowCompositionAttribute = moduser32.NewProc("SetWindowCompositionAttribute")
procMoveWindow = moduser32.NewProc("MoveWindow") procMoveWindow = moduser32.NewProc("MoveWindow")
procScreenToClient = moduser32.NewProc("ScreenToClient") procScreenToClient = moduser32.NewProc("ScreenToClient")
@ -415,6 +416,14 @@ func GetWindowInfo(hwnd HWND, info *WINDOWINFO) int {
return int(ret) return int(ret)
} }
func GetWindow(hwnd HWND, cmd uint32) HWND {
ret, _, _ := procGetWindow.Call(
hwnd,
uintptr(cmd),
)
return HWND(ret)
}
func GetWindowText(hwnd HWND) string { func GetWindowText(hwnd HWND) string {
textLen := GetWindowTextLength(hwnd) + 1 textLen := GetWindowTextLength(hwnd) + 1