@@ -372,6 +372,7 @@ pub fn winit_runner(mut app: App) {
372
372
WindowAndInputEventWriters ,
373
373
NonSend < WinitWindows > ,
374
374
Query < ( & mut Window , & mut CachedWindow ) > ,
375
+ NonSend < AccessKitAdapters > ,
375
376
) > = SystemState :: new ( & mut app. world ) ;
376
377
377
378
#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -476,7 +477,7 @@ pub fn winit_runner(mut app: App) {
476
477
event:: Event :: WindowEvent {
477
478
event, window_id, ..
478
479
} => {
479
- let ( mut event_writers, winit_windows, mut windows) =
480
+ let ( mut event_writers, winit_windows, mut windows, access_kit_adapters ) =
480
481
event_writer_system_state. get_mut ( & mut app. world ) ;
481
482
482
483
let Some ( window_entity) = winit_windows. get_window_entity ( window_id) else {
@@ -495,6 +496,18 @@ pub fn winit_runner(mut app: App) {
495
496
return ;
496
497
} ;
497
498
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
+
498
511
runner_state. window_event_received = true ;
499
512
500
513
match event {
@@ -713,20 +726,20 @@ pub fn winit_runner(mut app: App) {
713
726
event : DeviceEvent :: MouseMotion { delta : ( x, y) } ,
714
727
..
715
728
} => {
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 ) ;
717
730
event_writers. mouse_motion . send ( MouseMotion {
718
731
delta : Vec2 :: new ( x as f32 , y as f32 ) ,
719
732
} ) ;
720
733
}
721
734
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 ) ;
723
736
event_writers. lifetime . send ( ApplicationLifetime :: Suspended ) ;
724
737
// Mark the state as `WillSuspend`. This will let the schedule run one last time
725
738
// before actually suspending to let the application react
726
739
runner_state. active = ActiveState :: WillSuspend ;
727
740
}
728
741
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 ) ;
730
743
match runner_state. active {
731
744
ActiveState :: NotYetStarted => {
732
745
event_writers. lifetime . send ( ApplicationLifetime :: Started ) ;
0 commit comments