gui/window (Windows): give the keyboard focus to WebView2
The host window never moved the focus into the WebView2 control, so a page got no keys after the start or after Alt-Tab until it was clicked. Move it on WM_SETFOCUS and once the control exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5dd4a86b68
commit
586e76889c
1 file changed
+10
@@ -67,6 +67,7 @@ const (
|
||||
wmDestroy = 0x0002
|
||||
wmMove = 0x0003
|
||||
wmSize = 0x0005
|
||||
wmSetFocus = 0x0007
|
||||
wmClose = 0x0010
|
||||
wmQuit = 0x0012
|
||||
wmMoving = 0x0216
|
||||
@@ -193,6 +194,7 @@ func newBackend(opt Options) (backend, string, string, error) {
|
||||
return nil, "", "", errors.New("window: WebView2 could not be created (is the Microsoft Edge WebView2 Runtime installed?)")
|
||||
}
|
||||
c.Resize()
|
||||
c.Focus() // the window got WM_SETFOCUS before the control existed
|
||||
if s, err := c.GetSettings(); err == nil {
|
||||
_ = s.PutAreDevToolsEnabled(opt.Debug)
|
||||
_ = s.PutAreDefaultContextMenusEnabled(opt.Debug)
|
||||
@@ -220,6 +222,14 @@ func wndproc(hwnd, msg, wp, lp uintptr) uintptr {
|
||||
_ = b.chromium.NotifyParentWindowPositionChanged()
|
||||
}
|
||||
b.reportFrame()
|
||||
case wmSetFocus:
|
||||
// The keyboard focus belongs in the WebView2 control (its own
|
||||
// child window): without this a page gets no keys after the
|
||||
// start or after Alt-Tab until it is clicked.
|
||||
if b.chromium != nil {
|
||||
b.chromium.Focus()
|
||||
}
|
||||
return 0
|
||||
case wmApp:
|
||||
b.runQueue()
|
||||
return 0
|
||||
|
||||
Reference in new issue
Block a user