Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow AccessKit to filter WindowEvents before they reach the engine. #10239

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ pub fn winit_runner(mut app: App) {
WindowAndInputEventWriters,
NonSend<WinitWindows>,
Query<(&mut Window, &mut CachedWindow)>,
NonSend<AccessKitAdapters>,
)> = SystemState::new(&mut app.world);

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -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 {
Expand All @@ -437,6 +438,18 @@ pub fn winit_runner(mut app: App) {
return;
};

// 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) {
// 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);
}
}

runner_state.window_event_received = true;

match event {
Expand Down Expand Up @@ -663,7 +676,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),
});
Expand Down
Loading