-
Notifications
You must be signed in to change notification settings - Fork 948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cursor grab fails in fullscreen on windows #574
Comments
I think you mean: I have the same issue on Windows 10 The issue occurs when |
It looked like a deadlock was happening somewhere, and the results are a bit amusing. As you might've heard by now, we block during resize events on Windows. However, we only unblock in Here's a really goofy temporary workaround you can use: extern crate winit;
use winit::{ControlFlow, Event, WindowEvent};
fn main() {
let mut event_loop = winit::EventsLoop::new();
let monitor = event_loop.get_primary_monitor();
let window = winit::WindowBuilder::new()
.with_fullscreen(Some(monitor))
.build(&event_loop)
.unwrap();
let mut run_count = Some(0);
event_loop.run_forever(|event| {
match event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::Resized(_) => {
if let Some(count) = run_count {
let dpi_factor = window.get_hidpi_factor();
if (dpi_factor == 1.0 && count == 0)
|| (dpi_factor != 1.0 && count == 1) {
window.grab_cursor(true).unwrap();
run_count = None;
}
}
},
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
input: winit::KeyboardInput {
virtual_keycode: Some(winit::VirtualKeyCode::Escape),
..
}, ..
} => return ControlFlow::Break,
_ => (),
},
_ => (),
}
run_count = run_count.map(|n| n + 1);
ControlFlow::Continue
});
} @Osspial are you still down to implement #459 on Windows? I'm ready to start this migration if you are. |
@francesca64 I am, yes. Sorry about disappearing for a few weeks there! I'm going to be away from any Windows machines until the end of the month starting next week, but I'll try to make the most progress I can in the next couple days. |
Ran into this same deadlock when resizing a window, which triggered a Focused, which my game uses to know when to grab the cursor. |
I added the code to winit that blocks during windows resize events, in order to fix visual bugs that happened when resizing a window (see #250). I don't think that's as important as making sure programs don't freeze, though! I'm pretty sure getting rid of that block would not only fix this but also fix #391, so we may want to remove it in the meantime while #459 gets hammered out. |
@Osspial if it's only a visual issue, then I'd definitely be in favor of that. |
Removing that code should be pretty simple so I'll see if I can get a PR up in the next day or so. |
It seems that this might be related to a freeze when I try to resize the window on Windows builds. No issues happen on Mac or Linux. A snippet to reproduce, using the latest pull from the winit repo:
A sample stacktrace from debug calls:
|
@Osspial do you know if the issue I've posted above is related to the blocking issue? It seems that you're one of the people who are most knowledgeable about the Windows backend. |
@hobogenized I don't think it's related. The previous issue would freeze the entire program, preventing Winit windows from being resized. It seems like a soft-lock is happening here that's still letting Windows process events (so resizing still works), it's just that those events aren't getting delivered to Winit. |
@Osspial Thanks for the feedback. Should I open up a new issue for easier tracking? |
@hobogenized Sure, that would be great! We can also close this issue since the issue it describes is resolved. cc @francesca64 |
Thanks! |
When I add the line
window.set_cursor(winit::CursorState:Grab).unwrap()
after the window build in fullscreen example and run it on windows then it fails.The window does not respond and windows ask to quit or wait.
The text was updated successfully, but these errors were encountered: