bevy/crates
Alix Bott b054d116a6
Replace winit's synthetic events by our own key tracking (#14379)
# Objective

Defocusing a window while a key is held (such as when Alt+tabbing), will
currently send a key release on X11 and Windows. This is likely the
behavior that most people expect.
However it's synthetic events from winit are unimplemented for WASM and
some other platforms. (See
https://github.com/rust-windowing/winit/issues/1272).
While we can implement it upstream, there is also some doubt about the
synthetic events API as a whole
(https://github.com/rust-windowing/winit/issues/3543), so I propose to
do it in bevy directly for now.

## Solution

This PR implements key tracking in bevy directly so we can synthesize
our own key release events across all platforms.

Note regarding X11 specifically:
- On `main`, pressing a keyboard shortcut to unfocus the window (`Ctrl +
Super + ArrowRight` in my case) will yield the following events:
```
Pressed Control
Pressed Super
Released Control
Released ArrowRight
Released Super
```
- On this branch, it will yield the following sequence:
```
Pressed Control
Pressed Super
Released Control
Released Super
```
To me the behavior of this branch is more expected than `main`, because
`main` produces an `ArrowRight` release without producing a press first.

## Testing

Tested in WASM and X11 with
```rust
App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Update, |mut keys: EventReader<KeyboardInput>| {
            for ev in keys.read() {
                error!("received {ev:?}");
            }
        })
        .run();
```
2025-03-10 21:11:29 +00:00
..
bevy_a11y Automatically enable portable-atomic when required (#17570) 2025-02-24 20:52:46 +00:00
bevy_animation Update petgraph requirement from 0.6 to 0.7 (#18224) 2025-03-10 07:12:27 +00:00
bevy_app Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_asset Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_audio Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_color Allow bevy_reflect and wgpu-types features in no_std for bevy_color (#18061) 2025-03-01 00:31:35 +00:00
bevy_core_pipeline Partially fix panics when setting WGPU_SETTINGS_PRIO=webgl2 (#18113) 2025-03-09 20:14:27 +00:00
bevy_derive allow Call and Closure expressions in hook macro attributes (#18017) 2025-03-06 16:39:11 +00:00
bevy_dev_tools Make Query::single (and friends) return a Result (#18082) 2025-03-02 19:51:56 +00:00
bevy_diagnostic Add no_std support to bevy (#17955) 2025-03-07 03:39:46 +00:00
bevy_dylib Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_ecs Remove lifetime from QueryEntityError (#18157) 2025-03-09 20:05:22 +00:00
bevy_encase_derive Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_gilrs Replace some !Send resources with thread_local! (#17730) 2025-03-04 07:48:02 +00:00
bevy_gizmos Improve Segment2d/Segment3d API and docs (#18206) 2025-03-09 20:21:31 +00:00
bevy_gltf Add no_std support to bevy (#17955) 2025-03-07 03:39:46 +00:00
bevy_image Add no_std support to bevy (#17955) 2025-03-07 03:39:46 +00:00
bevy_input Fix Component require() IDE integration (#18165) 2025-03-06 02:44:47 +00:00
bevy_input_focus Make Query::single (and friends) return a Result (#18082) 2025-03-02 19:51:56 +00:00
bevy_internal Add support for experimental WESL shader source (#17953) 2025-03-09 19:26:55 +00:00
bevy_log Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_macro_utils Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_math Improve Segment2d/Segment3d API and docs (#18206) 2025-03-09 20:21:31 +00:00
bevy_mesh Fix mesh tangent attribute matching in mesh transform operations (#17992) 2025-03-07 17:39:42 +00:00
bevy_mikktspace Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_pbr Parallelize prepare_assets::<T> systems (#17914) 2025-03-10 05:01:12 +00:00
bevy_picking Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_platform_support Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_ptr moved Debug from derive to impl_ptr in bevy_ptr (#18042) 2025-02-28 02:54:46 +00:00
bevy_reflect Update petgraph requirement from 0.6 to 0.7 (#18224) 2025-03-10 07:12:27 +00:00
bevy_remote BRP resource methods (#17423) 2025-02-26 20:29:47 +00:00
bevy_render Parallelize prepare_assets::<T> systems (#17914) 2025-03-10 05:01:12 +00:00
bevy_scene Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_sprite Add no_std support to bevy (#17955) 2025-03-07 03:39:46 +00:00
bevy_state Automatically enable portable-atomic when required (#17570) 2025-02-24 20:52:46 +00:00
bevy_tasks Support for non-browser wasm (#17499) 2025-03-07 21:22:28 +00:00
bevy_text Add byte information to PositionedGlyph (#17900) 2025-03-08 16:35:01 +00:00
bevy_time Add no_std support to bevy (#17955) 2025-03-07 03:39:46 +00:00
bevy_transform Transform Propagation Optimization: Static Subtree Marking (#18093) 2025-03-09 19:29:01 +00:00
bevy_ui UiTargetCamera doc comment correction (#18216) 2025-03-09 22:48:52 +00:00
bevy_utils Automatically enable portable-atomic when required (#17570) 2025-02-24 20:52:46 +00:00
bevy_window Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
bevy_winit Replace winit's synthetic events by our own key tracking (#14379) 2025-03-10 21:11:29 +00:00