From e3c74485f1d3d2aff94de2a12486cf34c4bce0ed Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 25 Jun 2026 07:51:35 +0400 Subject: feat(platform-winit): bridge native window events --- adapters/fparkan-platform-winit/src/lib.rs | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/adapters/fparkan-platform-winit/src/lib.rs b/adapters/fparkan-platform-winit/src/lib.rs index 729ccb6..19de207 100644 --- a/adapters/fparkan-platform-winit/src/lib.rs +++ b/adapters/fparkan-platform-winit/src/lib.rs @@ -300,6 +300,27 @@ impl WinitWindow { self.apply_event(event); } } + + /// Applies one native `winit` window event to the cached window descriptor state. + pub fn apply_window_event(&mut self, event: &WindowEvent) { + match event { + WindowEvent::Resized(size) => { + self.width = size.width; + self.height = size.height; + self.minimized = size.width == 0 || size.height == 0; + } + WindowEvent::Focused(focused) => { + self.focused = *focused; + } + WindowEvent::Occluded(occluded) => { + self.occluded = *occluded; + } + WindowEvent::ScaleFactorChanged { scale_factor, .. } => { + self.scale = *scale_factor; + } + _ => {} + } + } } impl WindowPort for WinitWindow { @@ -528,6 +549,28 @@ mod tests { assert!(window.is_minimized()); assert!(window.is_occluded()); } + + #[test] + fn window_descriptor_applies_native_window_events() { + let mut window = WinitWindow::synthetic(640, 360); + + window.apply_window_event(&WindowEvent::Resized(winit::dpi::PhysicalSize::new( + 0u32, 720u32, + ))); + window.apply_window_event(&WindowEvent::Focused(false)); + window.apply_window_event(&WindowEvent::Occluded(true)); + + assert_eq!( + window.drawable_size(), + PhysicalSize { + width: 0, + height: 720, + } + ); + assert!(!window.has_focus()); + assert!(window.is_minimized()); + assert!(window.is_occluded()); + } } // SAFETY: no unsafe usage in this crate. -- cgit v1.2.3