bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Add `Windows::get_focused(_mut)`

Open tim-blackbird opened this issue 3 years ago • 5 comments

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.

tim-blackbird avatar Nov 12 '22 23:11 tim-blackbird

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

DJMcNab avatar Nov 13 '22 09:11 DJMcNab

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())
})

tim-blackbird avatar Nov 13 '22 14:11 tim-blackbird

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.

DJMcNab avatar Nov 13 '22 14:11 DJMcNab

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?

tim-blackbird avatar Nov 13 '22 14:11 tim-blackbird

bors r+

cart avatar Nov 14 '22 21:11 cart

Build failed (retrying...):

bors[bot] avatar Nov 14 '22 21:11 bors[bot]