summaryrefslogtreecommitdiffstats
path: root/winit/src/application.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-12-20 10:00:27 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-12-20 10:03:35 +0100
commit031784e274b0a65dc67004e503b89d29fe0e36ea (patch)
tree73ad7a5e46e8f9fc9832ac85848a7a29153b8845 /winit/src/application.rs
parent50a7852cb857cd110077ffce492bafe9ebe8786c (diff)
downloadiced-031784e274b0a65dc67004e503b89d29fe0e36ea.tar.gz
iced-031784e274b0a65dc67004e503b89d29fe0e36ea.tar.bz2
iced-031784e274b0a65dc67004e503b89d29fe0e36ea.zip
Batch events for processing in `iced_winit` event loop
Diffstat (limited to 'winit/src/application.rs')
-rw-r--r--winit/src/application.rs123
1 files changed, 64 insertions, 59 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 5ff76060..7f5a3620 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -469,71 +469,74 @@ async fn run_instance<A, E, C>(
events.push(event);
}
}
- _ => {}
- }
+ event::Event::AboutToWait => {
+ if events.is_empty() && messages.is_empty() {
+ continue;
+ }
- if events.is_empty() && messages.is_empty() {
- continue;
- }
+ debug.event_processing_started();
- debug.event_processing_started();
+ let (interface_state, statuses) = user_interface.update(
+ &events,
+ state.cursor(),
+ &mut renderer,
+ &mut clipboard,
+ &mut messages,
+ );
- let (interface_state, statuses) = user_interface.update(
- &events,
- state.cursor(),
- &mut renderer,
- &mut clipboard,
- &mut messages,
- );
+ debug.event_processing_finished();
- debug.event_processing_finished();
+ for (event, status) in
+ events.drain(..).zip(statuses.into_iter())
+ {
+ runtime.broadcast(event, status);
+ }
- for (event, status) in events.drain(..).zip(statuses.into_iter()) {
- runtime.broadcast(event, status);
- }
+ if !messages.is_empty()
+ || matches!(
+ interface_state,
+ user_interface::State::Outdated
+ )
+ {
+ let mut cache =
+ ManuallyDrop::into_inner(user_interface).into_cache();
- if !messages.is_empty()
- || matches!(interface_state, user_interface::State::Outdated)
- {
- let mut cache =
- ManuallyDrop::into_inner(user_interface).into_cache();
-
- // Update application
- update(
- &mut application,
- &mut compositor,
- &mut surface,
- &mut cache,
- &state,
- &mut renderer,
- &mut runtime,
- &mut clipboard,
- &mut should_exit,
- &mut proxy,
- &mut debug,
- &mut messages,
- &window,
- );
-
- // Update window
- state.synchronize(&application, &window);
-
- user_interface = ManuallyDrop::new(build_user_interface(
- &application,
- cache,
- &mut renderer,
- state.logical_size(),
- &mut debug,
- ));
-
- if should_exit {
- break;
- }
- }
+ // Update application
+ update(
+ &mut application,
+ &mut compositor,
+ &mut surface,
+ &mut cache,
+ &mut state,
+ &mut renderer,
+ &mut runtime,
+ &mut clipboard,
+ &mut should_exit,
+ &mut proxy,
+ &mut debug,
+ &mut messages,
+ &window,
+ );
+
+ user_interface = ManuallyDrop::new(build_user_interface(
+ &application,
+ cache,
+ &mut renderer,
+ state.logical_size(),
+ &mut debug,
+ ));
+
+ if should_exit {
+ break;
+ }
+ }
- if !redraw_pending {
- window.request_redraw();
- redraw_pending = true;
+ if !redraw_pending {
+ window.request_redraw();
+ redraw_pending = true;
+ }
+ }
+ _ => {}
}
}
@@ -595,7 +598,7 @@ pub fn update<A: Application, C, E: Executor>(
compositor: &mut C,
surface: &mut C::Surface,
cache: &mut user_interface::Cache,
- state: &State<A>,
+ state: &mut State<A>,
renderer: &mut A::Renderer,
runtime: &mut Runtime<E, Proxy<A::Message>, A::Message>,
clipboard: &mut Clipboard,
@@ -632,6 +635,8 @@ pub fn update<A: Application, C, E: Executor>(
);
}
+ state.synchronize(application, window);
+
let subscription = application.subscription();
runtime.track(subscription.into_recipes());
}