bevyengine / bevyengine/bevy

Windows cursor grabbing is bugged

Open
#22,750 6 comments 0 reactions 0 assignees View on GitHub
A-Windowing C-Bug O-Windows S-Blocked
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version and features

0.18 main branch

## \[Optional\] Relevant system information

Windows 11

## What you did

Ran the attached code, hit the windows key to change focus, tried to move the cursor out of the window.

## What went wrong

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.

## Additional information

```rs
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>,
mut time_since_last_print: Local,
time: Res

fn handle_focus_change(
mut focus_events: MessageReader,
mut primary_cursor_options: Single<&mut CursorOptions, With>,
) {
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;
}
}
}

```

Contributor guide

Open the contributing guide

Research direction

Start by running the attached minimal Rust reproduction on Windows 11 and tracing the handle_focus_change system together with CursorOptions and WindowFocused handling. Compare the reported grab_mode with the actual cursor behavior after focus is lost; done means CursorGrabMode::None allows the cursor to leave the window, with the behavior verified across the focus change shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.