diff --git a/Cargo.lock b/Cargo.lock index e90301e..4cf5b9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index d1e0fd3..d885054 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/app/Cargo.toml b/app/Cargo.toml index f8fb8f5..866d12e 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -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" } diff --git a/app/src/main.rs b/app/src/main.rs index 4cea97b..712f685 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -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}; diff --git a/app/src/pages/desktop/appearance.rs b/app/src/pages/desktop/appearance.rs index 840408a..057e9bc 100644 --- a/app/src/pages/desktop/appearance.rs +++ b/app/src/pages/desktop/appearance.rs @@ -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; diff --git a/app/src/pages/desktop/display/mod.rs b/app/src/pages/desktop/display/mod.rs index 2a14534..c34b6ea 100644 --- a/app/src/pages/desktop/display/mod.rs +++ b/app/src/pages/desktop/display/mod.rs @@ -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::(id); } diff --git a/app/src/pages/desktop/wallpaper/config.rs b/app/src/pages/desktop/wallpaper/config.rs index 2cfc750..25d4938 100644 --- a/app/src/pages/desktop/wallpaper/config.rs +++ b/app/src/pages/desktop/wallpaper/config.rs @@ -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}; diff --git a/app/src/pages/desktop/wallpaper/mod.rs b/app/src/pages/desktop/wallpaper/mod.rs index 4da640e..f079c8e 100644 --- a/app/src/pages/desktop/wallpaper/mod.rs +++ b/app/src/pages/desktop/wallpaper/mod.rs @@ -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, Context)>), + Init( + Box<( + wallpaper::Config, + HashMap, + 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 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, + displays: HashMap, 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() { diff --git a/app/src/pages/desktop/wallpaper/widgets.rs b/app/src/pages/desktop/wallpaper/widgets.rs index 6e8e43d..d9beeaf 100644 --- a/app/src/pages/desktop/wallpaper/widgets.rs +++ b/app/src/pages/desktop/wallpaper/widgets.rs @@ -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; diff --git a/app/src/utils.rs b/app/src/utils.rs new file mode 100644 index 0000000..80bcf40 --- /dev/null +++ b/app/src/utils.rs @@ -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 + ), + } +} diff --git a/pages/desktop/src/lib.rs b/pages/desktop/src/lib.rs deleted file mode 100644 index 888292e..0000000 --- a/pages/desktop/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod outputs; -pub mod wallpaper; diff --git a/pages/desktop/src/outputs.rs b/pages/desktop/src/outputs.rs deleted file mode 100644 index 5954177..0000000 --- a/pages/desktop/src/outputs.rs +++ /dev/null @@ -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, Box> { - 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, - _output: wl_output::WlOutput, - ) { - } - - fn update_output( - &mut self, - _conn: &Connection, - _qh: &QueueHandle, - _output: wl_output::WlOutput, - ) { - } - - fn output_destroyed( - &mut self, - _conn: &Connection, - _qh: &QueueHandle, - _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 - } -} diff --git a/pages/desktop/Cargo.toml b/pages/wallpapers/Cargo.toml similarity index 82% rename from pages/desktop/Cargo.toml rename to pages/wallpapers/Cargo.toml index 5be7246..036d375 100644 --- a/pages/desktop/Cargo.toml +++ b/pages/wallpapers/Cargo.toml @@ -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" diff --git a/pages/desktop/src/wallpaper.rs b/pages/wallpapers/src/lib.rs similarity index 97% rename from pages/desktop/src/wallpaper.rs rename to pages/wallpapers/src/lib.rs index c175462..0b7320d 100644 --- a/pages/desktop/src/wallpaper.rs +++ b/pages/wallpapers/src/lib.rs @@ -43,14 +43,12 @@ pub const DEFAULT_COLORS: &[Color] = &[ }), ]; -pub fn config() -> (Config, HashMap) { +pub async fn config() -> (Config, HashMap) { 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)); } }