Skip to content

On wasm, window.cursor.grab_mode is not updated when cursor is unlocked. #8949

Open
@sarahkittyy

Description

@sarahkittyy

Bevy version

0.10.1

What you did

Using examples/input/mouse_grab.rs:

fn grab_mouse(
    mut windows: Query<&mut Window>,
    mouse: Res<Input<MouseButton>>,
    key: Res<Input<KeyCode>>,
) {
    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', /* ... */)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WindowingPlatform-agnostic interface layer to run your app inC-BugAn unexpected or incorrect behaviorO-WebSpecific to web (WASM) buildsS-BlockedThis cannot move forward until something else changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions