-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve background tab behaviour #373
Comments
I think the general approach should be: Use the Window winit events to listen for when the window is tabbed-off / minimized / etc. Keep an attention state (active/inactive). #[derive(State)]
pub enum BevyWindowState {
Inactive,
Active,
} Depending on that, send inputs/etc. |
I'm also torn whether or not that should be in bevy proper, not just a plugin. As it currently stands, the winit event for WindowUnfocused just straight up doesn't work, because it fires after it returns, firing the Unfocused and Refocused at the same time. It's downright basically a bug, it's not delivering value to anyone. |
I've made a mention in bevy: bevyengine/bevy#13486 |
I just thought of something else... Let's imagine you have a system that is supposed to be an atomic counter. Every system, the counter += 1. If we do this Can we adjust the plugin so it only executes the Main schedule if (and only if) the window is not focused? Perhaps using a rolling track of whether the |
It does execute the Main schedule only if the window is not focused:
Basically the solution is extremely unsafe: we take a raw pointer on the world, which we use only when the window is hidden. So:
@Nul-led correct me if i'm wrong |
Its technically safe tho since we are in wasm land and everything is single threaded anyways, so we could totally run this alongside winits event loop |
Note these Primarily We should change this to if window().and_then(w| w.document()).is_some_and(|d| d.hidden()) {
...
} |
Wouldnt it be better to have a toggle for the "hidden" check instead, so we can enable / disable it on app launch |
@simbleau |
The main functionality was merged here: #371
But some things could be improved:
The text was updated successfully, but these errors were encountered: