From 9c1d508eb6e72040a0b3875e0a5bdde48f4d598e Mon Sep 17 00:00:00 2001 From: fwcd Date: Fri, 7 Mar 2025 02:47:57 +0100 Subject: [PATCH 1/5] Add MouseEvent::movement --- lighthouse-protocol/src/input/mouse_event.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lighthouse-protocol/src/input/mouse_event.rs b/lighthouse-protocol/src/input/mouse_event.rs index d09ece0..e0f287e 100644 --- a/lighthouse-protocol/src/input/mouse_event.rs +++ b/lighthouse-protocol/src/input/mouse_event.rs @@ -12,6 +12,8 @@ pub struct MouseEvent { pub source: EventSource, /// The mouse button. pub button: MouseButton, - /// The mouse position. + /// The mouse position on the lighthouse grid. pub pos: Pos, + /// The mouse movement on the lighthouse grid. + pub movement: Pos, } From aaca230b624aebf8f2e81ed52123e5a1004b46e1 Mon Sep 17 00:00:00 2001 From: fwcd Date: Fri, 7 Mar 2025 02:48:17 +0100 Subject: [PATCH 2/5] Add missing MouseEvent::down Not sure why we forgot this one --- lighthouse-protocol/src/input/mouse_event.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lighthouse-protocol/src/input/mouse_event.rs b/lighthouse-protocol/src/input/mouse_event.rs index e0f287e..ee3fd0a 100644 --- a/lighthouse-protocol/src/input/mouse_event.rs +++ b/lighthouse-protocol/src/input/mouse_event.rs @@ -10,6 +10,8 @@ use super::{EventSource, MouseButton}; pub struct MouseEvent { /// The client identifier. pub source: EventSource, + /// Whether the button was pressed. + pub down: bool, /// The mouse button. pub button: MouseButton, /// The mouse position on the lighthouse grid. From 282e6ecb119cdab0a45d50d0ce45d28c18d0cdf1 Mon Sep 17 00:00:00 2001 From: fwcd Date: Fri, 7 Mar 2025 02:48:44 +0100 Subject: [PATCH 3/5] Add MouseEvent::pointer_locked --- lighthouse-protocol/src/input/mouse_event.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lighthouse-protocol/src/input/mouse_event.rs b/lighthouse-protocol/src/input/mouse_event.rs index ee3fd0a..61ff12c 100644 --- a/lighthouse-protocol/src/input/mouse_event.rs +++ b/lighthouse-protocol/src/input/mouse_event.rs @@ -12,6 +12,8 @@ pub struct MouseEvent { pub source: EventSource, /// Whether the button was pressed. pub down: bool, + /// Whether the mouse pointer was locked (e.g. to the frontend's canvas) + pub pointer_locked: bool, /// The mouse button. pub button: MouseButton, /// The mouse position on the lighthouse grid. From 79add1f5ff049941b578cfe9471884ab6abf65f6 Mon Sep 17 00:00:00 2001 From: fwcd Date: Fri, 7 Mar 2025 02:48:56 +0100 Subject: [PATCH 4/5] More accurately describe movement as a Delta --- lighthouse-protocol/src/input/mouse_event.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lighthouse-protocol/src/input/mouse_event.rs b/lighthouse-protocol/src/input/mouse_event.rs index 61ff12c..9d61462 100644 --- a/lighthouse-protocol/src/input/mouse_event.rs +++ b/lighthouse-protocol/src/input/mouse_event.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::Pos; +use crate::{Delta, Pos}; use super::{EventSource, MouseButton}; @@ -19,5 +19,5 @@ pub struct MouseEvent { /// The mouse position on the lighthouse grid. pub pos: Pos, /// The mouse movement on the lighthouse grid. - pub movement: Pos, + pub movement: Delta, } From 8b46e91fbae7d3912945645e8d201eca38c871ba Mon Sep 17 00:00:00 2001 From: fwcd Date: Fri, 7 Mar 2025 02:53:19 +0100 Subject: [PATCH 5/5] Update tests --- lighthouse-protocol/src/input/input_event.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lighthouse-protocol/src/input/input_event.rs b/lighthouse-protocol/src/input/input_event.rs index fa2d7f2..0fe5fd8 100644 --- a/lighthouse-protocol/src/input/input_event.rs +++ b/lighthouse-protocol/src/input/input_event.rs @@ -53,7 +53,7 @@ impl InputEvent { mod tests { use serde_json::json; - use crate::{EventSource, GamepadAxis2DEvent, GamepadAxisEvent, GamepadButtonEvent, GamepadControlEvent, GamepadEvent, InputEvent, KeyEvent, KeyModifiers, MouseButton, MouseEvent, Pos, Vec2}; + use crate::{Delta, EventSource, GamepadAxis2DEvent, GamepadAxisEvent, GamepadButtonEvent, GamepadControlEvent, GamepadEvent, InputEvent, KeyEvent, KeyModifiers, MouseButton, MouseEvent, Pos, Vec2}; #[test] fn key_event() { @@ -88,15 +88,24 @@ mod tests { "type": "mouse", "source": 1, "button": "left", + "down": true, + "pointerLocked": false, "pos": { "x": 2, "y": 4, }, + "movement": { + "x": 6, + "y": -3, + }, })).unwrap(), InputEvent::Mouse(MouseEvent { source: EventSource::Int(1), button: MouseButton::Left, + down: true, + pointer_locked: false, pos: Pos::new(2.0, 4.0), + movement: Delta::new(6.0, -3.0), }) ); }