Batch events for processing in iced_winit event loop

This commit is contained in:
Héctor Ramón Jiménez 2023-12-20 10:00:27 +01:00
parent 50a7852cb8
commit 031784e274
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -469,9 +469,7 @@ async fn run_instance<A, E, C>(
events.push(event); events.push(event);
} }
} }
_ => {} event::Event::AboutToWait => {
}
if events.is_empty() && messages.is_empty() { if events.is_empty() && messages.is_empty() {
continue; continue;
} }
@ -488,12 +486,17 @@ async fn run_instance<A, E, C>(
debug.event_processing_finished(); debug.event_processing_finished();
for (event, status) in events.drain(..).zip(statuses.into_iter()) { for (event, status) in
events.drain(..).zip(statuses.into_iter())
{
runtime.broadcast(event, status); runtime.broadcast(event, status);
} }
if !messages.is_empty() if !messages.is_empty()
|| matches!(interface_state, user_interface::State::Outdated) || matches!(
interface_state,
user_interface::State::Outdated
)
{ {
let mut cache = let mut cache =
ManuallyDrop::into_inner(user_interface).into_cache(); ManuallyDrop::into_inner(user_interface).into_cache();
@ -504,7 +507,7 @@ async fn run_instance<A, E, C>(
&mut compositor, &mut compositor,
&mut surface, &mut surface,
&mut cache, &mut cache,
&state, &mut state,
&mut renderer, &mut renderer,
&mut runtime, &mut runtime,
&mut clipboard, &mut clipboard,
@ -515,9 +518,6 @@ async fn run_instance<A, E, C>(
&window, &window,
); );
// Update window
state.synchronize(&application, &window);
user_interface = ManuallyDrop::new(build_user_interface( user_interface = ManuallyDrop::new(build_user_interface(
&application, &application,
cache, cache,
@ -536,6 +536,9 @@ async fn run_instance<A, E, C>(
redraw_pending = true; redraw_pending = true;
} }
} }
_ => {}
}
}
// Manually drop the user interface // Manually drop the user interface
drop(ManuallyDrop::into_inner(user_interface)); drop(ManuallyDrop::into_inner(user_interface));
@ -595,7 +598,7 @@ pub fn update<A: Application, C, E: Executor>(
compositor: &mut C, compositor: &mut C,
surface: &mut C::Surface, surface: &mut C::Surface,
cache: &mut user_interface::Cache, cache: &mut user_interface::Cache,
state: &State<A>, state: &mut State<A>,
renderer: &mut A::Renderer, renderer: &mut A::Renderer,
runtime: &mut Runtime<E, Proxy<A::Message>, A::Message>, runtime: &mut Runtime<E, Proxy<A::Message>, A::Message>,
clipboard: &mut Clipboard, clipboard: &mut Clipboard,
@ -632,6 +635,8 @@ pub fn update<A: Application, C, E: Executor>(
); );
} }
state.synchronize(application, window);
let subscription = application.subscription(); let subscription = application.subscription();
runtime.track(subscription.into_recipes()); runtime.track(subscription.into_recipes());
} }