Add `Windows::get_focused(_mut)`
Add a method to get the focused window.
Use this instead of WindowFocused events in close_on_esc.
Seems that the OS/window manager might not always send focused events on application startup.
Sadly, not a fix for #5646.
I'd not looked into this before. Surely assuming that every window is focused on creation also doesn't make sense.
E.g. on systems where new windows don't get focus automatically
Something else needs to change here, I think. We need winit to provide some guidance here.
So this is still an improvement, but I think this is unviable as an end state
Thanks for pointing that out. I had thought that focused would get its initial state from winit, but it simply defaults to true.
Looked through the winit docs and focus events is all the info we have on the window's focused state, leading me to believe the linked issue is a bug in the i3 window manager.
I've changed focused to be false on window creation as true causes the following system to print '2' for a single frame when added to the multiple_windows example.
.add_system(|windows: Res<Windows>| {
println!("{}", windows.iter().filter(|w| w.is_focused()).count())
})
There is the possibility that a rogue Window 'unfocused' event is getting in there (e.g. 1: true, 2: false is sent in that order), which this would handle correctly but close_on_esc currently does not.
There is the possibility that a rogue Window 'unfocused' event is getting in there (e.g. 1: true, 2: false is sent in that order)
Surely that would be considered a bug in the window manager?
bors r+
Pull request successfully merged into main.
Build succeeded:
- build-and-install-on-iOS
- build-android
- build (macos-latest)
- build (ubuntu-latest)
- build-wasm
- build (windows-latest)
- build-without-default-features (bevy)
- build-without-default-features (bevy_ecs)
- build-without-default-features (bevy_reflect)
- check-compiles
- check-doc
- check-missing-examples-in-docs
- ci
- markdownlint
- run-examples
- run-examples-on-wasm
- run-examples-on-windows-dx12