Skip to content

Commit a1681f4

Browse files
mockersfndarilekAlice Cecilealice-i-cecile
authored
Allow AccessKit to react to WindowEvents before they reach the engine (#10356)
# Objective - Adopt #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 <nolan@thewordnerd.info> Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
1 parent 708569c commit a1681f4

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
@@ -372,6 +372,7 @@ pub fn winit_runner(mut app: App) {
372372
WindowAndInputEventWriters,
373373
NonSend<WinitWindows>,
374374
Query<(&mut Window, &mut CachedWindow)>,
375+
NonSend<AccessKitAdapters>,
375376
)> = SystemState::new(&mut app.world);
376377

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

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

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

500513
match event {
@@ -713,20 +726,20 @@ pub fn winit_runner(mut app: App) {
713726
event: DeviceEvent::MouseMotion { delta: (x, y) },
714727
..
715728
} => {
716-
let (mut event_writers, _, _) = event_writer_system_state.get_mut(&mut app.world);
729+
let (mut event_writers, ..) = event_writer_system_state.get_mut(&mut app.world);
717730
event_writers.mouse_motion.send(MouseMotion {
718731
delta: Vec2::new(x as f32, y as f32),
719732
});
720733
}
721734
event::Event::Suspended => {
722-
let (mut event_writers, _, _) = event_writer_system_state.get_mut(&mut app.world);
735+
let (mut event_writers, ..) = event_writer_system_state.get_mut(&mut app.world);
723736
event_writers.lifetime.send(ApplicationLifetime::Suspended);
724737
// Mark the state as `WillSuspend`. This will let the schedule run one last time
725738
// before actually suspending to let the application react
726739
runner_state.active = ActiveState::WillSuspend;
727740
}
728741
event::Event::Resumed => {
729-
let (mut event_writers, _, _) = event_writer_system_state.get_mut(&mut app.world);
742+
let (mut event_writers, ..) = event_writer_system_state.get_mut(&mut app.world);
730743
match runner_state.active {
731744
ActiveState::NotYetStarted => {
732745
event_writers.lifetime.send(ApplicationLifetime::Started);

0 commit comments

Comments
 (0)