From d61193dc4eb4f0dca6285f8f7d1c6e86f4590700 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 19 Aug 2024 10:11:16 -0700 Subject: [PATCH] display: Add options for DPI scales up to 300% Scale factors above 200% may be useful on things like 4k 13 inch laptops. So we should provide higher options, even if we don't default to anything above 200%. The way the dropdown is formatted with scrolling on smaller window sizes could probably be improved. But that will presumably be a libcosmic change, not anything here. --- cosmic-settings/src/pages/display/mod.rs | 32 +++++++++--------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/cosmic-settings/src/pages/display/mod.rs b/cosmic-settings/src/pages/display/mod.rs index 05eed5a..8a554e7 100644 --- a/cosmic-settings/src/pages/display/mod.rs +++ b/cosmic-settings/src/pages/display/mod.rs @@ -15,10 +15,15 @@ use cosmic::widget::{ use cosmic::{command, Apply, Command, Element}; use cosmic_randr_shell::{List, Output, OutputKey, Transform}; use cosmic_settings_page::{self as page, section, Section}; +use once_cell::sync::Lazy; use slab::Slab; use slotmap::{Key, SecondaryMap, SlotMap}; use std::{collections::BTreeMap, process::ExitStatus, sync::Arc}; +static DPI_SCALES: &[u32] = &[50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300]; +static DPI_SCALE_LABELS: Lazy> = + Lazy::new(|| DPI_SCALES.iter().map(|scale| format!("{scale}%")).collect()); + /// Display color depth options #[derive(Clone, Copy, Debug)] pub struct ColorDepth(usize); @@ -585,21 +590,12 @@ impl Page { self.cache.resolution_selected = None; self.cache.refresh_rate_selected = None; - self.cache.scale_selected = Some(if self.config.scale < 75 { - 0 - } else if self.config.scale < 100 { - 1 - } else if self.config.scale < 125 { - 2 - } else if self.config.scale < 150 { - 3 - } else if self.config.scale < 175 { - 4 - } else if self.config.scale < 200 { - 5 - } else { - 6 - }); + self.cache.scale_selected = Some( + DPI_SCALES + .iter() + .position(|scale| self.config.scale <= *scale) + .unwrap_or(DPI_SCALES.len() - 1), + ); if let Some(current_mode_id) = output.current { for (mode_id, mode) in output @@ -1041,11 +1037,7 @@ pub fn display_configuration() -> Section { )) .add(widget::settings::item( &descriptions[scale], - dropdown( - &["50%", "75%", "100%", "125%", "150%", "175%", "200%"], - page.cache.scale_selected, - Message::Scale, - ), + dropdown(&DPI_SCALE_LABELS, page.cache.scale_selected, Message::Scale), )) .add(widget::settings::item( &descriptions[orientation],