bevyengine / bevyengine/bevy

Error setting CursorGrabMode after unfocusing the window and switching from Locked/Confined to None, then switching back

Open
#16,238 1 comment 0 reactions 0 assignees View on GitHub
A-Windowing C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version
0.14.2

## \[Optional\] Relevant system information
Ubuntu 22.04.2 LTS
X11

## What you did
I am trying to set my cursor's CursorGrabMode to either Locked or Confined after switching tabs (and setting the CursorGrabMode to None) then switching back (and changing to Locked or Confined).

```
pub fn lock_mouse(mut primary_window: Query<&mut Window, With>) {
let window = &mut primary_window.single_mut();
if window.focused {
if window.position != WindowPosition::Automatic {
window.cursor.grab_mode = CursorGrabMode::Confined;
}
} else {
window.cursor.grab_mode = CursorGrabMode::None;
}
}

```
Note: The check for WindowPosition::Automatic is a workaround for another bug #16237

## What went wrong
with grabmode set to confined the mouse is not confined to the window and I get this error
```
ERROR bevy_winit::winit_windows: Unable to grab cursor: the requested operation is not supported by Winit
```
with grabmode locked the same thing happens and I get this error
```
ERROR bevy_winit::winit_windows: Unable to grab cursor: os error at /home/knar/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform_impl/linux/x11/window.rs:1551: Cursor could not be confined: already confined by another client
```

## Additional information
I haven't found a workaround for this issue yet :(

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the cursor-grab transition in Bevy 0.14.2 on Ubuntu 22.04 with X11, using the issue's lock_mouse example. Inspect bevy_winit::winit_windows and the referenced winit X11 window code around cursor confinement. Done means switching focus with grab mode set to None and back to Locked or Confined works without the reported errors.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.