diff options
author | Alan Jeffrey <ajeffrey@mozilla.com> | 2019-06-26 10:13:22 -0500 |
---|---|---|
committer | Alan Jeffrey <ajeffrey@mozilla.com> | 2019-06-26 10:13:22 -0500 |
commit | 373ae0e341c18f8380c8031075d201a59ae9180d (patch) | |
tree | 09dd1e4ab4a512cd4e707662558f3af6f2c703ce | |
parent | ea4b1631dd3e2564c8406267e1a0c3751be3d4bc (diff) | |
download | servo-373ae0e341c18f8380c8031075d201a59ae9180d.tar.gz servo-373ae0e341c18f8380c8031075d201a59ae9180d.zip |
Handle resize events during run_forever
-rw-r--r-- | ports/glutin/app.rs | 22 |
1 files changed, 19 insertions, 3 deletions
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 |