Skip to content

Commit 2b82b81

Browse files
committed
Windows: Implement EventLoopExtPumpEvents and EventLoopExtRunOnDemand
A surprising amount of work was required to enable these extensions on Windows. I had originally assumed that pump_events was going to be very similar to run except would use PeekMessageW instead of GetMessageW to avoid blocking the external loop but I found the Windows backend broke several assumptions I had. Overall I think these changes can hopefully be considered a quite a significant simplification (I think it's a net deletion of a fair amount of code) and I think it also helps bring it into slightly closer alignment with other backends too Key changes: - I have removed the `wait_thread` that was a fairly fiddly way of handling `ControlFlow::WaitUntil` timeouts in favor of using `SetTimer` which works with the same messages picked up by `GetMessage` and `PeekMessage`. - I have removed the ordering guarantees between `MainEventsCleared`, `RedrawRequested` and `RedrawEventsCleared` events due to the complexity in maintaining this artificial ordering, which is already not supported consistently across backends anyway (in particular this ordering already isn't compatible with how MacOS / iOS work). - `RedrawRequested` events are now directly dispatched via `WM_PAINT` messages - comparable to how `RedrawRequested` is dispatched via `drawRect` in the MacOS backend. - I have re-worked how `NewEvents`, `MainEventsCleared`, and `RedrawEventsCleared` get dispatched to be more in line with the MacOS backend and also more in line with how we have recently discussed defining them for all platforms. `NewEvents` is conceptually delivered when the event loop "wakes up" and `MainEventsCleared` gets dispatched when the event loop is about to ask the OS to wait for new events. This is a more portable model, and is already how these events work in the MacOS backend. `RedrawEventsCleared` are just delivered after `MainEventsCleared` but this event no longer has a useful meaning. Probably the most controversial thing here is that this "breaks" the ordering rules for redraw event handling, but since my changes interacted with how the order is maintained I was very reluctant to figure out how to continue maintaining something that we have recently been discussing changing: rust-windowing#2640. Additionally, since the MacOS backend already doesn't strictly maintain this order it's somewhat academic to see this as a breakage if Winit applications can't really rely on it already. This updates the documentation for `request_redraw()` to reflect that we no longer guarantee that `RedrawRequested` events must be dispatched after `MainEventsCleared`.
1 parent aa91832 commit 2b82b81

File tree

5 files changed

+343
-432
lines changed

5 files changed

+343
-432
lines changed

src/platform/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
//!
1212
//! And the following platform-specific modules:
1313
//!
14-
//! - `run_ondemand` (available on `android`)
15-
//! - `pump_events` (available on `android`)
14+
//! - `run_ondemand` (available on `windows`, `android`)
15+
//! - `pump_events` (available on `windows`, `android`)
1616
//! - `run_return` (available on `windows`, `unix`, `macos`, and `android`)
1717
//!
1818
//! However only the module corresponding to the platform you're compiling to will be available.
@@ -34,10 +34,10 @@ pub mod windows;
3434
#[cfg(x11_platform)]
3535
pub mod x11;
3636

37-
#[cfg(any(android_platform))]
37+
#[cfg(any(windows_platform, android_platform))]
3838
pub mod run_ondemand;
3939

40-
#[cfg(any(android_platform,))]
40+
#[cfg(any(windows_platform, android_platform,))]
4141
pub mod pump_events;
4242

4343
#[cfg(any(

0 commit comments

Comments
 (0)