#Listening to WindowOccluded winit event

5 messages · Page 1 of 1 (latest)

ripe bronze
#

I have this situation:

impl Plugin for PausePlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(PreUpdate, debug_pre);
        app.add_systems(Last, debug);
    }
}
fn debug(mut events: EventReader<WindowOccluded>) {
    for event in events.read() {
        if event.occluded {
            error!("LAST PAUSE");
        } else {
            error!("LAST PAUSE");
        }
    }
}
fn debug_pre(mut events: EventReader<WindowOccluded>) {
    for event in events.read() {
        if event.occluded {
            error!("PREUPDATE PAUSE");
        } else {
            error!("PREUPDATE UNPAUSE");
        }
    }
}

What I want is:

  • to run app.update() once after I switched to a new tab

What I observe:

  • it seems like app.update() doesn't run when I switch to a new tab. When I come back to the tab. I see all 4 logs at once:
    • PREUPDATE PAUSE
    • PREUPDATE UNPAUSE
    • LAST PAUSE
    • LAST UNPAUSE

Would there be a way to make this happen?

hot solstice
#

Since you’re using event readers, these are events that are being called. You can make sure they only run during those events? Just add
.run_if(on_event::<WindowOccluded>)) after your functions in the app builder

ripe bronze
#

no the problem is that the app is not run (app.update()) is not called when the window is occluded

hot solstice
#

Are you sure? I’m fairly certain I have some println!’s running in an update that keep printing when I minimize or put something over it

ripe bronze
#

Really? on the web as well?
This is specifically for putting a tab in the background on the web, sorry for not being more clear