From da16b075618b792458bbb9ca19e856e9c4189c66 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 18:00:25 +0400 Subject: fix(input): keep absolute mouse positions out of cockpit look --- adapters/fparkan-platform-winit/src/lib.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'adapters/fparkan-platform-winit/src/lib.rs') diff --git a/adapters/fparkan-platform-winit/src/lib.rs b/adapters/fparkan-platform-winit/src/lib.rs index 5307ee68..57ca827f 100644 --- a/adapters/fparkan-platform-winit/src/lib.rs +++ b/adapters/fparkan-platform-winit/src/lib.rs @@ -9,6 +9,10 @@ pub mod text; #[allow(unsafe_code)] pub mod startup_window; +#[cfg(windows)] +#[allow(unsafe_code)] +mod raw_mouse; + use fparkan_platform::{ EventSource, MonotonicClock, MonotonicInstant, NativeWindowHandles, PhysicalSize, PlatformError, PlatformEvent, RenderRequest, WindowHandle, WindowPort, @@ -19,6 +23,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::OnceLock; use std::time::Instant; use winit::event::{Event, MouseButton, WindowEvent}; +use winit::event_loop::EventLoop; use winit::platform::scancode::PhysicalKeyExtScancode; use winit::window::Window; @@ -31,6 +36,18 @@ fn next_window_id() -> u64 { NEXT_WINDOW_HANDLE_ID.fetch_add(1, Ordering::Relaxed) } +/// Builds the event loop used by the game and its relative camera controls. +pub fn new_game_event_loop() -> Result, winit::error::EventLoopError> { + #[cfg(windows)] + { + let mut builder = EventLoop::builder(); + raw_mouse::ignore_absolute_motion(&mut builder); + builder.build() + } + #[cfg(not(windows))] + EventLoop::new() +} + /// Simple monotonic clock for windowing abstractions. #[derive(Clone, Copy, Debug)] pub struct WinitClock; @@ -561,5 +578,3 @@ mod tests { assert!(window.is_occluded()); } } - -// SAFETY: no unsafe usage in this crate. -- cgit v1.2.3