Skip to content

Commit

Permalink
Merge pull request #2214 from dtzxporter/workaround-winit-win32-issues
Browse files Browse the repository at this point in the history
Workaround issue with winit on windows not resuming the event loop.
  • Loading branch information
hecrj authored Feb 7, 2024
2 parents b4dcf4e + a631f4d commit 80a29a2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Slow touch scrolling for `TextEditor` widget. [#2140](https://github.com/iced-rs/iced/pull/2140)
- `Subscription::map` using unreliable function pointer hash to identify mappers. [#2237](https://github.com/iced-rs/iced/pull/2237)
- Missing feature flag docs for `time::every`. [#2188](https://github.com/iced-rs/iced/pull/2188)
- Event loop not being resumed on Windows while resizing. [#2214](https://github.com/iced-rs/iced/pull/2214)

Many thanks to...

Expand Down
56 changes: 42 additions & 14 deletions winit/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,54 @@ where

let mut context = task::Context::from_waker(task::noop_waker_ref());

let _ = event_loop.run(move |event, event_loop| {
if event_loop.exiting() {
return;
}
let process_event =
move |event, event_loop: &winit::event_loop::EventLoopWindowTarget<_>| {
if event_loop.exiting() {
return;
}

event_sender.start_send(event).expect("Send event");
event_sender.start_send(event).expect("Send event");

let poll = instance.as_mut().poll(&mut context);
let poll = instance.as_mut().poll(&mut context);

match poll {
task::Poll::Pending => {
if let Ok(Some(flow)) = control_receiver.try_next() {
event_loop.set_control_flow(flow);
match poll {
task::Poll::Pending => {
if let Ok(Some(flow)) = control_receiver.try_next() {
event_loop.set_control_flow(flow);
}
}
task::Poll::Ready(_) => {
event_loop.exit();
}
}
task::Poll::Ready(_) => {
event_loop.exit();
}
};
});

#[cfg(not(target_os = "windows"))]
let _ = event_loop.run(process_event);

// TODO: Remove when unnecessary
// On Windows, we emulate an `AboutToWait` event after every `Resized` event
// since the event loop does not resume during resize interaction.
// More details: https://github.com/rust-windowing/winit/issues/3272
#[cfg(target_os = "windows")]
{
let mut process_event = process_event;

let _ = event_loop.run(move |event, event_loop| {
if matches!(
event,
winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::Resized(_),
..
}
) {
process_event(event, event_loop);
process_event(winit::event::Event::AboutToWait, event_loop);
} else {
process_event(event, event_loop);
}
});
}

Ok(())
}
Expand Down

0 comments on commit 80a29a2

Please sign in to comment.