From 66823e9a65328e1da9b75f99958d05846d8ead43 Mon Sep 17 00:00:00 2001 From: dtzxporter Date: Thu, 25 Jan 2024 15:23:30 -0500 Subject: [PATCH 1/3] Emulate `AboutToWait` event on Windows while resizing More details: https://github.com/rust-windowing/winit/issues/3272 --- winit/src/application.rs | 51 ++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/winit/src/application.rs b/winit/src/application.rs index 6a17683463..52cf7fe8a6 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -213,25 +213,50 @@ 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; - } + #[allow(unused_mut)] + let mut 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 _ = 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(()) From 518ec52ebd2001e26cd68f513432a7caed11c373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 7 Feb 2024 19:37:00 +0100 Subject: [PATCH 2/3] Update `CHANGELOG` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b4d5cfc51..518124e716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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... From a631f4d745848289a45c539191b8377e2e8e7c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 7 Feb 2024 19:42:55 +0100 Subject: [PATCH 3/3] Remove `allow(unused_mut)` in `winit::application` --- winit/src/application.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/winit/src/application.rs b/winit/src/application.rs index 52cf7fe8a6..77e2c83e7c 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -213,8 +213,7 @@ where let mut context = task::Context::from_waker(task::noop_waker_ref()); - #[allow(unused_mut)] - let mut process_event = + let process_event = move |event, event_loop: &winit::event_loop::EventLoopWindowTarget<_>| { if event_loop.exiting() { return; @@ -244,20 +243,24 @@ where // 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 _ = event_loop.run(move |event, event_loop| { - if matches!( - event, - winit::event::Event::WindowEvent { - event: winit::event::WindowEvent::Resized(_), - .. + { + 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); } - ) { - process_event(event, event_loop); - process_event(winit::event::Event::AboutToWait, event_loop); - } else { - process_event(event, event_loop); - } - }); + }); + } Ok(()) }