rust-windowing / rust-windowing/winit
Window does not close under specific conditions.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
Description
Description
Hi,
Window does not close if I click on Close button (on either window decorations or taskbar) and event_loop.exit() is called from about_to_wait. It just sort of stays there and does nothing. But it will close if I move mouse over window surface.
I am not sure if this is only Windows "problem" or it happens on other platforms too.
Minimal repro code:
fn main() -> Result<(), Box<dyn std::error::Error>> {
winit::event_loop::EventLoop::new()?.run_app(&mut App {
should_exit: false,
window: None,
})?;
Ok(())
}
struct App {
should_exit: bool,
window: Option<winit::window::Window>,
}
impl winit::application::ApplicationHandler for App {
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
self.window.get_or_insert_with(|| {
event_loop
.create_window(winit::window::WindowAttributes::default())
.unwrap()
});
}
fn window_event(
&mut self,
_: &winit::event_loop::ActiveEventLoop,
_: winit::window::WindowId,
event: winit::event::WindowEvent,
) {
match event {
winit::event::WindowEvent::CloseRequested => self.should_exit = true,
_ => (),
}
}
fn about_to_wait(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
if self.should_exit {
event_loop.exit()
}
}
}
Should be event_loop.exit() moved into window_event instead of self.should_exit = true then it will work as expected.
i got this "should exit bool pattern" from example control_flow so maybe that example has this issue too.
Thanks!
Windows version
Microsoft Windows [Version 10.0.22631.3447]
Winit version
0.30.0
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 minimal Rust reproduction on Windows and compare exiting from window_event with setting should_exit for about_to_wait. Trace the event-loop behavior around CloseRequested, about_to_wait, and event_loop.exit(). Done means the window closes after the Close button without requiring mouse movement, and the behavior is understood across the relevant platforms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100