fix: restore Minecraft default resolution action

This commit is contained in:
objz committed 2026-09-04 22:26:14 +02:00
1 parent 429e46b7b7
commit a5fdbaf74a
3 files changed
+19 -42

No files matched your search

+5 -12
View File
@@ -460,13 +460,9 @@ impl State {
} }
fn apply_default_resolution(&mut self) { fn apply_default_resolution(&mut self) {
if let Some(resolution) = default_resolution(&self.display_resolutions) { self.config.defaults.resolution = Some(default_resolution());
self.config.defaults.resolution = Some(resolution); self.save_pending = true;
self.save_pending = true; self.error = None;
self.error = None;
} else {
self.error = Some("Display resolution could not be detected.".to_owned());
}
} }
fn enable_auto_image_protocol(&mut self) { 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 { if index == 2 && state.config.ui.image_protocol == ImageProtocol::Auto && !editing {
spans.extend([Span::raw(" "), auto_label()]); spans.extend([Span::raw(" "), auto_label()]);
} }
if index == 7 if index == 7 && !editing && is_default_resolution(state.config.defaults.resolution) {
&& !editing
&& is_default_resolution(state.config.defaults.resolution, &state.display_resolutions)
{
spans.extend([Span::raw(" "), default_label()]); spans.extend([Span::raw(" "), default_label()]);
} }
if index == 10 && !editing { if index == 10 && !editing {
@@ -1369,7 +1362,7 @@ mod tests {
state.handle_key(&KeyEvent::from(KeyCode::Char('d'))), state.handle_key(&KeyEvent::from(KeyCode::Char('d'))),
Action::Save(..) Action::Save(..)
)); ));
assert_eq!(state.config.defaults.resolution, Some((2560, 1440))); assert_eq!(state.config.defaults.resolution, Some((854, 480)));
assert!( assert!(
global_field_line(&state, 7, field_label(7)) global_field_line(&state, 7, field_label(7))
.to_string() .to_string()
+5 -9
View File
@@ -749,13 +749,9 @@ impl State {
} }
fn apply_default_resolution(&mut self) { fn apply_default_resolution(&mut self) {
if let Some(resolution) = default_resolution(&self.display_resolutions) { self.draft.resolution = Some(default_resolution());
self.draft.resolution = Some(resolution); self.draft.inherit_resolution = false;
self.draft.inherit_resolution = false; self.error = None;
self.error = None;
} else {
self.error = Some("Display resolution could not be detected.".to_owned());
}
} }
fn toggle_global_window_default(&mut self) { 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 if index == 9
&& !editing && !editing
&& !state.draft.inherit_resolution && !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()]); spans.extend([Span::raw(" "), default_label()]);
} }
@@ -2004,7 +2000,7 @@ mod tests {
}]; }];
state.draft.resolution = Some((1920, 1080)); state.draft.resolution = Some((1920, 1080));
state.handle_key(&KeyEvent::from(KeyCode::Char('d'))); 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!( assert!(
field_line(&state, 9, field_label(9)) field_line(&state, 9, field_label(9))
.to_string() .to_string()
+9 -21
View File
@@ -20,7 +20,7 @@ use ratatui::{
use ratatui_textarea::{CursorMove, TextArea}; use ratatui_textarea::{CursorMove, TextArea};
use crate::{ use crate::{
config::theme::THEME, config::{settings::DEFAULT_RESOLUTION, theme::THEME},
instance::{WindowMode, java::JavaInstallation}, instance::{WindowMode, java::JavaInstallation},
tui::widgets::{popups::LoadState, status_badge}, tui::widgets::{popups::LoadState, status_badge},
}; };
@@ -1084,17 +1084,12 @@ pub(crate) fn display_resolutions() -> Vec<DisplayResolution> {
resolutions resolutions
} }
pub(crate) fn default_resolution(displays: &[DisplayResolution]) -> Option<(u32, u32)> { pub(crate) fn default_resolution() -> (u32, u32) {
displays DEFAULT_RESOLUTION
.first()
.map(|display| (display.width, display.height))
} }
pub(crate) fn is_default_resolution( pub(crate) fn is_default_resolution(resolution: Option<(u32, u32)>) -> bool {
resolution: Option<(u32, u32)>, resolution == Some(default_resolution())
displays: &[DisplayResolution],
) -> bool {
default_resolution(displays).is_some_and(|default| resolution == Some(default))
} }
pub(crate) fn resolution_choices( pub(crate) fn resolution_choices(
@@ -1189,17 +1184,10 @@ mod tests {
} }
#[test] #[test]
fn first_detected_display_is_the_default_resolution() { fn minecraft_window_size_is_the_default_resolution() {
let displays = vec![DisplayResolution { assert_eq!(default_resolution(), (854, 480));
width: 1440, assert!(is_default_resolution(Some((854, 480))));
height: 2560, assert!(!is_default_resolution(Some((1440, 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));
} }
#[test] #[test]