Skip to content

Commit

Permalink
On Windows, fix set_control_flow from `AboutToWait
Browse files Browse the repository at this point in the history
In case the AboutToWait event sets the control flow to another value
it's not being used on this iteration.

Fixes rust-windowing#3215.
  • Loading branch information
ogoffart authored and kchibisov committed Nov 24, 2023
1 parent bf2a9f6 commit 8c9b2cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 12 additions & 13 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 8c9b2cd

Please sign in to comment.