From 60aea1e4249dec279251dd43896a9b6b2a81e504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Fri, 20 Jan 2023 10:22:28 +0100 Subject: [PATCH 1/3] break feedback loop when moving cursor --- crates/bevy_winit/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index ff4eda67c5260..ab57d8040d251 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -396,7 +396,9 @@ pub fn winit_runner(mut app: App) { window.resolution.physical_height() as f64 - position.y, ); - window.set_physical_cursor_position(Some(physical_position)); + window + .bypass_change_detection() + .set_physical_cursor_position(Some(physical_position)); cursor_events.cursor_moved.send(CursorMoved { window: window_entity, @@ -412,7 +414,9 @@ pub fn winit_runner(mut app: App) { WindowEvent::CursorLeft { .. } => { // Component if let Ok((mut window, _)) = window_query.get_mut(window_entity) { - window.set_physical_cursor_position(None); + window + .bypass_change_detection() + .set_physical_cursor_position(None); } cursor_events.cursor_left.send(CursorLeft { From 76ff059c7a5b9f54f0982e651b88b2b4bc239375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Fri, 20 Jan 2023 11:16:50 +0100 Subject: [PATCH 2/3] do not change every window every frame in scene viewer --- examples/tools/scene_viewer/camera_controller_plugin.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/tools/scene_viewer/camera_controller_plugin.rs b/examples/tools/scene_viewer/camera_controller_plugin.rs index 701947bb775e8..2c2dcac4522bf 100644 --- a/examples/tools/scene_viewer/camera_controller_plugin.rs +++ b/examples/tools/scene_viewer/camera_controller_plugin.rs @@ -177,7 +177,8 @@ fn camera_controller( for mouse_event in mouse_events.iter() { mouse_delta += mouse_event.delta; } - } else { + } + if mouse_button_input.just_released(options.mouse_key_enable_mouse) { for mut window in &mut windows { window.cursor.grab_mode = CursorGrabMode::None; window.cursor.visible = true; From 7b40cec57bec35fdd5a37497a621ee95b6177079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Fri, 20 Jan 2023 18:16:16 +0100 Subject: [PATCH 3/3] comments --- crates/bevy_winit/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index ab57d8040d251..84303caaa1c99 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -396,6 +396,8 @@ pub fn winit_runner(mut app: App) { window.resolution.physical_height() as f64 - position.y, ); + // bypassing change detection to not trigger feedback loop with system `changed_window` + // this system change the cursor position in winit window .bypass_change_detection() .set_physical_cursor_position(Some(physical_position)); @@ -414,6 +416,8 @@ pub fn winit_runner(mut app: App) { WindowEvent::CursorLeft { .. } => { // Component if let Ok((mut window, _)) = window_query.get_mut(window_entity) { + // bypassing change detection to not trigger feedback loop with system `changed_window` + // this system change the cursor position in winit window .bypass_change_detection() .set_physical_cursor_position(None);