Skip to content

Commit

Permalink
Fix keyboard focus behavior. (#36)
Browse files Browse the repository at this point in the history
Fixes #32.
  • Loading branch information
jchv authored Feb 11, 2022
1 parent 0ff61f8 commit 3408ecb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/w32/w32.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package w32

import (
"golang.org/x/sys/windows"
"syscall"
"unicode/utf16"
"unsafe"

"golang.org/x/sys/windows"
)

var (
Expand Down Expand Up @@ -38,6 +39,8 @@ var (
User32SetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW")
User32AdjustWindowRect = user32.NewProc("AdjustWindowRect")
User32SetWindowPos = user32.NewProc("SetWindowPos")
User32IsDialogMessage = user32.NewProc("IsDialogMessage")
User32GetAncestor = user32.NewProc("GetAncestor")
)

const (
Expand Down Expand Up @@ -68,6 +71,12 @@ const (
WMApp = 0x8000
)

const (
GAParent = 1
GARoot = 2
GARootOwner = 3
)

const (
GWLStyle = -16
)
Expand Down
5 changes: 5 additions & 0 deletions webview.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ func (w *webview) Run() {
} else if msg.Message == w32.WMQuit {
return
}
r, _, _ := w32.User32GetAncestor.Call(uintptr(msg.Hwnd), w32.GARoot)
r, _, _ = w32.User32IsDialogMessage.Call(r, uintptr(unsafe.Pointer(&msg)))
if r != 0 {
continue
}
_, _, _ = w32.User32TranslateMessage.Call(uintptr(unsafe.Pointer(&msg)))
_, _, _ = w32.User32DispatchMessageW.Call(uintptr(unsafe.Pointer(&msg)))
}
Expand Down

0 comments on commit 3408ecb

Please sign in to comment.