Skip to content

Commit 6027371

Browse files
authored
Merge pull request #25 from ProjectLighthouseCAU/unknown-events
Add support for unknown input events
2 parents dc04921 + a783fac commit 6027371

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ default-members = ["lighthouse-client"]
77
resolver = "2"
88

99
[workspace.package]
10-
version = "5.1.6"
10+
version = "6.0.0"
1111
edition = "2021"
1212
license = "MIT"
1313

1414
[workspace.dependencies]
15-
lighthouse-protocol = { version = "^5.1.6", path = "lighthouse-protocol" }
15+
lighthouse-protocol = { version = "^6.0.0", path = "lighthouse-protocol" }

lighthouse-protocol/src/input/input_event.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
22

33
use crate::Direction;
44

5-
use super::{EventSource, GamepadEvent, KeyEvent, MouseEvent};
5+
use super::{EventSource, GamepadEvent, KeyEvent, MouseEvent, UnknownEvent};
66

77
/// A user input event, as generated by the new frontend (LUNA).
88
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
@@ -11,6 +11,8 @@ pub enum InputEvent {
1111
Key(KeyEvent),
1212
Mouse(MouseEvent),
1313
Gamepad(GamepadEvent),
14+
#[serde(untagged)]
15+
Unknown(UnknownEvent),
1416
}
1517

1618
impl InputEvent {
@@ -20,6 +22,7 @@ impl InputEvent {
2022
InputEvent::Key(KeyEvent { source, .. }) => source,
2123
InputEvent::Mouse(MouseEvent { source, .. }) => source,
2224
InputEvent::Gamepad(GamepadEvent { source, .. }) => source,
25+
InputEvent::Unknown(UnknownEvent { source, .. }) => source,
2326
}
2427
}
2528

@@ -53,7 +56,7 @@ impl InputEvent {
5356
mod tests {
5457
use serde_json::json;
5558

56-
use crate::{Delta, EventSource, GamepadAxis2DEvent, GamepadAxisEvent, GamepadButtonEvent, GamepadControlEvent, GamepadEvent, InputEvent, KeyEvent, KeyModifiers, MouseButton, MouseEvent, Pos, Vec2};
59+
use crate::{Delta, EventSource, GamepadAxis2DEvent, GamepadAxisEvent, GamepadButtonEvent, GamepadControlEvent, GamepadEvent, InputEvent, KeyEvent, KeyModifiers, MouseButton, MouseEvent, Pos, UnknownEvent, Vec2};
5760

5861
#[test]
5962
fn key_event() {
@@ -174,4 +177,21 @@ mod tests {
174177
})
175178
);
176179
}
180+
181+
#[test]
182+
fn unknown_event() {
183+
assert_eq!(
184+
serde_json::from_value::<InputEvent>(json!({
185+
"type": "someEventWeDoNotKnowAbout",
186+
"source": 1,
187+
"possibly": "abc",
188+
"more": "def",
189+
"fields": "ghi"
190+
})).unwrap(),
191+
InputEvent::Unknown(UnknownEvent {
192+
source: EventSource::Int(1),
193+
event_type: "someEventWeDoNotKnowAbout".into(),
194+
})
195+
)
196+
}
177197
}

lighthouse-protocol/src/input/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod key_modifiers;
1010
mod legacy_input_event;
1111
mod mouse_button;
1212
mod mouse_event;
13+
mod unknown_event;
1314

1415
pub use event_source::*;
1516
pub use gamepad_axis_2d_event::*;
@@ -23,3 +24,4 @@ pub use key_modifiers::*;
2324
pub use legacy_input_event::*;
2425
pub use mouse_button::*;
2526
pub use mouse_event::*;
27+
pub use unknown_event::*;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use super::EventSource;
4+
5+
/// A gamepad/controller event.
6+
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
7+
#[serde(rename_all = "camelCase")]
8+
pub struct UnknownEvent {
9+
/// The event type.
10+
#[serde(rename = "type")]
11+
pub event_type: String,
12+
/// The client identifier. Also unique per gamepad.
13+
pub source: EventSource,
14+
}

0 commit comments

Comments
 (0)