do not run after we get a Suspend event

This commit is contained in:
Paul Rouget 2018-03-07 14:35:09 +08:00
parent 16b770b5c3
commit 09ae72da05

View file

@ -197,6 +197,7 @@ pub struct Window {
fullscreen: Cell<bool>, fullscreen: Cell<bool>,
gl: Rc<gl::Gl>, gl: Rc<gl::Gl>,
suspended: Cell<bool>,
} }
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
@ -327,6 +328,7 @@ impl Window {
fullscreen: Cell::new(false), fullscreen: Cell::new(false),
inner_size: Cell::new(inner_size), inner_size: Cell::new(inner_size),
screen_size, screen_size,
suspended: Cell::new(false),
}; };
window.present(); window.present();
@ -483,6 +485,14 @@ impl Window {
self.event_queue.borrow_mut().push(WindowEvent::Resize); self.event_queue.borrow_mut().push(WindowEvent::Resize);
} }
} }
Event::Suspended(suspended) => {
self.suspended.set(suspended);
if suspended {
self.set_animation_state(AnimationState::Idle);
} else {
self.event_queue.borrow_mut().push(WindowEvent::Idle);
}
}
Event::Awakened => { Event::Awakened => {
self.event_queue.borrow_mut().push(WindowEvent::Idle); self.event_queue.borrow_mut().push(WindowEvent::Idle);
} }
@ -574,7 +584,9 @@ impl Window {
events_loop.borrow_mut().run_forever(|e| { events_loop.borrow_mut().run_forever(|e| {
self.handle_window_event(e); self.handle_window_event(e);
if !self.event_queue.borrow().is_empty() { if !self.event_queue.borrow().is_empty() {
stop = servo_callback(); if !self.suspended.get() {
stop = servo_callback();
}
} }
if stop || self.is_animating() { if stop || self.is_animating() {
glutin::ControlFlow::Break glutin::ControlFlow::Break