diff --git a/ports/glutin/app.rs b/ports/glutin/app.rs index babc44d5b3f..8292f5912be 100644 --- a/ports/glutin/app.rs +++ b/ports/glutin/app.rs @@ -73,7 +73,8 @@ impl App { !self.event_queue.borrow().is_empty() || self.window.has_events() } - fn winit_event_to_servo_event(&self, event: glutin::Event) { + // This function decides whether the event should be handled during `run_forever`. + fn winit_event_to_servo_event(&self, event: glutin::Event) -> glutin::ControlFlow { match event { // App level events glutin::Event::Suspended(suspended) => { @@ -94,10 +95,18 @@ impl App { if Some(window_id) != self.window.id() { warn!("Got an event from unknown window"); } else { + // Resize events need to be handled during run_forever + let cont = if let glutin::WindowEvent::Resized(_) = event { + glutin::ControlFlow::Continue + } else { + glutin::ControlFlow::Break + }; self.window.winit_event_to_servo_event(event); + return cont; } }, } + glutin::ControlFlow::Break } fn run_loop(self) { @@ -105,8 +114,15 @@ impl App { if !self.window.is_animating() || self.suspended.get() { // If there's no animations running then we block on the window event loop. self.events_loop.borrow_mut().run_forever(|e| { - self.winit_event_to_servo_event(e); - glutin::ControlFlow::Break + let cont = self.winit_event_to_servo_event(e); + if cont == glutin::ControlFlow::Continue { + // Note we need to be careful to make sure that any events + // that are handled during run_forever aren't re-entrant, + // since we are handling them while holding onto a mutable borrow + // of the events loop + self.handle_events(); + } + cont }); } // Grab any other events that may have happened