On wasm, window.cursor.grab_mode is not updated when cursor is unlocked.
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.10.1
## What you did
Using `examples/input/mouse_grab.rs`:
```rust
fn grab_mouse(
mut windows: Query<&mut Window>,
mouse: Res>,
key: Res>,
) {
let mut window = windows.single_mut();
if mouse.just_pressed(MouseButton::Left) {
window.cursor.visible = false;
window.cursor.grab_mode = CursorGrabMode::Locked;
}
if key.just_pressed(KeyCode::Escape) {
window.cursor.visible = true;
window.cursor.grab_mode = CursorGrabMode::None;
}
}
```
Left clicking on the canvas will lock the cursor. Hitting escape will unlock the cursor.
However, this is handled by the browser only, and the Escape key event is never actually sent to bevy. `window.cursor.grab_mode` will still be `Locked`. Left-clicking at this point will do nothing, as `grab_mode` is already `Locked` and no state is changed.
Clicking Hitting escape a *second* time will then set `grab_mode = None`, allowing you to re-lock by clicking.
## What went wrong
- The browser detaching your cursor should be picked up by bevy and grab_mode should be set to None, or at the very least an event should be emitted.
## Additional information
- In JS, you can listen to the change with `document.addEventListener('pointerlockchange', /* ... */)`
Contributor guide
Assessment
This issue has not been assessed yet.