rust-windowing / rust-windowing/winit
MacOS ControlFlow::Wait doesn't work properly when pointer leaves window
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
Description
Description
When implementing ApplicationHandler I implemented my own about_to_wait() method. When control flow is set to ControlFlow::Wait and the pointer remains within the window, everything works as expected - the thread goes to sleep when nothing is happening. However, when the pointer leaves the window, the about_to_wait() method is called non-stop as if control flow was set to ControlFlow::Poll. When the pointer reenters the window, things work as expected again.
Super simple code example:
use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
use winit::window::{Window, WindowAttributes, WindowId};
#[derive(Debug, Default)]
struct App {
window: Option<Window>,
}
impl ApplicationHandler for App {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
if self.window.is_none() {
let window = event_loop
.create_window(WindowAttributes::default())
.expect("Failed to create window");
self.window = Some(window);
}
println!("resumed");
}
fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
window_id: WindowId,
event: WindowEvent,
) {
println!("window_event: {:?}", event);
}
// When the pointer leaves the window, this is called incessantly!
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
println!("about_to_wait");
}
}
fn main() {
let event_loop = EventLoop::new().expect("Failed to create event loop");
event_loop.set_control_flow(ControlFlow::Wait);
let mut app = App::default();
event_loop.run_app(&mut app).expect("Failed to run app");
}
macOS version
ProductName: macOS
ProductVersion: 14.6.1
BuildVersion: 23G93
Winit version
0.30.5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided ApplicationHandler example on macOS 14.6.1 with winit 0.30.5, then inspect the event-loop handling of ControlFlow::Wait when the pointer leaves the window. Done means about_to_wait is no longer called continuously while the pointer remains outside an otherwise idle window.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100