diff --git a/src-tauri/src/cursor/mod.rs b/src-tauri/src/cursor/mod.rs index e1e87e4..4d65315 100644 --- a/src-tauri/src/cursor/mod.rs +++ b/src-tauri/src/cursor/mod.rs @@ -21,7 +21,9 @@ pub struct CursorPosition { #[derive(Debug, Clone, Serialize, Deserialize, Default, Type)] #[serde(rename_all = "camelCase")] pub struct CursorPositions { + /// Absolute cursor coordinates in physical pixels. pub raw: CursorPosition, + /// Cursor coordinates normalized to the source monitor for scale-independent projection. pub mapped: CursorPosition, } @@ -180,6 +182,25 @@ mod tests { assert_eq!(snapshot.len(), 2); assert_eq!(snapshot["local"].raw.x, 3.0); } + + #[test] + fn physical_cursor_positions_normalize_across_display_scale_factors() { + let one_x = transform_coords(&CursorPosition { x: 720.0, y: 450.0 }, true, 1440.0, 900.0); + let two_x = transform_coords( + &CursorPosition { + x: 1440.0, + y: 900.0, + }, + true, + 2880.0, + 1800.0, + ); + + assert_eq!(one_x.x, 0.5); + assert_eq!(one_x.y, 0.5); + assert_eq!(two_x.x, one_x.x); + assert_eq!(two_x.y, one_x.y); + } } /// Stop cursor tracking and unregister all listeners. diff --git a/src/lib/bindings.ts b/src/lib/bindings.ts index 23e89c1..7e5786b 100644 --- a/src/lib/bindings.ts +++ b/src/lib/bindings.ts @@ -84,7 +84,15 @@ export type ConnectionState = "connecting" | "connected" | "disconnected" export type ConnectionStatus = { remoteId: string; address: string; name: string | null; state: ConnectionState } export type CursorPosition = { x: number; y: number } export type CursorPositionChanged = { positions: Partial<{ [key in string]: CursorPositions }> } -export type CursorPositions = { raw: CursorPosition; mapped: CursorPosition } +export type CursorPositions = { +/** + * Absolute cursor coordinates in physical pixels. + */ +raw: CursorPosition; +/** + * Cursor coordinates normalized to the source monitor for scale-independent projection. + */ +mapped: CursorPosition } export type ForegroundAppChanged = { meta: AppMeta } export type FriendForegroundAppChanged = { friendId: string; meta: AppMeta } export type FriendsChanged = { friends: User[] } diff --git a/src/routes/scene/+page.svelte b/src/routes/scene/+page.svelte index 59b4c34..56b3cc2 100644 --- a/src/routes/scene/+page.svelte +++ b/src/routes/scene/+page.svelte @@ -1,12 +1,35 @@
- diff --git a/static/fa.png b/static/fa.png new file mode 100644 index 0000000..8a0be5b Binary files /dev/null and b/static/fa.png differ