mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Handle resize events during run_forever
This commit is contained in:
parent
ea4b1631dd
commit
373ae0e341
1 changed files with 19 additions and 3 deletions
|
@ -73,7 +73,8 @@ impl App {
|
||||||
!self.event_queue.borrow().is_empty() || self.window.has_events()
|
!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 {
|
match event {
|
||||||
// App level events
|
// App level events
|
||||||
glutin::Event::Suspended(suspended) => {
|
glutin::Event::Suspended(suspended) => {
|
||||||
|
@ -94,10 +95,18 @@ impl App {
|
||||||
if Some(window_id) != self.window.id() {
|
if Some(window_id) != self.window.id() {
|
||||||
warn!("Got an event from unknown window");
|
warn!("Got an event from unknown window");
|
||||||
} else {
|
} 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);
|
self.window.winit_event_to_servo_event(event);
|
||||||
|
return cont;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
glutin::ControlFlow::Break
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_loop(self) {
|
fn run_loop(self) {
|
||||||
|
@ -105,8 +114,15 @@ impl App {
|
||||||
if !self.window.is_animating() || self.suspended.get() {
|
if !self.window.is_animating() || self.suspended.get() {
|
||||||
// If there's no animations running then we block on the window event loop.
|
// If there's no animations running then we block on the window event loop.
|
||||||
self.events_loop.borrow_mut().run_forever(|e| {
|
self.events_loop.borrow_mut().run_forever(|e| {
|
||||||
self.winit_event_to_servo_event(e);
|
let cont = self.winit_event_to_servo_event(e);
|
||||||
glutin::ControlFlow::Break
|
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
|
// Grab any other events that may have happened
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue