Skip to content

Commit 80a29a2

Browse files
authored
Merge pull request #2214 from dtzxporter/workaround-winit-win32-issues
Workaround issue with winit on windows not resuming the event loop.
2 parents b4dcf4e + a631f4d commit 80a29a2

2 files changed

Lines changed: 43 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9696
- Slow touch scrolling for `TextEditor` widget. [#2140](https://github.com/iced-rs/iced/pull/2140)
9797
- `Subscription::map` using unreliable function pointer hash to identify mappers. [#2237](https://github.com/iced-rs/iced/pull/2237)
9898
- Missing feature flag docs for `time::every`. [#2188](https://github.com/iced-rs/iced/pull/2188)
99+
- Event loop not being resumed on Windows while resizing. [#2214](https://github.com/iced-rs/iced/pull/2214)
99100

100101
Many thanks to...
101102

winit/src/application.rs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,54 @@ where
213213

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

216-
let _ = event_loop.run(move |event, event_loop| {
217-
if event_loop.exiting() {
218-
return;
219-
}
216+
let process_event =
217+
move |event, event_loop: &winit::event_loop::EventLoopWindowTarget<_>| {
218+
if event_loop.exiting() {
219+
return;
220+
}
220221

221-
event_sender.start_send(event).expect("Send event");
222+
event_sender.start_send(event).expect("Send event");
222223

223-
let poll = instance.as_mut().poll(&mut context);
224+
let poll = instance.as_mut().poll(&mut context);
224225

225-
match poll {
226-
task::Poll::Pending => {
227-
if let Ok(Some(flow)) = control_receiver.try_next() {
228-
event_loop.set_control_flow(flow);
226+
match poll {
227+
task::Poll::Pending => {
228+
if let Ok(Some(flow)) = control_receiver.try_next() {
229+
event_loop.set_control_flow(flow);
230+
}
231+
}
232+
task::Poll::Ready(_) => {
233+
event_loop.exit();
229234
}
230-
}
231-
task::Poll::Ready(_) => {
232-
event_loop.exit();
233235
}
234236
};
235-
});
237+
238+
#[cfg(not(target_os = "windows"))]
239+
let _ = event_loop.run(process_event);
240+
241+
// TODO: Remove when unnecessary
242+
// On Windows, we emulate an `AboutToWait` event after every `Resized` event
243+
// since the event loop does not resume during resize interaction.
244+
// More details: https://github.com/rust-windowing/winit/issues/3272
245+
#[cfg(target_os = "windows")]
246+
{
247+
let mut process_event = process_event;
248+
249+
let _ = event_loop.run(move |event, event_loop| {
250+
if matches!(
251+
event,
252+
winit::event::Event::WindowEvent {
253+
event: winit::event::WindowEvent::Resized(_),
254+
..
255+
}
256+
) {
257+
process_event(event, event_loop);
258+
process_event(winit::event::Event::AboutToWait, event_loop);
259+
} else {
260+
process_event(event, event_loop);
261+
}
262+
});
263+
}
236264

237265
Ok(())
238266
}

0 commit comments

Comments
 (0)