support keyboard input on wayland and android properly

This commit is contained in:
griffi-gh 2024-09-01 14:59:19 +02:00
parent 097bdc29ff
commit bb4d2a80bf
2 changed files with 22 additions and 4 deletions

View file

@ -48,8 +48,9 @@ ndk = "0.9"
winapi = { version = "0.3", features = ["wincon"] }
[features]
default = ["raw-evt"]
raw-evt = [] #required for mouse input, but breaks keyboard on android
default = ["raw-evt-mouse"]
raw-evt-keyboard = [] # use raw input for keyboard. works on x11 and windows, breaks keyboard on android and wayland
raw-evt-mouse = [] # required for mouse input
generate_visualizer_data = ["dep:serde_json", "shipyard/serde1"]
safe_lz4 = ["lz4_flex/safe-encode", "lz4_flex/safe-decode"]
parallel = ["shipyard/parallel"] # causes some serious issues!

View file

@ -34,8 +34,12 @@ pub fn process_winit_events(world: &mut World, event: &Event<()>) {
));
},
#[cfg(not(feature = "raw-evt"))]
#[cfg(not(feature = "raw-evt-keyboard"))]
WindowEvent::KeyboardInput { device_id, event, .. } => {
// HACK: translate KeyboardInput events to raw device events
if event.repeat {
return;
}
world.add_entity((
EventComponent,
InputDeviceEvent {
@ -63,8 +67,21 @@ pub fn process_winit_events(world: &mut World, event: &Event<()>) {
_ => ()
},
#[cfg(feature = "raw-evt")]
#[cfg(any(
feature = "raw-evt-keyboard",
feature = "raw-evt-mouse",
))]
Event::DeviceEvent { device_id, event } => {
// Filter out events we don't care about
match event {
#[cfg(feature = "raw-evt-keyboard")]
DeviceEvent::Key(_) => (),
#[cfg(feature = "raw-evt-mouse")]
DeviceEvent::MouseMotion { .. } | DeviceEvent::Button { .. } => (),
_ => return,
};
world.add_entity((
EventComponent,
InputDeviceEvent {