rust-windowing / rust-windowing/winit
Child windows can cause different ForegroundWindow and Focus on Windows
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
Description
Description
When you call focus_window in winit on Windows, it uses SetForegroundWindow but it's possible that the window is the foreground window but it's not in focus resulting in an unfocusable window that you have to switch out of and back into to regain proper focus.
I found this out when using wry to create a webview as a child window which pulls focus and when it's destroyed, it leaves nothing focused even though the parent window is still the foreground window. I made a workaround for myself which calls SetFocus on the parent window.
I suggest that the focus_window method should fallback to checking if the window is focused via GetFocus and setting it with SetFocus if the window is already in the foreground but I'm not a Windows API expert or anything so I'm not sure what the correct approach is.
Windows version
Microsoft Windows [Version 10.0.22631.5768]
Winit version
0.30.12
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Windows implementation of focus_window and trace its use of SetForegroundWindow. Reproduce the child-window case described with wry, then investigate GetFocus and SetFocus for the parent after the child is destroyed. Done means the parent remains properly focused when it is already the foreground window.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100