mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 17:12:11 +08:00
[v3 Windows] Support application hide/show. Add WebviewWindow.IsVisible()
.
This commit is contained in:
parent
6e92a4f71e
commit
d56bb59b72
@ -82,8 +82,8 @@ Webview Window Interface Methods
|
||||
| Feature | Windows | Linux | Mac | Notes |
|
||||
|---------|---------|-------|-----|-------|
|
||||
| Quit | | | Y | |
|
||||
| Hide | | | Y | |
|
||||
| Show | | | Y | |
|
||||
| Hide | Y | | Y | |
|
||||
| Show | Y | | Y | |
|
||||
|
||||
### Dialogs
|
||||
|
||||
|
@ -23,6 +23,10 @@ type windowsApp struct {
|
||||
mainThreadID w32.HANDLE
|
||||
mainThreadWindowHWND w32.HWND
|
||||
|
||||
// Windows hidden by application.Hide()
|
||||
hiddenWindows []*windowsWebviewWindow
|
||||
focusedWindow w32.HWND
|
||||
|
||||
// system theme
|
||||
isDarkMode bool
|
||||
}
|
||||
@ -38,9 +42,29 @@ func (m *windowsApp) getScreens() ([]*Screen, error) {
|
||||
}
|
||||
|
||||
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() {
|
||||
// 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) {
|
||||
|
@ -53,7 +53,7 @@ type (
|
||||
isMaximised() bool
|
||||
isFullscreen() bool
|
||||
isNormal() bool
|
||||
disableSizeConstraints()
|
||||
isVisible() bool
|
||||
setFullscreenButtonEnabled(enabled bool)
|
||||
show()
|
||||
hide()
|
||||
@ -360,6 +360,14 @@ func (w *WebviewWindow) IsMinimised() bool {
|
||||
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
|
||||
func (w *WebviewWindow) IsMaximised() bool {
|
||||
if w.impl == nil {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
// on is used to indicate that a particular event should be listened for
|
||||
func (w *windowsWebviewWindow) on(eventID uint) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
@ -320,14 +321,13 @@ func (w *windowsWebviewWindow) isNormal() bool {
|
||||
return !w.isMinimised() && !w.isMaximised() && !w.isFullscreen()
|
||||
}
|
||||
|
||||
func (w *windowsWebviewWindow) disableSizeConstraints() {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
func (w *windowsWebviewWindow) isVisible() bool {
|
||||
style := uint32(w32.GetWindowLong(w.hwnd, w32.GWL_STYLE))
|
||||
return style&w32.WS_VISIBLE != 0
|
||||
}
|
||||
|
||||
func (w *windowsWebviewWindow) setFullscreenButtonEnabled(enabled bool) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
func (w *windowsWebviewWindow) setFullscreenButtonEnabled(_ bool) {
|
||||
// Unused in Windows
|
||||
}
|
||||
|
||||
func (w *windowsWebviewWindow) show() {
|
||||
|
@ -276,6 +276,16 @@ const (
|
||||
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
|
||||
const (
|
||||
WS_OVERLAPPED = 0x00000000
|
||||
|
@ -41,6 +41,7 @@ var (
|
||||
procGetWindowText = moduser32.NewProc("GetWindowTextW")
|
||||
procGetWindowRect = moduser32.NewProc("GetWindowRect")
|
||||
procGetWindowInfo = moduser32.NewProc("GetWindowInfo")
|
||||
procGetWindow = moduser32.NewProc("GetWindow")
|
||||
procSetWindowCompositionAttribute = moduser32.NewProc("SetWindowCompositionAttribute")
|
||||
procMoveWindow = moduser32.NewProc("MoveWindow")
|
||||
procScreenToClient = moduser32.NewProc("ScreenToClient")
|
||||
@ -415,6 +416,14 @@ func GetWindowInfo(hwnd HWND, info *WINDOWINFO) int {
|
||||
return int(ret)
|
||||
}
|
||||
|
||||
func GetWindow(hwnd HWND, cmd uint32) HWND {
|
||||
ret, _, _ := procGetWindow.Call(
|
||||
hwnd,
|
||||
uintptr(cmd),
|
||||
)
|
||||
return HWND(ret)
|
||||
}
|
||||
|
||||
func GetWindowText(hwnd HWND) string {
|
||||
textLen := GetWindowTextLength(hwnd) + 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user