Repository navigation
Windows: give keyboard focus back in focus_window when in the foreground - #2
Merged
Merged
Conversation
`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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 reportsWindowEvent::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, soResponse::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, butGetFocus()isn't the window, it callsSetFocus. Windows sendsWM_SETFOCUS, and winit reportsWindowEvent::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 noWindowFocused(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 asWM_SYSKEYDOWNand egui's text fields don't check window focus. With Evolve callingfocus_window()after closing the web view, the log showsWindowFocused(true)right after it closes and navigation works.🤖 Generated with Claude Code