mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-21 19:39:29 +08:00
[v3 windows] Fix window lose focus events.
This commit is contained in:
parent
3efab5ba23
commit
10144adf61
@ -46,54 +46,31 @@ func (s *windowsSystemTray) positionWindow(window *WebviewWindow, offset int) er
|
||||
|
||||
screenBounds := currentScreen.WorkArea
|
||||
|
||||
newX := screenBounds.Width - window.Width()
|
||||
newY := screenBounds.Height - window.Height()
|
||||
|
||||
taskbarBounds := w32.GetTaskbarPosition()
|
||||
switch taskbarBounds.UEdge {
|
||||
case w32.ABE_LEFT:
|
||||
if trayBounds == nil {
|
||||
// Move it to the bottom left corner of the screen
|
||||
window.SetRelativePosition(offset, screenBounds.Height-window.Height())
|
||||
return nil
|
||||
if trayBounds != nil && trayBounds.Y-(window.Height()/2) >= 0 {
|
||||
newY = trayBounds.Y - (window.Height() / 2)
|
||||
}
|
||||
newHeight := trayBounds.Y - (window.Height() / 2)
|
||||
if newHeight < 0 {
|
||||
newHeight = 0
|
||||
}
|
||||
// Move it to the top left corner of the screen
|
||||
window.SetRelativePosition(offset, newHeight)
|
||||
window.SetRelativePosition(offset, newY)
|
||||
case w32.ABE_TOP:
|
||||
if trayBounds == nil {
|
||||
// Move it to the top right corner of the screen
|
||||
window.SetRelativePosition(screenBounds.Width-window.Width(), offset)
|
||||
return nil
|
||||
if trayBounds != nil && trayBounds.X-(window.Width()/2) <= newX {
|
||||
newX = trayBounds.X - (window.Width() / 2)
|
||||
}
|
||||
newWidth := trayBounds.X - (window.Width() / 2)
|
||||
if newWidth > screenBounds.Width-window.Width() {
|
||||
newWidth = screenBounds.Width - window.Width()
|
||||
}
|
||||
// Move it to the top left corner of the screen
|
||||
window.SetRelativePosition(newWidth, offset)
|
||||
window.SetRelativePosition(newX, offset)
|
||||
case w32.ABE_RIGHT:
|
||||
if trayBounds == nil {
|
||||
// Move it to the bottom right corner of the screen
|
||||
window.SetRelativePosition(screenBounds.Width-window.Width()-offset, screenBounds.Height-window.Height())
|
||||
return nil
|
||||
if trayBounds != nil && trayBounds.Y-(window.Height()/2) <= newY {
|
||||
newY = trayBounds.Y - (window.Height() / 2)
|
||||
}
|
||||
newHeight := trayBounds.Y - (window.Height() / 2)
|
||||
if newHeight > screenBounds.Height-window.Height() {
|
||||
newHeight = screenBounds.Height - window.Height()
|
||||
}
|
||||
window.SetRelativePosition(screenBounds.Width-window.Width()-offset, newHeight)
|
||||
window.SetRelativePosition(screenBounds.Width-window.Width()-offset, newY)
|
||||
case w32.ABE_BOTTOM:
|
||||
if trayBounds == nil {
|
||||
// Move it to the bottom right corner of the screen
|
||||
window.SetRelativePosition(screenBounds.Width-window.Width(), screenBounds.Height-window.Height()-offset)
|
||||
return nil
|
||||
if trayBounds != nil && trayBounds.X-(window.Width()/2) <= newX {
|
||||
newX = trayBounds.X - (window.Width() / 2)
|
||||
}
|
||||
newWidth := trayBounds.X - (window.Width() / 2)
|
||||
if newWidth > screenBounds.Width-window.Width() {
|
||||
newWidth = screenBounds.Width - window.Width()
|
||||
}
|
||||
window.SetRelativePosition(newWidth, screenBounds.Height-window.Height()-offset)
|
||||
window.SetRelativePosition(newX, screenBounds.Height-window.Height()-offset)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -61,10 +61,7 @@ type windowsWebviewWindow struct {
|
||||
// resizeBorder* is the width/height of the resize border in pixels.
|
||||
resizeBorderWidth int32
|
||||
resizeBorderHeight int32
|
||||
|
||||
// Internal flag to prevent closing the window almost immediately after opening it.
|
||||
// This happens when the window is opened after clicking a notification icon
|
||||
justOpened bool
|
||||
focusingChromium bool
|
||||
}
|
||||
|
||||
func (w *windowsWebviewWindow) setAbsolutePosition(x int, y int) {
|
||||
@ -566,7 +563,9 @@ func (w *windowsWebviewWindow) focus() {
|
||||
|
||||
func (w *windowsWebviewWindow) show() {
|
||||
w32.ShowWindow(w.hwnd, w32.SW_SHOW)
|
||||
w.focusingChromium = true
|
||||
w.chromium.Focus()
|
||||
w.focusingChromium = false
|
||||
}
|
||||
|
||||
func (w *windowsWebviewWindow) hide() {
|
||||
@ -740,6 +739,9 @@ func (w *windowsWebviewWindow) isActive() bool {
|
||||
func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
||||
switch msg {
|
||||
case w32.WM_ACTIVATE:
|
||||
if int(wparam&0xffff) == w32.WA_INACTIVE {
|
||||
w.parent.emit(events.Common.WindowLostFocus)
|
||||
}
|
||||
if wparam == w32.WA_ACTIVE || wparam == w32.WA_CLICKACTIVE {
|
||||
getNativeApplication().currentWindowID = w.parent.id
|
||||
w.parent.emit(events.Common.WindowFocus)
|
||||
@ -751,16 +753,11 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp
|
||||
if w.framelessWithDecorations() {
|
||||
w32.ExtendFrameIntoClientArea(w.hwnd, true)
|
||||
}
|
||||
w.justOpened = true
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
w.justOpened = false
|
||||
}()
|
||||
case w32.WM_CLOSE:
|
||||
w.parent.emit(events.Common.WindowClosing)
|
||||
return 0
|
||||
case w32.WM_KILLFOCUS:
|
||||
if w.justOpened {
|
||||
if w.focusingChromium {
|
||||
return 0
|
||||
}
|
||||
w.parent.emit(events.Common.WindowLostFocus)
|
||||
|
Loading…
Reference in New Issue
Block a user