bevyengine / bevyengine/bevy

window.cursor_position() is None after hitting alt+[a-z]

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

Description

## Bevy version and features

I have noticed this since i started using bevy from 0.16,0.17,0.18

## \[Optional\] Relevant system information

this bug only happens on windows, notably does not occur even in wine

## What you did

hit alt and any other character, for this i only tested [a-z], also ctrl+alt+[a-z] does not have this bug occur

## What went wrong

window.cursor_position() becomes None until the mouse cursor moves

if this is expected the description for cursor_position should be updated as currently it does not describe this behaviour

```
/// The cursor position in this window in logical pixels.
///
/// Returns `None` if the cursor is outside the window area.
///
/// See [`WindowResolution`] for an explanation about logical/physical sizes.
```

## Additional information

minimal working example, when hitting alt+b for example the circle goes to the top left of the screen

```
use bevy::prelude::*;
use bevy::window::PrimaryWindow;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, update)
.run();
}
pub fn setup(
mut commands: Commands,
mut meshes: ResMut>,
mut materials: ResMut>,
) {
commands.spawn(Camera2d);
commands.spawn((
Mesh2d(meshes.add(Circle::new(32.0))),
MeshMaterial2d(materials.add(Color::WHITE)),
Transform::from_xyz(0.0, 0.0, 0.0),
));
}
pub fn update(
mut transform: Single<&mut Transform, With>,
window: Single<&Window, With>,
camera: Single<(&Camera, &GlobalTransform)>,
) {
let pos = if let Some(cursor_position) = window.cursor_position() {
cursor_position
} else {
Vec2::splat(0.0)
};
if let Ok(new) = camera.0.viewport_to_world_2d(camera.1, pos) {
transform.translation.x = new.x;
transform.translation.y = new.y;
} else {
transform.translation = Vec3::splat(0.0);
}
}
```

Contributor guide

Open the contributing guide

Research direction

Run the minimal example on Windows and reproduce the loss of Window::cursor_position() after Alt+[a-z], then inspect the window cursor-position handling around that entry point. Done means the cursor position no longer becomes None until mouse movement, or the cursor_position documentation accurately describes the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.