Skip to content

Commit dec45ce

Browse files
ogoffartkchibisov
authored andcommitted
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.
1 parent f709ac6 commit dec45ce

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Unreleased` header.
1313

1414
- On X11, check common alternative cursor names when loading cursor.
1515
- On Windows, fix so `drag_window` and `drag_resize_window` can be called from another thread.
16+
- On Windows, fix `set_control_flow` in `AboutToWait` not being taken in account.
1617
- On macOS, send a `Resized` event after each `ScaleFactorChanged` event.
1718

1819
# 0.29.3

src/platform_impl/windows/event_loop.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -356,19 +356,6 @@ impl<T: 'static> EventLoop<T> {
356356

357357
/// Wait for one message and dispatch it, optionally with a timeout
358358
fn wait_and_dispatch_message(&mut self, timeout: Option<Duration>) {
359-
let start = Instant::now();
360-
361-
let runner = &self.window_target.p.runner_shared;
362-
363-
let control_flow_timeout = match runner.control_flow() {
364-
ControlFlow::Wait => None,
365-
ControlFlow::Poll => Some(Duration::ZERO),
366-
ControlFlow::WaitUntil(wait_deadline) => {
367-
Some(wait_deadline.saturating_duration_since(start))
368-
}
369-
};
370-
let timeout = min_timeout(control_flow_timeout, timeout);
371-
372359
fn get_msg_with_timeout(msg: &mut MSG, timeout: Option<Duration>) -> PumpStatus {
373360
unsafe {
374361
// A timeout of None means wait indefinitely (so we don't need to call SetTimer)
@@ -404,6 +391,8 @@ impl<T: 'static> EventLoop<T> {
404391
}
405392
}
406393

394+
let runner = &self.window_target.p.runner_shared;
395+
407396
// We aim to be consistent with the MacOS backend which has a RunLoop
408397
// observer that will dispatch AboutToWait when about to wait for
409398
// events, and NewEvents after the RunLoop wakes up.
@@ -415,6 +404,16 @@ impl<T: 'static> EventLoop<T> {
415404
//
416405
runner.prepare_wait();
417406

407+
let control_flow_timeout = match runner.control_flow() {
408+
ControlFlow::Wait => None,
409+
ControlFlow::Poll => Some(Duration::ZERO),
410+
ControlFlow::WaitUntil(wait_deadline) => {
411+
let start = Instant::now();
412+
Some(wait_deadline.saturating_duration_since(start))
413+
}
414+
};
415+
let timeout = min_timeout(control_flow_timeout, timeout);
416+
418417
// # Safety
419418
// The Windows API has no documented requirement for bitwise
420419
// initializing a `MSG` struct (it can be uninitialized memory for the C

0 commit comments

Comments
 (0)