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

39
Cargo.lock generated
View file

@ -1083,7 +1083,7 @@ dependencies = [
[[package]]
name = "cosmic-randr-shell"
version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-randr?rev=c35172c#c35172c637865d498ac509848a9194ba345d1350"
source = "git+https://github.com/pop-os/cosmic-randr#88c570cf8b88beae1cf4f3e2d412cc64ec49cd7c"
dependencies = [
"kdl",
"slotmap",
@ -1104,10 +1104,10 @@ dependencies = [
"cosmic-comp-config",
"cosmic-panel-config",
"cosmic-randr-shell",
"cosmic-settings-desktop",
"cosmic-settings-page",
"cosmic-settings-system",
"cosmic-settings-time",
"cosmic-settings-wallpaper",
"derivative",
"derive_setters",
"dirs 5.0.1",
@ -1136,24 +1136,6 @@ dependencies = [
"url",
]
[[package]]
name = "cosmic-settings-desktop"
version = "0.1.0"
dependencies = [
"cosmic-bg-config",
"cosmic-config",
"dirs 5.0.1",
"freedesktop-icons",
"futures-lite 2.2.0",
"image",
"infer",
"rayon",
"smithay-client-toolkit 0.18.0",
"tokio",
"tracing",
"wayland-client 0.31.2",
]
[[package]]
name = "cosmic-settings-page"
version = "0.1.0"
@ -1190,6 +1172,23 @@ dependencies = [
"zbus",
]
[[package]]
name = "cosmic-settings-wallpaper"
version = "0.1.0"
dependencies = [
"cosmic-bg-config",
"cosmic-config",
"cosmic-randr-shell",
"dirs 5.0.1",
"freedesktop-icons",
"futures-lite 2.2.0",
"image",
"infer",
"rayon",
"tokio",
"tracing",
]
[[package]]
name = "cosmic-text"
version = "0.10.0"

View file

@ -20,6 +20,9 @@ git = "https://github.com/pop-os/cosmic-comp"
[workspace.dependencies.cosmic-panel-config]
git = "https://github.com/pop-os/cosmic-panel"
[workspace.dependencies.cosmic-randr-shell]
git = "https://github.com/pop-os/cosmic-randr"
[workspace.dependencies.sctk]
git = "https://github.com/smithay/client-toolkit/"
package = "smithay-client-toolkit"

View file

@ -9,8 +9,8 @@ rust-version = "1.65.0"
apply = "0.3.0"
async-channel = "2.1.1"
color-eyre = "0.6.2"
cosmic-randr-shell = { git = "https://github.com/pop-os/cosmic-randr", rev = "c35172c" }
cosmic-settings-desktop = { path = "../pages/desktop" }
cosmic-randr-shell = { workspace = true }
cosmic-settings-wallpaper = { path = "../pages/wallpapers" }
cosmic-settings-page = { path = "../page" }
cosmic-settings-system = { path = "../pages/system" }
cosmic-settings-time = { path = "../pages/time" }

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
),
}
}

View file

@ -1,2 +0,0 @@
pub mod outputs;
pub mod wallpaper;

View file

@ -1,84 +0,0 @@
//! Test application to list all available outputs.
use std::error::Error;
use sctk::{
delegate_output, delegate_registry,
output::{OutputHandler, OutputInfo, OutputState},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
};
use wayland_client::{globals::registry_queue_init, protocol::wl_output, Connection, QueueHandle};
pub fn outputs() -> Result<impl Iterator<Item = OutputInfo>, Box<dyn Error>> {
let conn = Connection::connect_to_env()?;
let (globals, mut event_queue) = registry_queue_init(&conn).unwrap();
let qh = event_queue.handle();
let registry_state = RegistryState::new(&globals);
let output_delegate = OutputState::new(&globals, &qh);
let mut list_outputs = ListOutputs {
registry_state,
output_state: output_delegate,
};
event_queue.roundtrip(&mut list_outputs)?;
// Now our outputs have been initialized with data, we may access what outputs exist and information about
// said outputs using the output delegate.
Ok(list_outputs
.output_state
.outputs()
.filter_map(move |output| list_outputs.output_state.info(&output)))
}
struct ListOutputs {
registry_state: RegistryState,
output_state: OutputState,
}
impl OutputHandler for ListOutputs {
fn output_state(&mut self) -> &mut OutputState {
&mut self.output_state
}
fn new_output(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_output: wl_output::WlOutput,
) {
}
fn update_output(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_output: wl_output::WlOutput,
) {
}
fn output_destroyed(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_output: wl_output::WlOutput,
) {
}
}
delegate_output!(ListOutputs);
delegate_registry!(ListOutputs);
impl ProvidesRegistryState for ListOutputs {
fn registry(&mut self) -> &mut RegistryState {
&mut self.registry_state
}
registry_handlers! {
OutputState
}
}

View file

@ -1,5 +1,5 @@
[package]
name = "cosmic-settings-desktop"
name = "cosmic-settings-wallpaper"
version = "0.1.0"
edition = "2021"
@ -8,13 +8,12 @@ edition = "2021"
[dependencies]
cosmic-bg-config = { workspace = true }
cosmic-config = { workspace = true }
cosmic-randr-shell = { workspace = true }
dirs = "5.0.1"
freedesktop-icons = "0.2.5"
futures-lite = "2.2.0"
image = "0.24.8"
infer = "0.15.0"
rayon = "1.8.1"
sctk = { workspace = true }
tokio = { version = "1.35.1", features = ["sync"] }
tracing = "0.1.40"
wayland-client = "0.31.2"

View file

@ -43,14 +43,12 @@ pub const DEFAULT_COLORS: &[Color] = &[
}),
];
pub fn config() -> (Config, HashMap<String, String>) {
pub async fn config() -> (Config, HashMap<String, (String, (u32, u32))>) {
let mut displays = HashMap::new();
if let Ok(outputs) = crate::outputs::outputs() {
for output in outputs {
if let Some(name) = output.name {
displays.insert(name, output.make);
}
if let Ok(list) = cosmic_randr_shell::list().await {
for (_key, output) in list.outputs {
displays.insert(output.name, (output.model, output.physical));
}
}