From bbf852f697e0c09b60706ab929053aecffbf2507 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 23 Oct 2023 07:49:28 -0500 Subject: [PATCH 1/6] Allow AccessKit to filter `WindowEvent`s before they reach the engine. --- crates/bevy_winit/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 3947b5020a867..b55f3931a20b5 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -437,6 +437,18 @@ pub fn winit_runner(mut app: App) { return; }; + // Allow AccessKit to filter `WindowEvent`s before they reach + // the engine. + if let Some(adapters) = app.world.get_non_send_resource::() { + if let Some(adapter) = adapters.get(&window_entity) { + if let Some(window) = winit_windows.get_window(window_entity) { + if !adapter.on_event(window, &event) { + return; + } + } + } + } + runner_state.window_event_received = true; match event { From 76eb94203696bc942cddd6d0fd829d5cbb734de3 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Mon, 23 Oct 2023 09:20:18 -0400 Subject: [PATCH 2/6] Rename created_windows_query to avoid ambiguity --- crates/bevy_winit/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index b55f3931a20b5..b9e08dedb7814 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -371,7 +371,7 @@ pub fn winit_runner(mut app: App) { #[cfg(not(target_arch = "wasm32"))] let ( commands, - mut windows, + mut created_windows_query, event_writer, winit_windows, adapters, @@ -382,7 +382,7 @@ pub fn winit_runner(mut app: App) { #[cfg(target_arch = "wasm32")] let ( commands, - mut windows, + mut created_windows_query, event_writer, winit_windows, adapters, @@ -394,7 +394,7 @@ pub fn winit_runner(mut app: App) { create_windows( event_loop, commands, - windows.iter_mut(), + created_windows_query.iter_mut(), event_writer, winit_windows, adapters, @@ -761,7 +761,7 @@ pub fn winit_runner(mut app: App) { #[cfg(not(target_arch = "wasm32"))] let ( commands, - mut windows, + mut created_windows_query, event_writer, winit_windows, adapters, @@ -772,7 +772,7 @@ pub fn winit_runner(mut app: App) { #[cfg(target_arch = "wasm32")] let ( commands, - mut windows, + mut created_windows_query, event_writer, winit_windows, adapters, @@ -784,7 +784,7 @@ pub fn winit_runner(mut app: App) { create_windows( event_loop, commands, - windows.iter_mut(), + created_windows_query.iter_mut(), event_writer, winit_windows, adapters, From 53390a16b2afb4e278c0624cb796b1626dedff6a Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Mon, 23 Oct 2023 09:23:04 -0400 Subject: [PATCH 3/6] Revert "Rename created_windows_query to avoid ambiguity" This reverts commit 76eb94203696bc942cddd6d0fd829d5cbb734de3. --- crates/bevy_winit/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index b9e08dedb7814..b55f3931a20b5 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -371,7 +371,7 @@ pub fn winit_runner(mut app: App) { #[cfg(not(target_arch = "wasm32"))] let ( commands, - mut created_windows_query, + mut windows, event_writer, winit_windows, adapters, @@ -382,7 +382,7 @@ pub fn winit_runner(mut app: App) { #[cfg(target_arch = "wasm32")] let ( commands, - mut created_windows_query, + mut windows, event_writer, winit_windows, adapters, @@ -394,7 +394,7 @@ pub fn winit_runner(mut app: App) { create_windows( event_loop, commands, - created_windows_query.iter_mut(), + windows.iter_mut(), event_writer, winit_windows, adapters, @@ -761,7 +761,7 @@ pub fn winit_runner(mut app: App) { #[cfg(not(target_arch = "wasm32"))] let ( commands, - mut created_windows_query, + mut windows, event_writer, winit_windows, adapters, @@ -772,7 +772,7 @@ pub fn winit_runner(mut app: App) { #[cfg(target_arch = "wasm32")] let ( commands, - mut created_windows_query, + mut windows, event_writer, winit_windows, adapters, @@ -784,7 +784,7 @@ pub fn winit_runner(mut app: App) { create_windows( event_loop, commands, - created_windows_query.iter_mut(), + windows.iter_mut(), event_writer, winit_windows, adapters, From ec09d2b46ac22b19c1b4b5f7827775b7a49c9c4b Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Mon, 23 Oct 2023 09:25:37 -0400 Subject: [PATCH 4/6] Fix borrow checking problem --- crates/bevy_winit/src/lib.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index b55f3931a20b5..f8d85e3dae060 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -311,6 +311,7 @@ pub fn winit_runner(mut app: App) { WindowAndInputEventWriters, NonSend, Query<(&mut Window, &mut CachedWindow)>, + NonSend, )> = SystemState::new(&mut app.world); #[cfg(not(target_arch = "wasm32"))] @@ -418,7 +419,7 @@ pub fn winit_runner(mut app: App) { event::Event::WindowEvent { event, window_id, .. } => { - let (mut event_writers, winit_windows, mut windows) = + let (mut event_writers, winit_windows, mut windows, access_kit_adapters) = event_writer_system_state.get_mut(&mut app.world); let Some(window_entity) = winit_windows.get_window_entity(window_id) else { @@ -439,12 +440,10 @@ pub fn winit_runner(mut app: App) { // Allow AccessKit to filter `WindowEvent`s before they reach // the engine. - if let Some(adapters) = app.world.get_non_send_resource::() { - if let Some(adapter) = adapters.get(&window_entity) { - if let Some(window) = winit_windows.get_window(window_entity) { - if !adapter.on_event(window, &event) { - return; - } + if let Some(adapter) = access_kit_adapters.get(&window_entity) { + if let Some(window) = winit_windows.get_window(window_entity) { + if !adapter.on_event(window, &event) { + return; } } } @@ -675,7 +674,7 @@ pub fn winit_runner(mut app: App) { event: DeviceEvent::MouseMotion { delta: (x, y) }, .. } => { - let (mut event_writers, _, _) = event_writer_system_state.get_mut(&mut app.world); + let (mut event_writers, ..) = event_writer_system_state.get_mut(&mut app.world); event_writers.mouse_motion.send(MouseMotion { delta: Vec2::new(x as f32, y as f32), }); From 3b1b3be48477a26cd56fd4ce46680a816b3e3f40 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sat, 28 Oct 2023 20:23:59 -0400 Subject: [PATCH 5/6] Don't filter events from AccessKit (yet) --- crates/bevy_winit/src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index f8d85e3dae060..5e94cae3b8222 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -438,13 +438,15 @@ pub fn winit_runner(mut app: App) { return; }; - // Allow AccessKit to filter `WindowEvent`s before they reach + // Allow AccessKit to respond to `WindowEvent`s before they reach // the engine. if let Some(adapter) = access_kit_adapters.get(&window_entity) { if let Some(window) = winit_windows.get_window(window_entity) { - if !adapter.on_event(window, &event) { - return; - } + // Somewhat surprisingly, this call has meaningful side effects + // See https://github.com/AccessKit/accesskit/issues/300 + // AccessKit might later need to filter events based on this, but we currently do not. + // See https://github.com/bevyengine/bevy/pull/10239#issuecomment-1775572176 + let _ = adapter.on_event(window, &event); } } From 5d8eb5a752591555e2deb13e6a86b7aafeed087b Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Fri, 3 Nov 2023 08:52:20 -0500 Subject: [PATCH 6/6] rustfmt --- crates/bevy_winit/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 5e94cae3b8222..be000b9f6dd14 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -442,7 +442,7 @@ pub fn winit_runner(mut app: App) { // the engine. if let Some(adapter) = access_kit_adapters.get(&window_entity) { if let Some(window) = winit_windows.get_window(window_entity) { - // Somewhat surprisingly, this call has meaningful side effects + // Somewhat surprisingly, this call has meaningful side effects // See https://github.com/AccessKit/accesskit/issues/300 // AccessKit might later need to filter events based on this, but we currently do not. // See https://github.com/bevyengine/bevy/pull/10239#issuecomment-1775572176