bevyengine / bevyengine/bevy

set_cursor_position fails if CursorGrabMode is changed from Confined to None on the same frame

Open
#20,792 1 comment 2 reactions 0 assignees View on GitHub
A-Windowing C-Bug D-Modest S-Needs-Investigation X-Uncontroversial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version and features

Bevy 0.16.1, Windows 10, Rust 1.88.0

## What you did

When changing `CursorGrabMode::Confined` to `CursorGrabMode::None` on Windows, the cursor will appear in the center of the screen.

If you use `set_cursor_position()` on the same frame, it won't do anything - the cursor will remain in the center of the screen, instead of the location you specified.

The behavior I expected was that, if called on the same frame, `set_cursor_position` functionality would override the default cursor starting position (or that there might exist a way to specify the location of where the cursor should appear when changing `CursorGrabMode` like this).

## Additional information

A workaround is to change `CursorGrabMode::Confined` to `CursorGrabMode::None`, and then wait one frame before calling `set_cursor_position()`. This works but is a bit unergonomic and adds a bit of code complexity. It also requires you to make sure that the cursor is invisible until the second frame when the position is set, or it will flash onscreen for a frame in an unappealing way.

(I'm unsure if this issue belongs here or on the `winit` github; if the latter, sorry, and please let me know so I can post it there.)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.