diff --git a/src/tui/widgets/popups/global_settings.rs b/src/tui/widgets/popups/global_settings.rs index 46514dd..fc23afa 100644 --- a/src/tui/widgets/popups/global_settings.rs +++ b/src/tui/widgets/popups/global_settings.rs @@ -460,13 +460,9 @@ impl State { } fn apply_default_resolution(&mut self) { - if let Some(resolution) = default_resolution(&self.display_resolutions) { - self.config.defaults.resolution = Some(resolution); - self.save_pending = true; - self.error = None; - } else { - self.error = Some("Display resolution could not be detected.".to_owned()); - } + self.config.defaults.resolution = Some(default_resolution()); + self.save_pending = true; + self.error = None; } fn enable_auto_image_protocol(&mut self) { @@ -1110,10 +1106,7 @@ fn global_field_line(state: &State, index: usize, label: &str) -> Line<'static> if index == 2 && state.config.ui.image_protocol == ImageProtocol::Auto && !editing { spans.extend([Span::raw(" "), auto_label()]); } - if index == 7 - && !editing - && is_default_resolution(state.config.defaults.resolution, &state.display_resolutions) - { + if index == 7 && !editing && is_default_resolution(state.config.defaults.resolution) { spans.extend([Span::raw(" "), default_label()]); } if index == 10 && !editing { @@ -1369,7 +1362,7 @@ mod tests { state.handle_key(&KeyEvent::from(KeyCode::Char('d'))), Action::Save(..) )); - assert_eq!(state.config.defaults.resolution, Some((2560, 1440))); + assert_eq!(state.config.defaults.resolution, Some((854, 480))); assert!( global_field_line(&state, 7, field_label(7)) .to_string() diff --git a/src/tui/widgets/popups/instance_settings.rs b/src/tui/widgets/popups/instance_settings.rs index 9e10d0b..c4106fa 100644 --- a/src/tui/widgets/popups/instance_settings.rs +++ b/src/tui/widgets/popups/instance_settings.rs @@ -749,13 +749,9 @@ impl State { } fn apply_default_resolution(&mut self) { - if let Some(resolution) = default_resolution(&self.display_resolutions) { - self.draft.resolution = Some(resolution); - self.draft.inherit_resolution = false; - self.error = None; - } else { - self.error = Some("Display resolution could not be detected.".to_owned()); - } + self.draft.resolution = Some(default_resolution()); + self.draft.inherit_resolution = false; + self.error = None; } fn toggle_global_window_default(&mut self) { @@ -1495,7 +1491,7 @@ fn field_line(state: &State, index: usize, label: &str) -> Line<'static> { if index == 9 && !editing && !state.draft.inherit_resolution - && is_default_resolution(state.draft.resolution, &state.display_resolutions) + && is_default_resolution(state.draft.resolution) { spans.extend([Span::raw(" "), default_label()]); } @@ -2004,7 +2000,7 @@ mod tests { }]; state.draft.resolution = Some((1920, 1080)); state.handle_key(&KeyEvent::from(KeyCode::Char('d'))); - assert_eq!(state.draft.resolution, Some((2560, 1440))); + assert_eq!(state.draft.resolution, Some((854, 480))); assert!( field_line(&state, 9, field_label(9)) .to_string() diff --git a/src/tui/widgets/popups/settings_controls.rs b/src/tui/widgets/popups/settings_controls.rs index 554d2e0..cf92c93 100644 --- a/src/tui/widgets/popups/settings_controls.rs +++ b/src/tui/widgets/popups/settings_controls.rs @@ -20,7 +20,7 @@ use ratatui::{ use ratatui_textarea::{CursorMove, TextArea}; use crate::{ - config::theme::THEME, + config::{settings::DEFAULT_RESOLUTION, theme::THEME}, instance::{WindowMode, java::JavaInstallation}, tui::widgets::{popups::LoadState, status_badge}, }; @@ -1084,17 +1084,12 @@ pub(crate) fn display_resolutions() -> Vec { resolutions } -pub(crate) fn default_resolution(displays: &[DisplayResolution]) -> Option<(u32, u32)> { - displays - .first() - .map(|display| (display.width, display.height)) +pub(crate) fn default_resolution() -> (u32, u32) { + DEFAULT_RESOLUTION } -pub(crate) fn is_default_resolution( - resolution: Option<(u32, u32)>, - displays: &[DisplayResolution], -) -> bool { - default_resolution(displays).is_some_and(|default| resolution == Some(default)) +pub(crate) fn is_default_resolution(resolution: Option<(u32, u32)>) -> bool { + resolution == Some(default_resolution()) } pub(crate) fn resolution_choices( @@ -1189,17 +1184,10 @@ mod tests { } #[test] - fn first_detected_display_is_the_default_resolution() { - let displays = vec![DisplayResolution { - width: 1440, - height: 2560, - name: "DP-1".to_owned(), - primary: true, - }]; - - assert_eq!(default_resolution(&displays), Some((1440, 2560))); - assert!(is_default_resolution(Some((1440, 2560)), &displays)); - assert!(!is_default_resolution(Some((854, 480)), &displays)); + fn minecraft_window_size_is_the_default_resolution() { + assert_eq!(default_resolution(), (854, 480)); + assert!(is_default_resolution(Some((854, 480)))); + assert!(!is_default_resolution(Some((1440, 2560)))); } #[test]