Stop animations when window is hidden (API + UWP)

This commit is contained in:
Paul Rouget 2020-02-19 14:09:50 +01:00
parent 5597ccf57d
commit 6ddde1a3e1
11 changed files with 77 additions and 0 deletions

View file

@ -487,6 +487,17 @@ impl ServoGlue {
self.process_event(WindowEvent::MediaSessionAction(action))
}
pub fn change_visibility(&mut self, visible: bool) -> Result<(), &'static str> {
info!("change_visibility");
if let Ok(id) = self.get_browser_id() {
let event = WindowEvent::ChangeBrowserVisibility(id, visible);
self.process_event(event)
} else {
// Ignore visibility change if no browser has been created yet.
Ok(())
}
}
fn process_event(&mut self, event: WindowEvent) -> Result<(), &'static str> {
self.events.push(event);
if !self.batch_mode {

View file

@ -686,6 +686,14 @@ pub extern "C" fn media_session_action(action: CMediaSessionActionType) {
});
}
#[no_mangle]
pub extern "C" fn change_visibility(visible: bool) {
catch_any_panic(|| {
debug!("change_visibility");
call(|s| s.change_visibility(visible));
});
}
pub struct WakeupCallback(extern "C" fn());
impl WakeupCallback {