From 8a57094478829666c00232a5b3aca2255c5fefdd Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Fri, 30 May 2025 22:49:18 +0200 Subject: [PATCH] app_context: Remove useless monitors video modes checking --- src/core/app/context.rs | 64 +++++++---------------------------------- 1 file changed, 10 insertions(+), 54 deletions(-) diff --git a/src/core/app/context.rs b/src/core/app/context.rs index f7f8ec4..713a56b 100644 --- a/src/core/app/context.rs +++ b/src/core/app/context.rs @@ -14,6 +14,7 @@ use vulkano::{ use vulkano_util::{renderer::VulkanoWindowRenderer, window::VulkanoWindows}; use winit::{ event_loop::EventLoopProxy, + monitor::MonitorHandle, window::{Window, WindowId}, }; @@ -78,61 +79,10 @@ impl ApplicationContext { } } - /// Récupère les résolutions disponibles du moniteur (méthode utilitaire statique) - fn get_monitor_resolutions(window: &Window) -> Vec<(u32, u32)> { - // Première tentative : moniteur actuel - if let Some(monitor) = window.current_monitor() { - let resolutions = Self::extract_resolutions_from_monitor(&monitor); - if !resolutions.is_empty() { - log::debug!( - "Résolutions trouvées via moniteur actuel: {:?}", - resolutions - ); - return resolutions; - } - } - - // Deuxième tentative : tous les moniteurs disponibles - log::debug!("Tentative de récupération via tous les moniteurs disponibles..."); - let mut all_resolutions = Vec::new(); - - for monitor in window.available_monitors() { - let resolutions = Self::extract_resolutions_from_monitor(&monitor); - all_resolutions.extend(resolutions); - } - - if !all_resolutions.is_empty() { - // Supprime les doublons et trie - all_resolutions.sort_unstable(); - all_resolutions.dedup(); - all_resolutions.sort_by(|a, b| (b.0 * b.1).cmp(&(a.0 * a.1))); - - log::debug!( - "Résolutions trouvées via tous les moniteurs: {:?}", - all_resolutions - ); - return all_resolutions; - } - - // Aucune résolution détectée - retourne un vecteur vide - log::warn!("Aucune résolution détectée pour cette fenêtre"); - Vec::new() - } - /// Extrait les résolutions d'un moniteur donné - fn extract_resolutions_from_monitor( - monitor: &winit::monitor::MonitorHandle, - ) -> Vec<(u32, u32)> { + fn extract_resolutions_from_monitor(monitor: MonitorHandle) -> Vec<(u32, u32)> { let video_modes: Vec<_> = monitor.video_modes().collect(); - if video_modes.is_empty() { - log::debug!( - "Aucun mode vidéo trouvé pour le moniteur {:?}", - monitor.name() - ); - return Vec::new(); - } - let resolutions: Vec<(u32, u32)> = video_modes .into_iter() .map(|mode| { @@ -141,7 +91,7 @@ impl ApplicationContext { }) .collect(); - log::debug!( + log::trace!( "Modes vidéo trouvés pour {:?}: {:?}", monitor.name(), resolutions @@ -151,7 +101,13 @@ impl ApplicationContext { /// Récupère les résolutions disponibles pub fn get_available_resolutions(&self) -> Vec<(u32, u32)> { - self.with_renderer(|renderer| Self::get_monitor_resolutions(renderer.window())) + self.with_renderer(|renderer| { + renderer + .window() + .current_monitor() + .map(Self::extract_resolutions_from_monitor) + .unwrap_or_default() + }) } /// Récupère le delta time actuel depuis le timer