diff --git a/cosmic-settings/src/app.rs b/cosmic-settings/src/app.rs index 31db0493..5a87edef 100644 --- a/cosmic-settings/src/app.rs +++ b/cosmic-settings/src/app.rs @@ -59,7 +59,6 @@ impl SettingsApp { match cmd { PageCommands::About => self.pages.page_id::(), PageCommands::Appearance => self.pages.page_id::(), - PageCommands::Bluetooth => None, PageCommands::DateTime => self.pages.page_id::(), PageCommands::Desktop => self.pages.page_id::(), PageCommands::Displays => self.pages.page_id::(), @@ -68,7 +67,6 @@ impl SettingsApp { PageCommands::Input => self.pages.page_id::(), PageCommands::Keyboard => self.pages.page_id::(), PageCommands::Mouse => self.pages.page_id::(), - PageCommands::Network => None, PageCommands::Panel => self.pages.page_id::(), PageCommands::Power => self.pages.page_id::(), PageCommands::RegionLanguage => self.pages.page_id::(), @@ -82,6 +80,8 @@ impl SettingsApp { self.pages.page_id::() } PageCommands::Workspaces => self.pages.page_id::(), + // Unimplemented + PageCommands::Bluetooth | PageCommands::Network => None, } } diff --git a/cosmic-settings/src/main.rs b/cosmic-settings/src/main.rs index f4b7db8a..451ea858 100644 --- a/cosmic-settings/src/main.rs +++ b/cosmic-settings/src/main.rs @@ -94,9 +94,9 @@ impl FromStr for PageCommands { } } -impl ToString for PageCommands { - fn to_string(&self) -> String { - ron::ser::to_string(self).unwrap() +impl std::fmt::Display for PageCommands { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&ron::ser::to_string(self).map_err(|_| std::fmt::Error)?) } } diff --git a/cosmic-settings/src/pages/desktop/appearance.rs b/cosmic-settings/src/pages/desktop/appearance.rs index dfe31c43..7b65d286 100644 --- a/cosmic-settings/src/pages/desktop/appearance.rs +++ b/cosmic-settings/src/pages/desktop/appearance.rs @@ -444,7 +444,7 @@ impl Page { .zip(self.icon_handles.iter()) .enumerate() .map(|(i, (theme, handles))| { - let selected = active.map(|j| i == j).unwrap_or_default(); + let selected = active.is_some_and(|j| i == j); icon_theme_button(&theme.name, handles, i, selected) }) .collect(), @@ -496,7 +496,7 @@ impl Page { Message::IconTheme(id) => { if let Some(theme) = self.icon_themes.get(id).cloned() { self.icon_theme_active = Some(id); - self.tk.icon_theme = theme.id.clone(); + self.tk.icon_theme = theme.id; if let Some(ref config) = self.tk_config { let _ = self.tk.write_entry(config); @@ -598,7 +598,7 @@ impl Page { self.icon_theme_active = self .icon_themes .iter() - .position(|theme| &theme.id == &self.tk.icon_theme); + .position(|theme| theme.id == self.tk.icon_theme); self.icon_handles = icon_handles; Command::none() } @@ -1689,7 +1689,7 @@ async fn set_gnome_icon_theme(theme: String) { .await; } -/// Generate [icon::Handle]s to use for icon theme previews. +/// Generate [`icon::Handle`]s to use for icon theme previews. fn preview_handles(theme: String, inherits: Vec) -> [icon::Handle; ICON_PREV_N] { // Cache current default and set icon theme as a temporary default let default = cosmic::icon_theme::default(); diff --git a/cosmic-settings/src/pages/desktop/dock/mod.rs b/cosmic-settings/src/pages/desktop/dock/mod.rs index c708ae6a..088be43f 100644 --- a/cosmic-settings/src/pages/desktop/dock/mod.rs +++ b/cosmic-settings/src/pages/desktop/dock/mod.rs @@ -16,12 +16,12 @@ use crate::pages::desktop::panel::inner::{ add_panel, behavior_and_position, configuration, reset_button, style, }; -use super::panel::inner::{self, PageInner, PanelPage}; +use super::panel::inner; pub mod applets; pub struct Page { - inner: PageInner, + inner: inner::Page, } #[derive(Clone, Debug)] @@ -75,12 +75,12 @@ impl page::AutoBind for Page { } } -impl PanelPage for Page { - fn inner(&self) -> &PageInner { +impl inner::PanelPage for Page { + fn inner(&self) -> &inner::Page { &self.inner } - fn inner_mut(&mut self) -> &mut PageInner { + fn inner_mut(&mut self) -> &mut inner::Page { &mut self.inner } @@ -130,7 +130,7 @@ impl Default for Page { .ok(); let container_config = CosmicPanelContainerConfig::load().ok(); Self { - inner: PageInner { + inner: inner::Page { config_helper, panel_config, container_config, diff --git a/cosmic-settings/src/pages/desktop/panel/applets_inner.rs b/cosmic-settings/src/pages/desktop/panel/applets_inner.rs index be2dc524..c7fed6eb 100644 --- a/cosmic-settings/src/pages/desktop/panel/applets_inner.rs +++ b/cosmic-settings/src/pages/desktop/panel/applets_inner.rs @@ -324,6 +324,9 @@ impl Page { .into() } + /// # Panics + /// + /// Panics if the wings of the added applet are None. #[allow(clippy::too_many_lines)] pub fn update(&mut self, message: Message) -> Command { match message { @@ -666,7 +669,7 @@ impl<'a, Message: 'static + Clone> AppletReorderList<'a, Message> { ) -> Message + 'a, on_remove: impl Fn(String) -> Message + 'a, - on_details: impl Fn(String) -> Message + 'a, + _on_details: impl Fn(String) -> Message + 'a, on_reorder: impl Fn(Vec>) -> Message + 'a, on_apply_reorder: Message, on_cancel: Message, @@ -972,7 +975,10 @@ where } DraggingState::Dragging(applet) => match &event { event::Event::PlatformSpecific(PlatformSpecific::Wayland( - wayland::Event::DataSource(wayland::DataSourceEvent::DndFinished), + wayland::Event::DataSource( + wayland::DataSourceEvent::DndFinished + | wayland::DataSourceEvent::DndDropPerformed, + ), )) => { ret = event::Status::Captured; DraggingState::None @@ -986,13 +992,6 @@ where } DraggingState::None } - event::Event::PlatformSpecific(PlatformSpecific::Wayland( - wayland::Event::DataSource(wayland::DataSourceEvent::DndDropPerformed), - )) => { - ret = event::Status::Captured; - - DraggingState::None - } _ => DraggingState::Dragging(applet), }, DraggingState::Pressed(start) => { diff --git a/cosmic-settings/src/pages/desktop/panel/inner.rs b/cosmic-settings/src/pages/desktop/panel/inner.rs index a2a4fb6d..69bfb733 100644 --- a/cosmic-settings/src/pages/desktop/panel/inner.rs +++ b/cosmic-settings/src/pages/desktop/panel/inner.rs @@ -18,7 +18,7 @@ use cosmic_settings_page::{self as page, Section}; use slab::Slab; use std::collections::HashMap; -pub struct PageInner { +pub struct Page { pub(crate) config_helper: Option, pub(crate) panel_config: Option, pub outputs: Vec, @@ -31,7 +31,7 @@ pub struct PageInner { pub(crate) system_container: Option, } -impl Default for PageInner { +impl Default for Page { fn default() -> Self { Self { config_helper: Option::default(), @@ -72,9 +72,9 @@ impl Default for PageInner { } pub trait PanelPage { - fn inner(&self) -> &PageInner; + fn inner(&self) -> &Page; - fn inner_mut(&mut self) -> &mut PageInner; + fn inner_mut(&mut self) -> &mut Page; fn autohide_label(&self) -> String; @@ -336,14 +336,14 @@ pub fn reset_button< #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct Anchor(PanelAnchor); -impl ToString for Anchor { - fn to_string(&self) -> String { - match self.0 { +impl std::fmt::Display for Anchor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&match self.0 { PanelAnchor::Top => fl!("panel-top"), PanelAnchor::Bottom => fl!("panel-bottom"), PanelAnchor::Left => fl!("panel-left"), PanelAnchor::Right => fl!("panel-right"), - } + }) } } @@ -354,13 +354,13 @@ pub enum Appearance { Dark, } -impl ToString for Appearance { - fn to_string(&self) -> String { - match self { +impl std::fmt::Display for Appearance { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&match self { Appearance::Match => fl!("panel-appearance", "match"), Appearance::Light => fl!("panel-appearance", "light"), Appearance::Dark => fl!("panel-appearance", "dark"), - } + }) } } @@ -404,7 +404,7 @@ pub enum Message { FullReset, } -impl PageInner { +impl Page { #[allow(clippy::too_many_lines)] pub fn update(&mut self, message: Message) { let Some(helper) = self.config_helper.as_ref() else { diff --git a/cosmic-settings/src/pages/desktop/panel/mod.rs b/cosmic-settings/src/pages/desktop/panel/mod.rs index 2ad64b54..195f2596 100644 --- a/cosmic-settings/src/pages/desktop/panel/mod.rs +++ b/cosmic-settings/src/pages/desktop/panel/mod.rs @@ -9,13 +9,11 @@ use crate::pages::desktop::panel::inner::{ add_panel, behavior_and_position, configuration, reset_button, style, }; -use self::inner::{PageInner, PanelPage}; - pub mod applets_inner; pub mod inner; pub struct Page { - inner: PageInner, + inner: inner::Page, } #[derive(Clone, Debug)] @@ -33,12 +31,12 @@ impl page::AutoBind for Page { } } -impl PanelPage for Page { - fn inner(&self) -> &PageInner { +impl inner::PanelPage for Page { + fn inner(&self) -> &inner::Page { &self.inner } - fn inner_mut(&mut self) -> &mut PageInner { + fn inner_mut(&mut self) -> &mut inner::Page { &mut self.inner } @@ -87,7 +85,7 @@ impl Default for Page { .ok(); let container_config = CosmicPanelContainerConfig::load().ok(); Self { - inner: PageInner { + inner: inner::Page { config_helper, panel_config, container_config, diff --git a/cosmic-settings/src/pages/desktop/wallpaper/mod.rs b/cosmic-settings/src/pages/desktop/wallpaper/mod.rs index 0a91c12b..008542d2 100644 --- a/cosmic-settings/src/pages/desktop/wallpaper/mod.rs +++ b/cosmic-settings/src/pages/desktop/wallpaper/mod.rs @@ -24,18 +24,11 @@ use cosmic::{ }, }; use cosmic::{ - iced::{wayland::actions::window::SctkWindowSettings, window, Color, Length}, + iced::{Color, Length}, prelude::CollectionWidget, }; -use cosmic::{ - iced_core::Alignment, - iced_sctk::commands::window::{close_window, get_window}, - widget::icon, -}; -use cosmic::{ - iced_core::{alignment, layout}, - iced_runtime::core::image::Handle as ImageHandle, -}; +use cosmic::{iced_core::alignment, iced_runtime::core::image::Handle as ImageHandle}; +use cosmic::{iced_core::Alignment, widget::icon}; use cosmic::{ widget::{color_picker::ColorPickerUpdate, ColorPickerModel}, Element, @@ -43,7 +36,7 @@ use cosmic::{ use cosmic_bg_config::Source; use cosmic_settings_page::Section; use cosmic_settings_page::{self as page, section}; -use cosmic_settings_wallpaper::{self as wallpaper, Entry, ScalingMode}; +use cosmic_settings_wallpaper::{self as wallpaper, Entry, ImageSelection, ScalingMode}; use image::imageops::FilterType::Lanczos3; use image::{ImageBuffer, Rgba}; use slab::Slab; @@ -98,7 +91,7 @@ pub enum Message { /// Sets the wallpaper fit parameter. Fit(usize), /// Adds a new custom image to the wallpaper view. - ImageAdd(Option>), + ImageAdd(Option>), /// Creates an image dialog. ImageAddDialog, /// Removes a custom image from the wallpaper view. @@ -144,12 +137,18 @@ enum ContextView { AddColor, } +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct DisplayConfig { + pub remaining: usize, + pub displays: HashMap, +} + /// The page struct for the wallpaper view. pub struct Page { /// Whether to show a context drawer. context_view: Option, - /// Whether to show the tab_bar or not. + /// Whether to show the `tab_bar` or not. show_tab_bar: bool, /// The display that is currently being configured. @@ -193,8 +192,8 @@ pub struct Page { /// Stores custom colors, custom images, and all image data for every wallpaper. selection: Context, - /// When set, applys a config update after images are loaded. - update_config: Option<(usize, HashMap)>, + /// When set, apply a config update after images are loaded. + update_config: Option, } impl page::Page for Page { @@ -708,27 +707,23 @@ impl Page { } Message::ColorAdd(message) => { - match message { - ColorPickerUpdate::ActionFinished => { - let _res = self - .color_model - .update::(ColorPickerUpdate::AppliedColor); + if let ColorPickerUpdate::ActionFinished = message { + let _res = self + .color_model + .update::(ColorPickerUpdate::AppliedColor); - if let Some(color) = self.color_model.get_applied_color() { - let color = wallpaper::Color::Single([color.r, color.g, color.b]); + if let Some(color) = self.color_model.get_applied_color() { + let color = wallpaper::Color::Single([color.r, color.g, color.b]); - if let Err(why) = self.config.add_custom_color(color.clone()) { - tracing::error!(?why, "could not set custom color"); - } - - self.selection.add_custom_color(color.clone()); - self.selection.active = Choice::Color(color); - self.cached_display_handle = None; - self.context_view = None; + if let Err(why) = self.config.add_custom_color(color.clone()) { + tracing::error!(?why, "could not set custom color"); } - } - _ => (), + self.selection.add_custom_color(color.clone()); + self.selection.active = Choice::Color(color); + self.cached_display_handle = None; + self.context_view = None; + } }; return self.color_model.update::(message); @@ -752,7 +747,12 @@ impl Page { Message::ImageAdd(result) => { let result = result.and_then(Arc::into_inner); - let Some((path, display, selection)) = result else { + let Some(ImageSelection { + path, + display_thumbnail: display, + selection_thumbnail: selection, + }) = result + else { tracing::warn!("image not found for provided wallpaper"); return Command::none(); }; @@ -772,13 +772,13 @@ impl Page { ); // If an update was queued, apply it after all custom images have been added. - if let Some((mut remaining, displays)) = self.update_config.take() { - remaining -= 1; - if remaining == 0 { - self.wallpaper_service_config_update(displays); + if let Some(mut config) = self.update_config.take() { + config.remaining -= 1; + if config.remaining == 0 { + self.wallpaper_service_config_update(config.displays); self.config_apply(); } else { - self.update_config = Some((remaining, displays)); + self.update_config = Some(config); } } } @@ -844,20 +844,16 @@ impl Page { self.cache_display_image(); } else { if let Some(output) = self.config_output() { - match self.config.current_image(output) { - Some(Source::Path(path)) => { - if let Some(entity) = self.wallpaper_id_from_path(&path) { - if let Some(entry) = - self.config_wallpaper_entry(output.to_owned(), path) - { - self.select_wallpaper(&entry, entity, false); - self.config_apply(); - return Command::none(); - } + if let Some(Source::Path(path)) = self.config.current_image(output) { + if let Some(entity) = self.wallpaper_id_from_path(&path) { + if let Some(entry) = + self.config_wallpaper_entry(output.to_owned(), path) + { + self.select_wallpaper(&entry, entity, false); + self.config_apply(); + return Command::none(); } } - - _ => (), } } @@ -953,7 +949,10 @@ impl Page { self.config_apply(); } else { // Make note of how many images are to be loaded, with the display update for the service config. - self.update_config = Some((custom_images, update.displays)); + self.update_config = Some(DisplayConfig { + remaining: custom_images, + displays: update.displays, + }); } // Load preview images concurrently for each custom image stored in the on-disk config. @@ -1127,7 +1126,12 @@ pub async fn change_folder(current_folder: PathBuf, recurse: bool) -> Context { let mut update = Context::default(); let mut wallpapers = wallpaper::load_each_from_path(current_folder, recurse).await; - while let Some((path, display_image, selection_image)) = wallpapers.next().await { + while let Some(ImageSelection { + path, + display_thumbnail: display_image, + selection_thumbnail: selection_image, + }) = wallpapers.next().await + { let id = update.paths.insert(path); update.display_images.insert(id, display_image); diff --git a/cosmic-settings/src/pages/desktop/wallpaper/widgets.rs b/cosmic-settings/src/pages/desktop/wallpaper/widgets.rs index 3a621cb6..a5e5ecc7 100644 --- a/cosmic-settings/src/pages/desktop/wallpaper/widgets.rs +++ b/cosmic-settings/src/pages/desktop/wallpaper/widgets.rs @@ -75,11 +75,11 @@ pub fn color_image<'a, M: 'a>( border: Border { radius: border_radius.map_or_else( || Radius::from(theme.cosmic().corner_radii.radius_s), - |br| br.into(), + std::convert::Into::into, ), ..Default::default() }, - shadow: Default::default(), + ..Default::default() } })) .padding(0) diff --git a/cosmic-settings/src/pages/desktop/window_management.rs b/cosmic-settings/src/pages/desktop/window_management.rs index bcb31aa3..0be4d718 100644 --- a/cosmic-settings/src/pages/desktop/window_management.rs +++ b/cosmic-settings/src/pages/desktop/window_management.rs @@ -83,7 +83,7 @@ impl Page { self.focus_follows_cursor = value; if let Err(err) = self .comp_config - .set("focus_follows_cursor", &self.focus_follows_cursor) + .set("focus_follows_cursor", self.focus_follows_cursor) { error!(?err, "Failed to set config 'focus_follows_cursor'"); } @@ -92,7 +92,7 @@ impl Page { self.cursor_follows_focus = value; if let Err(err) = self .comp_config - .set("cursor_follows_focus", &self.cursor_follows_focus) + .set("cursor_follows_focus", self.cursor_follows_focus) { error!(?err, "Failed to set config 'cursor_follows_focus'"); } diff --git a/cosmic-settings/src/pages/display/arrangement.rs b/cosmic-settings/src/pages/display/arrangement.rs index 99778a70..1ba90f62 100644 --- a/cosmic-settings/src/pages/display/arrangement.rs +++ b/cosmic-settings/src/pages/display/arrangement.rs @@ -396,21 +396,15 @@ fn display_regions<'a>( .iter() .filter_map(move |id| model.data::(id)) .filter_map(move |&key| { - let Some(output) = list.outputs.get(key) else { - return None; - }; + let output = list.outputs.get(key)?; if !output.enabled { return None; } - let Some(mode_key) = output.current else { - return None; - }; + let mode_key = output.current?; - let Some(mode) = list.modes.get(mode_key) else { - return None; - }; + let mode = list.modes.get(mode_key)?; let (mut width, mut height) = ( (mode.size.0 as f32 / output.scale as f32) / UNIT_PIXELS, diff --git a/cosmic-settings/src/pages/display/mod.rs b/cosmic-settings/src/pages/display/mod.rs index 1683b95e..f30e36ed 100644 --- a/cosmic-settings/src/pages/display/mod.rs +++ b/cosmic-settings/src/pages/display/mod.rs @@ -28,6 +28,7 @@ static DPI_SCALE_LABELS: Lazy> = /// Display color depth options #[derive(Clone, Copy, Debug)] +#[allow(dead_code)] // ColorDepth is currently unimplemented, so the struct data is unused pub struct ColorDepth(usize); /// Identifies the content to display in the context drawer @@ -494,7 +495,7 @@ impl Page { self.comp_config_descale_xwayland = descale; if let Err(err) = self .comp_config - .set("descale_xwayland", &self.comp_config_descale_xwayland) + .set("descale_xwayland", self.comp_config_descale_xwayland) { error!(?err, "Failed to set config 'descale_xwayland'"); } @@ -908,7 +909,7 @@ impl Page { .arg("mode") .arg("--refresh") .arg( - &[ + [ itoa::Buffer::new().format(rate / 1000), ".", itoa::Buffer::new().format(rate % 1000), @@ -937,7 +938,7 @@ impl Page { .arg("mode") .arg("--scale") .arg( - &[ + [ itoa::Buffer::new().format(scale / 100), ".", itoa::Buffer::new().format(scale % 100), @@ -1204,23 +1205,23 @@ fn cache_rates(cached_rates: &mut Vec, rates: &[u32]) { (None, None) => cached_rates.push(format!("{} Hz", round(rate))), (None, Some(next)) => { if round(rate) == round(next) { - cached_rates.push(format_dec(rate)) + cached_rates.push(format_dec(rate)); } else { - cached_rates.push(format!("{} Hz", round(rate))) + cached_rates.push(format!("{} Hz", round(rate))); } } (Some(prev), None) => { if round(rate) == round(prev) { - cached_rates.push(format_dec(rate)) + cached_rates.push(format_dec(rate)); } else { - cached_rates.push(format!("{} Hz", round(rate))) + cached_rates.push(format!("{} Hz", round(rate))); } } (Some(prev), Some(next)) => { if round(rate) == round(prev) || round(rate) == round(next) { - cached_rates.push(format_dec(rate)) + cached_rates.push(format_dec(rate)); } else { - cached_rates.push(format!("{} Hz", round(rate))) + cached_rates.push(format!("{} Hz", round(rate))); } } } diff --git a/cosmic-settings/src/pages/input/keyboard/mod.rs b/cosmic-settings/src/pages/input/keyboard/mod.rs index cafaa0ac..b2a1476c 100644 --- a/cosmic-settings/src/pages/input/keyboard/mod.rs +++ b/cosmic-settings/src/pages/input/keyboard/mod.rs @@ -154,28 +154,24 @@ fn popover_menu(id: DefaultKey) -> cosmic::Element<'static, Message> { id, fl!("keyboard-sources", "move-up"), SourceContext::MoveUp, - ) - .into(), + ), popover_menu_row( id, fl!("keyboard-sources", "move-down"), SourceContext::MoveDown, - ) - .into(), + ), cosmic::widget::divider::horizontal::default().into(), popover_menu_row( id, fl!("keyboard-sources", "settings"), SourceContext::Settings, - ) - .into(), + ), popover_menu_row( id, fl!("keyboard-sources", "view-layout"), SourceContext::ViewLayout, - ) - .into(), - popover_menu_row(id, fl!("keyboard-sources", "remove"), SourceContext::Remove).into(), + ), + popover_menu_row(id, fl!("keyboard-sources", "remove"), SourceContext::Remove), ]) .padding(8) .width(Length::Shrink) @@ -615,11 +611,11 @@ fn special_character_entry() -> Section { settings::view_section(§ion.title) .add(crate::widget::go_next_item( - &*descriptions[alternate], + &descriptions[alternate], Message::OpenSpecialCharacterContext(SpecialKey::AlternateCharacters), )) .add(crate::widget::go_next_item( - &*descriptions[compose], + &descriptions[compose], Message::OpenSpecialCharacterContext(SpecialKey::Compose), )) .apply(cosmic::Element::from) diff --git a/cosmic-settings/src/pages/input/keyboard/shortcuts/mod.rs b/cosmic-settings/src/pages/input/keyboard/shortcuts/mod.rs index 363d86d4..f96b61a6 100644 --- a/cosmic-settings/src/pages/input/keyboard/shortcuts/mod.rs +++ b/cosmic-settings/src/pages/input/keyboard/shortcuts/mod.rs @@ -669,6 +669,6 @@ fn localize_custom_action(action: &Action, binding: &Binding) -> String { if let Some(description) = &binding.description { description.to_string() } else { - localize_action(&action) + localize_action(action) } } diff --git a/cosmic-settings/src/pages/power/backend/mod.rs b/cosmic-settings/src/pages/power/backend/mod.rs index 1d559796..6d616f78 100644 --- a/cosmic-settings/src/pages/power/backend/mod.rs +++ b/cosmic-settings/src/pages/power/backend/mod.rs @@ -16,8 +16,8 @@ pub trait GetCurrentPowerProfile { } pub enum PowerBackendEnum { - S76(S76Backend), - PP(PPBackend), + S76(S76), + PP(PP), } impl SetPowerProfile for PowerBackendEnum { @@ -38,15 +38,13 @@ impl GetCurrentPowerProfile for PowerBackendEnum { } } -pub trait PowerBackend: SetPowerProfile + GetCurrentPowerProfile {} - -pub async fn get_backend() -> Option { +pub async fn get() -> Option { match get_s76power_daemon_proxy().await { Ok(p) => match p.get_profile().await { - Ok(_) => Some(PowerBackendEnum::S76(S76Backend {})), + Ok(_) => Some(PowerBackendEnum::S76(S76 {})), Err(_) => match get_power_profiles_proxy().await { Ok(pr) => match pr.active_profile().await { - Ok(_) => Some(PowerBackendEnum::PP(PPBackend {})), + Ok(_) => Some(PowerBackendEnum::PP(PP {})), Err(_) => None, }, Err(()) => None, @@ -72,7 +70,7 @@ impl PowerProfile { } } - pub fn title(&self) -> String { + pub fn title(self) -> String { match self { Self::Battery => fl!("power-mode", "battery"), Self::Balanced => fl!("power-mode", "balanced"), @@ -80,7 +78,7 @@ impl PowerProfile { } } - pub fn description(&self) -> String { + pub fn description(self) -> String { match self { Self::Battery => fl!("power-mode", "battery-desc"), Self::Balanced => fl!("power-mode", "balanced-desc"), @@ -97,11 +95,9 @@ pub fn get_power_profiles() -> Vec { ] } -pub struct S76Backend {} - -impl PowerBackend for S76Backend {} +pub struct S76 {} -impl SetPowerProfile for S76Backend { +impl SetPowerProfile for S76 { async fn set_power_profile(&self, profile: PowerProfile) { let Ok(daemon) = get_s76power_daemon_proxy().await else { tracing::error!("Problem while setting power profile."); @@ -125,7 +121,7 @@ impl SetPowerProfile for S76Backend { } } -impl GetCurrentPowerProfile for S76Backend { +impl GetCurrentPowerProfile for S76 { async fn get_current_power_profile(&self) -> PowerProfile { let Ok(daemon) = get_s76power_daemon_proxy().await else { tracing::error!("Problem while getting power profile."); @@ -162,18 +158,15 @@ async fn get_s76power_daemon_proxy<'a>() -> Result c, - Err(()) => { - tracing::error!("Problem while setting power profile."); - return; - } + let daemon = if let Ok(c) = get_power_profiles_proxy().await { + c + } else { + tracing::error!("Problem while setting power profile."); + return; }; match profile { @@ -193,7 +186,7 @@ impl SetPowerProfile for PPBackend { } } -impl GetCurrentPowerProfile for PPBackend { +impl GetCurrentPowerProfile for PP { async fn get_current_power_profile(&self) -> PowerProfile { let Ok(daemon) = get_power_profiles_proxy().await else { tracing::error!("Problem while getting power profile."); @@ -422,34 +415,6 @@ impl Battery { } } -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_can_format_battery_remaining() { - let cases = [ - (59, "Less than a minute until empty"), - (300, "5 minutes until empty"), - (305, "5 minutes until empty"), - (330, "5 minutes until empty"), - (360, "6 minutes until empty"), - (3660, "1 hour and 1 minute until empty"), - (10800, "3 hours until empty"), - (969400, "11 days, 5 hours and 16 minutes until empty"), - ]; - for case in cases { - let (actual, expected) = case; - let battery = Battery { - remaining_duration: Duration::new(actual, 0).unwrap(), - on_battery: true, - ..Default::default() - }; - assert_eq!(battery.remaining_time(), expected); - } - } -} - impl ConnectedDevice { async fn from_device_maybe(proxy: DeviceProxy<'_>) -> Option { let device_type = proxy.type_().await.unwrap_or(BatteryType::Unknown); @@ -513,3 +478,31 @@ impl ConnectedDevice { vec![] } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_can_format_battery_remaining() { + let cases = [ + (59, "Less than a minute until empty"), + (300, "5 minutes until empty"), + (305, "5 minutes until empty"), + (330, "5 minutes until empty"), + (360, "6 minutes until empty"), + (3660, "1 hour and 1 minute until empty"), + (10800, "3 hours until empty"), + (969400, "11 days, 5 hours and 16 minutes until empty"), + ]; + for case in cases { + let (actual, expected) = case; + let battery = Battery { + remaining_duration: Duration::new(actual, 0).unwrap(), + on_battery: true, + ..Default::default() + }; + assert_eq!(battery.remaining_time(), expected); + } + } +} diff --git a/cosmic-settings/src/pages/power/mod.rs b/cosmic-settings/src/pages/power/mod.rs index e02e2e12..43bc698d 100644 --- a/cosmic-settings/src/pages/power/mod.rs +++ b/cosmic-settings/src/pages/power/mod.rs @@ -70,7 +70,7 @@ impl Page { pub fn update(&mut self, message: Message) { let runtime = tokio::runtime::Runtime::new().unwrap(); - let backend = runtime.block_on(backend::get_backend()); + let backend = runtime.block_on(backend::get()); match message { Message::PowerProfileChange(p) => { @@ -203,7 +203,7 @@ fn profiles() -> Section { let runtime = tokio::runtime::Runtime::new().unwrap(); - let backend = runtime.block_on(backend::get_backend()); + let backend = runtime.block_on(backend::get()); if let Some(b) = backend { let profiles = backend::get_power_profiles(); @@ -217,7 +217,7 @@ fn profiles() -> Section { widget::column::with_capacity(2) .push(text::body(profile.title())) .push(text::caption(profile.description())), - profile.clone(), + profile, Some(current_profile), Message::PowerProfileChange, ) diff --git a/cosmic-settings/src/pages/sound.rs b/cosmic-settings/src/pages/sound.rs index e83e1ee0..67712e6d 100644 --- a/cosmic-settings/src/pages/sound.rs +++ b/cosmic-settings/src/pages/sound.rs @@ -442,7 +442,7 @@ impl Page { Message::Pipewire(pipewire::DeviceEvent::Remove(node_id)) => { let mut remove = None; for (card_id, card) in &mut self.devices { - if card.devices.remove(&node_id).is_some() { + if card.devices.swap_remove(&node_id).is_some() { if card.devices.is_empty() { remove = Some(card_id.clone()); } @@ -746,25 +746,25 @@ fn output() -> Section { fn sort_pulse_devices(descriptions: &mut Vec, node_ids: &mut Vec) { let mut tmp: Vec<(String, NodeId)> = std::mem::take(descriptions) .into_iter() - .zip(std::mem::take(node_ids).into_iter()) + .zip(std::mem::take(node_ids)) .collect(); - tmp.sort_unstable_by(|(ak, _), (bk, _)| ak.cmp(&bk)); + tmp.sort_unstable_by(|(ak, _), (bk, _)| ak.cmp(bk)); (*descriptions, *node_ids) = tmp.into_iter().collect(); } async fn pactl_set_card_profile(id: String, profile: String) { _ = tokio::process::Command::new("pactl") - .args(&["set-card-profile", id.as_str(), profile.as_str()]) + .args(["set-card-profile", id.as_str(), profile.as_str()]) .status() - .await + .await; } fn pactl_set_default_sink(id: String) { tokio::task::spawn(async move { _ = tokio::process::Command::new("pactl") - .args(&["set-default-sink", id.as_str()]) + .args(["set-default-sink", id.as_str()]) .status() .await; }); @@ -773,7 +773,7 @@ fn pactl_set_default_sink(id: String) { fn pactl_set_default_source(id: String) { tokio::task::spawn(async move { _ = tokio::process::Command::new("pactl") - .args(&["set-default-source", id.as_str()]) + .args(["set-default-source", id.as_str()]) .status() .await; }); @@ -783,7 +783,7 @@ fn wpctl_set_mute(id: u32, mute: bool) { tokio::task::spawn(async move { let default = id.to_string(); _ = tokio::process::Command::new("wpctl") - .args(&["set-mute", default.as_str(), if mute { "1" } else { "0" }]) + .args(["set-mute", default.as_str(), if mute { "1" } else { "0" }]) .status() .await; }); @@ -794,7 +794,7 @@ fn wpctl_set_volume(id: u32, volume: u32) { let id = id.to_string(); let volume = format!("{}.{:02}", volume / 100, volume % 100); _ = tokio::process::Command::new("wpctl") - .args(&["set-volume", id.as_str(), volume.as_str()]) + .args(["set-volume", id.as_str(), volume.as_str()]) .status() .await; }); diff --git a/cosmic-settings/src/pages/time/date.rs b/cosmic-settings/src/pages/time/date.rs index 1f93b96f..0f7ad65d 100644 --- a/cosmic-settings/src/pages/time/date.rs +++ b/cosmic-settings/src/pages/time/date.rs @@ -369,7 +369,6 @@ impl page::AutoBind for Page {} fn date() -> Section { let mut descriptions = Slab::new(); - let auto = descriptions.insert(fl!("time-date", "auto")); let title = descriptions.insert(fl!("time-date")); Section::default() diff --git a/cosmic-settings/src/theme.rs b/cosmic-settings/src/theme.rs index 766ca737..4a66eb47 100644 --- a/cosmic-settings/src/theme.rs +++ b/cosmic-settings/src/theme.rs @@ -16,7 +16,7 @@ pub fn display_container_frame() -> cosmic::theme::Container { radius: cosmic.corner_radii.radius_xs.into(), width: 3.0, }, - shadow: Default::default(), + ..Default::default() } }) } @@ -34,7 +34,7 @@ pub fn display_container_screen() -> cosmic::theme::Container { radius: cosmic.corner_radii.radius_0.into(), width: 0.0, }, - shadow: Default::default(), + ..Default::default() } }) } diff --git a/page/src/binder.rs b/page/src/binder.rs index 235828c8..9a7190c6 100644 --- a/page/src/binder.rs +++ b/page/src/binder.rs @@ -74,7 +74,7 @@ impl Binder { if self.contains_item(id) { self.storage .entry(TypeId::of::()) - .or_insert_with(SecondaryMap::new) + .or_default() .insert(id, Box::new(data)); } } @@ -206,7 +206,7 @@ impl Binder { ) -> impl Iterator + 'a { self.content.iter().flat_map(move |(page, sections)| { sections - .into_iter() + .iter() .filter(|&id| self.sections[*id].search_matches(rule)) .map(move |&id| (page, id)) }) diff --git a/page/src/insert.rs b/page/src/insert.rs index 84700c48..aa589d4e 100644 --- a/page/src/insert.rs +++ b/page/src/insert.rs @@ -39,6 +39,11 @@ impl<'a, Message: 'static> Insert<'a, Message> { self } + /// Returns the sub page with id of this [`Insert`]. + /// + /// # Panics + /// + /// Panics if the page is missing #[allow(clippy::return_self_not_must_use)] #[allow(clippy::must_use_candidate)] pub fn sub_page_with_id>(&mut self) -> Entity { diff --git a/pages/wallpapers/src/lib.rs b/pages/wallpapers/src/lib.rs index 6dce108e..96a2c83b 100644 --- a/pages/wallpapers/src/lib.rs +++ b/pages/wallpapers/src/lib.rs @@ -95,7 +95,7 @@ pub fn cache_dir() -> Option { pub async fn load_each_from_path( path: PathBuf, recurse: bool, -) -> Pin>> { +) -> Pin>> { let wallpapers = tokio::task::spawn_blocking(move || { // Directories to search recursively. let mut paths = vec![path]; @@ -147,14 +147,15 @@ pub async fn load_each_from_path( } } +#[derive(Debug)] +pub struct ImageSelection { + pub path: PathBuf, + pub display_thumbnail: ImageBuffer, Vec>, + pub selection_thumbnail: ImageBuffer, Vec>, +} + #[must_use] -pub fn load_image_with_thumbnail( - path: PathBuf, -) -> Option<( - PathBuf, - ImageBuffer, Vec>, - ImageBuffer, Vec>, -)> { +pub fn load_image_with_thumbnail(path: PathBuf) -> Option { let cache_dir = cache_dir(); let image_operation = load_thumbnail(&mut Vec::new(), cache_dir.as_deref(), &path); @@ -194,7 +195,11 @@ pub fn load_image_with_thumbnail( round(&mut selection_thumbnail, [8, 8, 8, 8]); - Some((path, display_thumbnail, selection_thumbnail)) + Some(ImageSelection { + path, + display_thumbnail, + selection_thumbnail, + }) } else { None } @@ -336,7 +341,7 @@ fn border_radius( let draw = |img: &mut RgbaImage, alpha, x, y| { debug_assert!((1..=256).contains(&alpha)); let pixel_alpha = &mut img[coordinates(r0 - x, r0 - y)].0[3]; - *pixel_alpha = ((alpha * *pixel_alpha as u16 + 128) / 256) as u8; + *pixel_alpha = ((alpha * u16::from(*pixel_alpha) + 128) / 256) as u8; }; 'l: loop {