Skip to content

Commit

Permalink
Merge pull request #2242 from dtzxporter/workaround-windows-issue-pt2
Browse files Browse the repository at this point in the history
Implement win32 workaround for multi_window application as well. Also trigger AboutToWait for Moved as well.
  • Loading branch information
hecrj authored Feb 13, 2024
2 parents dc2cba9 + 3a80fec commit 7a1e105
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion winit/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ where
if matches!(
event,
winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::Resized(_),
event: winit::event::WindowEvent::Resized(_)
| winit::event::WindowEvent::Moved(_),
..
}
) {
Expand Down
32 changes: 30 additions & 2 deletions winit/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ where

let mut context = task::Context::from_waker(task::noop_waker_ref());

let _ = event_loop.run(move |event, event_loop| {
let process_event = move |event, event_loop: &winit::event_loop::EventLoopWindowTarget<_>| {
if event_loop.exiting() {
return;
}
Expand Down Expand Up @@ -280,7 +280,35 @@ where
}
};
}
});
};

#[cfg(not(target_os = "windows"))]
let _ = event_loop.run(process_event);

// TODO: Remove when unnecessary
// On Windows, we emulate an `AboutToWait` event after every `Resized` event
// since the event loop does not resume during resize interaction.
// More details: https://github.com/rust-windowing/winit/issues/3272
#[cfg(target_os = "windows")]
{
let mut process_event = process_event;

let _ = event_loop.run(move |event, event_loop| {
if matches!(
event,
winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::Resized(_)
| winit::event::WindowEvent::Moved(_),
..
}
) {
process_event(event, event_loop);
process_event(winit::event::Event::AboutToWait, event_loop);
} else {
process_event(event, event_loop);
}
});
}

Ok(())
}
Expand Down

0 comments on commit 7a1e105

Please sign in to comment.