improv(wallpaper): share display listing logic with display page

This commit is contained in:
Michael Aaron Murphy 2024-01-30 00:58:53 +01:00 committed by Michael Murphy
parent f25e31ed45
commit e7c9595578
14 changed files with 66 additions and 145 deletions

View file

@ -15,10 +15,10 @@ pub mod config;
#[macro_use]
pub mod localize;
pub mod pages;
pub mod theme;
pub mod widget;
pub mod subscription;
pub mod theme;
pub mod utils;
pub mod widget;
use clap::{Parser, Subcommand};
use cosmic::{app::CosmicFlags, iced::Limits};

View file

@ -19,9 +19,9 @@ use cosmic::widget::{
settings, spin_button, text, ColorPickerModel,
};
use cosmic::{command, Command, Element};
use cosmic_settings_desktop::wallpaper;
use cosmic_settings_page::Section;
use cosmic_settings_page::{self as page, section};
use cosmic_settings_wallpaper as wallpaper;
use once_cell::sync::Lazy;
use ron::ser::PrettyConfig;
use slotmap::SlotMap;

View file

@ -470,24 +470,9 @@ impl Page {
continue;
};
let inches =
((output.physical.0.pow(2) + output.physical.1.pow(2)) as f32).sqrt() * 0.039_370_1;
let inches_string = format!("{inches:.1}\"");
self.display_tabs
.insert()
.text(match name {
"eDP-1" | "LVDS1" => {
fl!("display", "laptop", size = inches_string.as_str())
}
output => fl!(
"display",
"external",
size = inches_string.as_str(),
output = output
),
})
.text(crate::utils::display_name(&output.name, output.physical))
.data::<OutputKey>(id);
}

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only
use cosmic::cosmic_config::{self, ConfigGet, ConfigSet};
use cosmic_settings_desktop::wallpaper;
use cosmic_settings_wallpaper as wallpaper;
use std::collections::VecDeque;
use std::path::{Path, PathBuf};

View file

@ -40,9 +40,9 @@ use cosmic::{
widget::{color_picker::ColorPickerUpdate, ColorPickerModel},
Element,
};
use cosmic_settings_desktop::wallpaper::{self, Entry, ScalingMode};
use cosmic_settings_page::Section;
use cosmic_settings_page::{self as page, section};
use cosmic_settings_wallpaper::{self as wallpaper, Entry, ScalingMode};
use image::imageops::FilterType::Lanczos3;
use image::{ImageBuffer, Rgba};
use slotmap::{DefaultKey, SecondaryMap, SlotMap};
@ -93,7 +93,13 @@ pub enum Message {
/// Removes a custom image from the wallpaper view.
ImageRemove(DefaultKey),
/// Initializes the view.
Init(Box<(wallpaper::Config, HashMap<String, String>, Context)>),
Init(
Box<(
wallpaper::Config,
HashMap<String, (String, (u32, u32))>,
Context,
)>,
),
/// Changes the active output display that is to be configured.
Output(segmented_button::Entity),
/// Changes the rotation frequency of wallpaper images in slideshow mode.
@ -184,7 +190,7 @@ impl page::Page<crate::pages::Message> for Page {
let current_folder = self.config.current_folder().to_owned();
command::future(async move {
let (wallpaper_service_config, outputs) = wallpaper::config();
let (wallpaper_service_config, outputs) = wallpaper::config().await;
let update = change_folder(current_folder).await;
@ -414,7 +420,7 @@ impl Page {
fn wallpaper_service_config_update(
&mut self,
wallpaper_service_config: wallpaper::Config,
displays: HashMap<String, String>,
displays: HashMap<String, (String, (u32, u32))>,
selection: Context,
) {
self.wallpaper_service_config = wallpaper_service_config;
@ -422,11 +428,11 @@ impl Page {
self.outputs.clear();
let mut first = None;
for (name, model) in displays {
for (name, (_model, physical)) in displays {
let entity = self
.outputs
.insert()
.text(format!("{model} ({name})"))
.text(crate::utils::display_name(&name, physical))
.data(name);
if first.is_none() {

View file

@ -7,7 +7,7 @@ use cosmic::iced_runtime::core::image::Handle as ImageHandle;
use cosmic::prelude::*;
use cosmic::widget::{button, container, space};
use cosmic::{iced, Element};
use cosmic_settings_desktop::wallpaper;
use cosmic_settings_wallpaper as wallpaper;
use slotmap::DefaultKey;
const COLOR_WIDTH: u16 = 70;

17
app/src/utils.rs Normal file
View file

@ -0,0 +1,17 @@
/// Normalize the labeling of displays across settings pages.
pub fn display_name(name: &str, physical: (u32, u32)) -> String {
let inches = ((physical.0.pow(2) + physical.1.pow(2)) as f32).sqrt() * 0.039_370_1;
let inches_string = format!("{inches:.1}\"");
match name {
"eDP-1" | "LVDS1" => {
fl!("display", "laptop", size = inches_string.as_str())
}
output => fl!(
"display",
"external",
size = inches_string.as_str(),
output = output
),
}
}