rust-windowing / rust-windowing/winit
Windows cursor grabbing is bugged affecting bevy
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
Description
Description
I am working with bevy and experiencing this issue. https://github.com/bevyengine/bevy/issues/22750
Bevy main branch.
If the debug print is showing that the cursor is not grabbed I expect the mouse to not act confined. It is not letting my mouse leave the window even though its not grabbed. I minimized the code for you.
The issue is not present on linux.
use std::time::Duration;
use bevy::{
prelude::*,
window::{CursorGrabMode, CursorOptions, PrimaryWindow, WindowFocused},
};
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window { ..default() }),
..default()
}))
.add_systems(Update, (print_cursor, handle_focus_change))
.run();
}
fn print_cursor(
primary_cursor_options: Single<&mut CursorOptions, With<PrimaryWindow>>,
mut time_since_last_print: Local<Duration>,
time: Res<Time>,
) {
*time_since_last_print += time.delta();
if *time_since_last_print < Duration::from_secs(5) {
return;
}
println!("grabbed: {:?}", primary_cursor_options.grab_mode);
*time_since_last_print = Duration::ZERO;
}
fn handle_focus_change(
mut focus_events: MessageReader<WindowFocused>,
mut primary_cursor_options: Single<&mut CursorOptions, With<PrimaryWindow>>,
) {
for event in focus_events.read() {
if event.focused {
println!("gained focus");
primary_cursor_options.grab_mode = CursorGrabMode::Confined;
} else {
println!("lost focus");
primary_cursor_options.grab_mode = CursorGrabMode::None;
}
}
}
Windows version
Version 10.0.26100 Build 26100
OS Name Microsoft Windows 11 Pro
Winit version
0.30.12
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
Run the minimized Rust reproduction on Windows 11 with winit 0.30.12 first, using the CursorGrabMode and WindowFocused transitions shown in the issue. Trace the Windows-specific cursor-grab handling for the focus-loss path. Done means changing from Confined to None allows the pointer to leave the window, without regressing the reported Linux behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100