On Windows, fix set_control_flow from `AboutToWait

In case the AboutToWait event sets the control flow to another value
it's not being used on this iteration.

Fixes #3215.
This commit is contained in:
Olivier Goffart 2023-11-08 16:21:33 +01:00 committed by GitHub
parent c89e6df758
commit 21701a33de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 13 deletions

View file

@ -13,6 +13,7 @@ Unreleased` header.
- On X11, check common alternative cursor names when loading cursor.
- On Windows, fix so `drag_window` and `drag_resize_window` can be called from another thread.
- On Windows, fix `set_control_flow` in `AboutToWait` not being taken in account.
- On macOS, send a `Resized` event after each `ScaleFactorChanged` event.
# 0.29.3

View file

@ -356,19 +356,6 @@ impl<T: 'static> EventLoop<T> {
/// Wait for one message and dispatch it, optionally with a timeout
fn wait_and_dispatch_message(&mut self, timeout: Option<Duration>) {
let start = Instant::now();
let runner = &self.window_target.p.runner_shared;
let control_flow_timeout = match runner.control_flow() {
ControlFlow::Wait => None,
ControlFlow::Poll => Some(Duration::ZERO),
ControlFlow::WaitUntil(wait_deadline) => {
Some(wait_deadline.saturating_duration_since(start))
}
};
let timeout = min_timeout(control_flow_timeout, timeout);
fn get_msg_with_timeout(msg: &mut MSG, timeout: Option<Duration>) -> PumpStatus {
unsafe {
// A timeout of None means wait indefinitely (so we don't need to call SetTimer)
@ -404,6 +391,8 @@ impl<T: 'static> EventLoop<T> {
}
}
let runner = &self.window_target.p.runner_shared;
// We aim to be consistent with the MacOS backend which has a RunLoop
// observer that will dispatch AboutToWait when about to wait for
// events, and NewEvents after the RunLoop wakes up.
@ -415,6 +404,16 @@ impl<T: 'static> EventLoop<T> {
//
runner.prepare_wait();
let control_flow_timeout = match runner.control_flow() {
ControlFlow::Wait => None,
ControlFlow::Poll => Some(Duration::ZERO),
ControlFlow::WaitUntil(wait_deadline) => {
let start = Instant::now();
Some(wait_deadline.saturating_duration_since(start))
}
};
let timeout = min_timeout(control_flow_timeout, timeout);
// # Safety
// The Windows API has no documented requirement for bitwise
// initializing a `MSG` struct (it can be uninitialized memory for the C