From 6bf4205e35c02f7bbb3b693c2acf2829d93b1e66 Mon Sep 17 00:00:00 2001 From: creamy-corn Date: Tue, 12 Aug 2025 16:06:34 -0700 Subject: [PATCH 1/2] Update window.go Fixes the potential of losing focus from actions like ALT-Tab, Clicking the Titlebar, opening and closing dialogs. --- v2/internal/frontend/desktop/windows/window.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/v2/internal/frontend/desktop/windows/window.go b/v2/internal/frontend/desktop/windows/window.go index b04d61814..f745435bc 100644 --- a/v2/internal/frontend/desktop/windows/window.go +++ b/v2/internal/frontend/desktop/windows/window.go @@ -237,6 +237,14 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr { //} } + if w.isActive && w.chromium != nil { + if ctrl := w.chromium.GetController(); ctrl != nil { + // Push keyboard focus into WebView2 when activated + _ = ctrl.MoveFocus(edge.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC) + // _ = ctrl.MoveFocus(0) // fallback if your bindings lack the constant + } + } + case 0x02E0: //w32.WM_DPICHANGED newWindowSize := (*w32.RECT)(unsafe.Pointer(lparam)) w32.SetWindowPos(w.Handle(), From 0fe2f5febc0d96fec0e7a1e9f9880a88e4ff1c87 Mon Sep 17 00:00:00 2001 From: creamy-corn Date: Tue, 12 Aug 2025 16:11:45 -0700 Subject: [PATCH 2/2] Update frontend.go Fixes the focus error when application starts up. When an input has autofocus, the user should instantly be able to type. --- v2/internal/frontend/desktop/windows/frontend.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/v2/internal/frontend/desktop/windows/frontend.go b/v2/internal/frontend/desktop/windows/frontend.go index a29eb851b..c052fc228 100644 --- a/v2/internal/frontend/desktop/windows/frontend.go +++ b/v2/internal/frontend/desktop/windows/frontend.go @@ -942,6 +942,14 @@ func (f *Frontend) navigationCompleted(sender *edge.ICoreWebView2, args *edge.IC win32.ShowWindow(f.mainWindow.Handle()) } + // Ensure initial keyboard focus goes into the WebView so typing works without a click. + if !f.frontendOptions.StartHidden && f.frontendOptions.WindowStartState != options.Minimised { + if ctrl := f.chromium.GetController(); ctrl != nil { + _ = ctrl.MoveFocus(edge.COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC) + // _ = ctrl.MoveFocus(0) + } + } + f.mainWindow.hasBeenShown = true }