Skip to content

Commit d73e565

Browse files
mockersfndarilekAlice Cecilealice-i-cecile
authored andcommitted
Allow AccessKit to react to WindowEvents before they reach the engine (bevyengine#10356)
# Objective - Adopt bevyengine#10239 to get it in time for the release - Fix accessibility on macOS and linux ## Solution - call `on_event` from AcccessKit adapter on winit events --------- Co-authored-by: Nolan Darilek <[email protected]> Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Alice Cecile <[email protected]>
1 parent 2631f4c commit d73e565

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

crates/bevy_winit/src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ pub fn winit_runner(mut app: App) {
371371
WindowAndInputEventWriters,
372372
NonSend<WinitWindows>,
373373
Query<(&mut Window, &mut CachedWindow)>,
374+
NonSend<AccessKitAdapters>,
374375
)> = SystemState::new(&mut app.world);
375376

376377
#[cfg(not(target_arch = "wasm32"))]
@@ -475,7 +476,7 @@ pub fn winit_runner(mut app: App) {
475476
event::Event::WindowEvent {
476477
event, window_id, ..
477478
} => {
478-
let (mut event_writers, winit_windows, mut windows) =
479+
let (mut event_writers, winit_windows, mut windows, access_kit_adapters) =
479480
event_writer_system_state.get_mut(&mut app.world);
480481

481482
let Some(window_entity) = winit_windows.get_window_entity(window_id) else {
@@ -494,6 +495,18 @@ pub fn winit_runner(mut app: App) {
494495
return;
495496
};
496497

498+
// Allow AccessKit to respond to `WindowEvent`s before they reach
499+
// the engine.
500+
if let Some(adapter) = access_kit_adapters.get(&window_entity) {
501+
if let Some(window) = winit_windows.get_window(window_entity) {
502+
// Somewhat surprisingly, this call has meaningful side effects
503+
// See https://github.com/AccessKit/accesskit/issues/300
504+
// AccessKit might later need to filter events based on this, but we currently do not.
505+
// See https://github.com/bevyengine/bevy/pull/10239#issuecomment-1775572176
506+
let _ = adapter.on_event(window, &event);
507+
}
508+
}
509+
497510
runner_state.window_event_received = true;
498511

499512
match event {
@@ -712,20 +725,20 @@ pub fn winit_runner(mut app: App) {
712725
event: DeviceEvent::MouseMotion { delta: (x, y) },
713726
..
714727
} => {
715-
let (mut event_writers, _, _) = event_writer_system_state.get_mut(&mut app.world);
728+
let (mut event_writers, ..) = event_writer_system_state.get_mut(&mut app.world);
716729
event_writers.mouse_motion.send(MouseMotion {
717730
delta: Vec2::new(x as f32, y as f32),
718731
});
719732
}
720733
event::Event::Suspended => {
721-
let (mut event_writers, _, _) = event_writer_system_state.get_mut(&mut app.world);
734+
let (mut event_writers, ..) = event_writer_system_state.get_mut(&mut app.world);
722735
event_writers.lifetime.send(ApplicationLifetime::Suspended);
723736
// Mark the state as `WillSuspend`. This will let the schedule run one last time
724737
// before actually suspending to let the application react
725738
runner_state.active = ActiveState::WillSuspend;
726739
}
727740
event::Event::Resumed => {
728-
let (mut event_writers, _, _) = event_writer_system_state.get_mut(&mut app.world);
741+
let (mut event_writers, ..) = event_writer_system_state.get_mut(&mut app.world);
729742
match runner_state.active {
730743
ActiveState::NotYetStarted => {
731744
event_writers.lifetime.send(ApplicationLifetime::Started);

0 commit comments

Comments
 (0)