diff --git a/v3/pkg/application/systemtray_windows.go b/v3/pkg/application/systemtray_windows.go index c468b900c..d0a388a84 100644 --- a/v3/pkg/application/systemtray_windows.go +++ b/v3/pkg/application/systemtray_windows.go @@ -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 } diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index b24c0f391..6c31d04e4 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -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)