Skip to content
Permalink
Browse files

Handle resize events during run_forever

  • Loading branch information...
asajeffrey committed Jun 26, 2019
1 parent ea4b163 commit 373ae0e341c18f8380c8031075d201a59ae9180d
Showing with 19 additions and 3 deletions.
  1. +19 −3 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,19 +95,34 @@ 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) {
loop {
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

0 comments on commit 373ae0e

Please sign in to comment.
You can’t perform that action at this time.