Skip to content

Windows: give keyboard focus back in focus_window when in the foreground - #2

Merged
maxded merged 1 commit into
ios-pump-eventsfrom
restore-keyboard-focus
Nov 10, 2026
Merged

maxded merged 1 commit into
ios-pump-eventsfrom
restore-keyboard-focus

Conversation

@maxded

@maxded maxded commented Nov 10, 2026 •

Copy link
Copy Markdown

Problem

On Windows, Window::focus_window() returns early when the window is already the foreground window. That misses one case: when a focused child window is destroyed, such as an embedded web view (wry/WebView2 built as a child of the winit window), Windows doesn't give keyboard focus back to the parent. The window stays in the foreground without keyboard focus, so winit never reports WindowEvent::Focused(true). Clicking or tapping it doesn't help, since it's already active and winit doesn't take focus on clicks. Only switching to another window and back fixes it.

Keystrokes still arrive: without a focus window, Windows sends them to the active window as WM_SYSKEYDOWN/WM_SYSKEYUP, which winit handles like normal key messages. What breaks is everything that tracks window focus. egui, for example, keeps treating the window as unfocused, so Response::has_focus() stays false and keyboard focus isn't shown.

Changes

  • focus_window() on Windows: when the window is visible, not minimized and in the foreground, but GetFocus() isn't the window, it calls SetFocus. Windows sends WM_SETFOCUS, and winit reports WindowEvent::Focused(true) as usual. Unchanged when the window isn't in the foreground.

Based on ios-pump-events, which Evolve and Breda pin (#1). Used by https://github.com/Traverse-Research/evolve/pull/3355.

Evidence

In Evolve on an MSI Claw 8 AI+ (Windows 11), logging in through the in-app web view logged WindowFocused(false) when the login page opened and no WindowFocused(true) after it closed. egui showed no keyboard focus, so controller navigation lost its highlight and stick input until alt-tabbing. On a Windows desktop, typing into a text field after logging in kept working, because the keystrokes arrive as WM_SYSKEYDOWN and egui's text fields don't check window focus. With Evolve calling focus_window() after closing the web view, the log shows WindowFocused(true) right after it closes and navigation works.

🤖 Generated with Claude Code

`focus_window` only activated the window when it wasn't the foreground window. When a focused
child window, such as an embedded web view, is destroyed, Windows doesn't move keyboard focus
back to its parent: the window stays in the foreground without keyboard focus, and clicking it
doesn't take focus either. `focus_window` now calls `SetFocus` in that case, which sends
`WM_SETFOCUS` and reports `WindowEvent::Focused(true)`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maxded
maxded merged commit 03fb4b7 into ios-pump-events Nov 10, 2026
0 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant