diff --git a/CHANGELOG.md b/CHANGELOG.md index 523dda53..a69df9d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +- On Windows, fix minor timing issue in wait_until_time_or_msg - On macOS, fix `set_simple_screen` to remember frame excluding title bar. - On Wayland, fix coordinates in touch events when scale factor isn't 1. - On Wayland, fix color from `close_button_icon_color` not applying. diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 7e1d929e..890e2f04 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -320,11 +320,9 @@ fn main_thread_id() -> DWORD { unsafe { MAIN_THREAD_ID } } -// Returns true if the wait time was reached, and false if a message must be processed. -unsafe fn wait_until_time_or_msg(wait_until: Instant) -> bool { - let mut msg = mem::zeroed(); +unsafe fn wait_until_time_or_msg(wait_until: Instant) { let now = Instant::now(); - if now <= wait_until { + if now < wait_until { // MsgWaitForMultipleObjects tends to overshoot just a little bit. We subtract 1 millisecond // from the requested time and spinlock for the remainder to compensate for that. let resume_reason = winuser::MsgWaitForMultipleObjectsEx( @@ -336,16 +334,16 @@ unsafe fn wait_until_time_or_msg(wait_until: Instant) -> bool { ); if resume_reason == winerror::WAIT_TIMEOUT { + let mut msg = mem::zeroed(); while Instant::now() < wait_until { if 0 != winuser::PeekMessageW(&mut msg, ptr::null_mut(), 0, 0, 0) { - return false; + break; } } } } - - return true; } + // Implementation taken from https://github.com/rust-lang/rust/blob/db5476571d9b27c862b95c1e64764b0ac8980e23/src/libstd/sys/windows/mod.rs fn dur2timeout(dur: Duration) -> DWORD { // Note that a duration is a (u64, u32) (seconds, nanoseconds) pair, and the