fix issues in wait_until_time_or_msg function (#1423)

also removed unused return value
This commit is contained in:
Philippe Renon 2020-02-19 01:27:47 +01:00 committed by GitHub
parent 76d0dd7ec3
commit 522a6e3298
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View file

@ -1,5 +1,6 @@
# Unreleased # 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 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 coordinates in touch events when scale factor isn't 1.
- On Wayland, fix color from `close_button_icon_color` not applying. - On Wayland, fix color from `close_button_icon_color` not applying.

View file

@ -320,11 +320,9 @@ fn main_thread_id() -> DWORD {
unsafe { MAIN_THREAD_ID } 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) {
unsafe fn wait_until_time_or_msg(wait_until: Instant) -> bool {
let mut msg = mem::zeroed();
let now = Instant::now(); let now = Instant::now();
if now <= wait_until { if now < wait_until {
// MsgWaitForMultipleObjects tends to overshoot just a little bit. We subtract 1 millisecond // 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. // from the requested time and spinlock for the remainder to compensate for that.
let resume_reason = winuser::MsgWaitForMultipleObjectsEx( 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 { if resume_reason == winerror::WAIT_TIMEOUT {
let mut msg = mem::zeroed();
while Instant::now() < wait_until { while Instant::now() < wait_until {
if 0 != winuser::PeekMessageW(&mut msg, ptr::null_mut(), 0, 0, 0) { 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 // Implementation taken from https://github.com/rust-lang/rust/blob/db5476571d9b27c862b95c1e64764b0ac8980e23/src/libstd/sys/windows/mod.rs
fn dur2timeout(dur: Duration) -> DWORD { fn dur2timeout(dur: Duration) -> DWORD {
// Note that a duration is a (u64, u32) (seconds, nanoseconds) pair, and the // Note that a duration is a (u64, u32) (seconds, nanoseconds) pair, and the