-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Bevy version
16.0 to main
Relevant system information
Linux kernel 6.15.2 on Wayland (built with wayland
feature)
What you did
Assume a standard Linux setup under wayland with the following code. In Setup
, it sets the cursor mode to Locked
, and in every update
, the cursor position is set with window.set_cursor_position
.
This results in an error:
2025-06-25T21:13:38.781498Z ERROR bevy_winit::system: could not set cursor position: os error at /home/doomy/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winit-0.30.11/src/platform_impl/linux/wayland/window/state.rs:901: cursor position can be set only for locked cursor.
This is confusing, as the cursor position is set to locked.
use bevy::{prelude::*, window::CursorGrabMode, window::CursorOptions};
fn main() {
App::new().add_plugins(ClientPlugin).run();
}
pub struct ClientPlugin;
impl Plugin for ClientPlugin {
fn build(&self, app: &mut App) {
// ...
app.add_plugins(DefaultPlugins);
app.add_systems(Startup, setup_cursor);
app.add_systems(Update, recenter_cursor);
}
}
fn setup_cursor(mut windows: Query<(&mut Window, &mut CursorOptions)>) {
let Ok((mut window, mut cursor_options)) = windows.single_mut() else {
panic!();
};
cursor_options.visible = true;
cursor_options.grab_mode = CursorGrabMode::Locked;
let center = Vec2::new(window.width() / 2., window.height() / 2.);
window.set_cursor_position(Some(center));
}
fn recenter_cursor(mut windows: Query<&mut Window>) {
let Ok(mut window) = windows.single_mut() else {
panic!();
};
let center = Vec2::new(window.width() / 2., window.height() / 2.);
window.set_cursor_position(Some(center));
}
What went wrong
Expectation: The cursor should be locked and allowed to be set to a specific position, in this case, the center of the screen.
Actual: The cursor is locked in place, but is not placed in the center, and an error is emitted.
Additional information
It was suggested that the system ordering here may be at fault, as the cursor mode is set after window properties. However, after reordering the systems locally, the same issue persisted.