From fc5689ea44f17986f429f189ce6cdda4274199a7 Mon Sep 17 00:00:00 2001 From: Inkeliz Date: Mon, 25 Jul 2022 13:40:56 +0100 Subject: [PATCH] app: [windows] recover focus on click Previously, Gio doesn't reclaim the focus when they lose that to a parent window. In such a case, the child window can steal keyboard focus, and Gio will never recover it. Now, Gio will recover the focus when clicked. Signed-off-by: Inkeliz --- app/os_windows.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/os_windows.go b/app/os_windows.go index d476896e..0a49f94e 100644 --- a/app/os_windows.go +++ b/app/os_windows.go @@ -53,6 +53,7 @@ type window struct { placement *windows.WindowPlacement animating bool + focused bool deltas winDeltas borderSize image.Point @@ -277,8 +278,10 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr Type: pointer.Cancel, }) case windows.WM_SETFOCUS: + w.focused = true w.w.Event(key.FocusEvent{Focus: true}) case windows.WM_KILLFOCUS: + w.focused = false w.w.Event(key.FocusEvent{Focus: false}) case windows.WM_NCHITTEST: if w.config.Decorated { @@ -470,6 +473,10 @@ func (w *window) hitTest(x, y int) uintptr { } func (w *window) pointerButton(btn pointer.Buttons, press bool, lParam uintptr, kmods key.Modifiers) { + if !w.focused { + windows.SetFocus(w.hwnd) + } + var typ pointer.Type if press { typ = pointer.Press