Skip to content

Commit e910eb3

Browse files
committed
Add InputEvent::source
1 parent 7b8ddbf commit e910eb3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lighthouse-protocol/src/input/input_event.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
use super::{GamepadEvent, KeyEvent, MouseEvent};
3+
use super::{EventSource, GamepadEvent, KeyEvent, MouseEvent};
44

55
/// A user input event, as generated by the new frontend (LUNA).
66
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
@@ -11,6 +11,17 @@ pub enum InputEvent {
1111
Gamepad(GamepadEvent),
1212
}
1313

14+
impl InputEvent {
15+
/// The event's source.
16+
pub fn source(&self) -> &EventSource {
17+
match self {
18+
InputEvent::Key(KeyEvent { source, .. }) => source,
19+
InputEvent::Mouse(MouseEvent { source, .. }) => source,
20+
InputEvent::Gamepad(GamepadEvent { source, .. }) => source,
21+
}
22+
}
23+
}
24+
1425
#[cfg(test)]
1526
mod tests {
1627
use serde_json::json;

0 commit comments

Comments
 (0)