diff --git a/cosmic-app-list/src/app.rs b/cosmic-app-list/src/app.rs index 932ffd6ca..4ff59baaf 100755 --- a/cosmic-app-list/src/app.rs +++ b/cosmic-app-list/src/app.rs @@ -310,15 +310,16 @@ impl DockItem { icon_button.into() }; + let icon_origin = iced::Vector::new(app_icon.padding.left, app_icon.padding.top); let path = desktop_info.path.clone(); let icon_button = if dnd_source_enabled && interaction_enabled { DndSource::with_id(icon_button, cosmic::widget::Id::new("asdfasdfadfs")) .window(window_id) - .drag_icon(move |_| { + .drag_icon(move |pointer_offset| { ( cosmic_icon.clone().into(), iced::core::widget::tree::State::None, - iced::Vector::ZERO, + icon_origin - pointer_offset, ) }) .drag_threshold(16.) @@ -336,6 +337,15 @@ impl DockItem { icon_button.into() } } + + fn as_dragged_item(&self, applet: &Context) -> Element<'_, Message> { + let app_icon = AppletIconData::new(applet); + + container(horizontal_space()) + .width(app_icon.icon_size as f32 + app_icon.padding.left + app_icon.padding.right) + .height(app_icon.icon_size as f32 + app_icon.padding.top + app_icon.padding.bottom) + .into() + } } #[derive(Debug, Clone, Default)] @@ -361,6 +371,7 @@ struct CosmicAppList { desktop_entries: Vec, active_list: Vec, pinned_list: Vec, + dragged_item: Option, dnd_source: Option<(window::Id, DockItem, DndAction, Option)>, config: AppListConfig, wayland_sender: Option>, @@ -421,40 +432,21 @@ enum Message { } fn index_in_list( - mut list_len: usize, + list_len: usize, item_size: f32, - divider_size: f32, + center_threshold: f32, existing_preview: Option, pos_in_list: f32, ) -> usize { - if existing_preview.is_some() { - list_len += 1; - } - - let index = if (list_len == 0) || (pos_in_list < item_size / 2.0) { - 0 - } else { - let mut i = 1; - let mut pos = item_size / 2.0; - while i < list_len { - let next_pos = pos + item_size + divider_size; - if pos < pos_in_list && pos_in_list < next_pos { - break; - } - pos = next_pos; - i += 1; - } - i - }; + let current_index = existing_preview.unwrap_or(0); + let current_center = current_index as f32 * item_size + item_size / 2.0; - if let Some(existing_preview) = existing_preview { - if index >= existing_preview { - index.saturating_sub(1) - } else { - index - } + if pos_in_list > current_center + item_size - center_threshold { + (current_index + 1).min(list_len) + } else if pos_in_list < current_center - item_size + center_threshold { + current_index.saturating_sub(1) } else { - index + current_index } } @@ -665,7 +657,7 @@ impl CosmicAppList { .output_list .iter() .find(|(_, info)| info.name.as_ref() == Some(&self.core.applet.output_name)) - .map_or(true, |(active_output, _)| { + .is_none_or(|(active_output, _)| { toplevel_info .output .iter() @@ -1131,26 +1123,36 @@ impl cosmic::Application for CosmicAppList { }) { let icon_id = window::Id::unique(); + if let Some(pinned_pos) = pos { + let entry = self.pinned_list.remove(pinned_pos); + if !entry.toplevels.is_empty() { + self.dragged_item = Some(entry); + } + } self.dnd_source = Some((icon_id, toplevel_group.clone(), DndAction::empty(), pos)); + self.dnd_offer = Some(DndOffer { + dock_item: Some(toplevel_group), + preview_index: pos.unwrap_or(self.pinned_list.len()), + }); } } Message::DragFinished => { if let Some((_, mut toplevel_group, _, _pinned_pos)) = self.dnd_source.take() { - if self.dnd_offer.take().is_some() { - if let Some((_, toplevel_group, _, pinned_pos)) = self.dnd_source.as_ref() { - let mut pos = 0; - self.pinned_list.retain_mut(|pinned| { - let matched_id = - pinned.desktop_info.id() == toplevel_group.desktop_info.id(); - let pinned_match = - pinned_pos.is_some_and(|pinned_pos| pinned_pos == pos); - let ret = !matched_id || pinned_match; - - pos += 1; - ret - }); - } + if self.dnd_offer.take().is_some() + && let Some((_, toplevel_group, _, pinned_pos)) = self.dnd_source.as_ref() + { + let mut pos = 0; + self.pinned_list.retain_mut(|pinned| { + let matched_id = + pinned.desktop_info.id() == toplevel_group.desktop_info.id(); + let pinned_match = + pinned_pos.is_some_and(|pinned_pos| pinned_pos == pos); + let ret = !matched_id || pinned_match; + + pos += 1; + ret + }); } if !self @@ -1175,14 +1177,20 @@ impl cosmic::Application for CosmicAppList { }; let num_pinned = self.pinned_list.len(); let index = index_in_list(num_pinned, item_size as f32, 4.0, None, pos_in_list); - self.dnd_offer = Some(DndOffer { - preview_index: index, - ..DndOffer::default() - }); if let Some(dnd_source) = self.dnd_source.as_ref() { - self.dnd_offer.as_mut().unwrap().dock_item = Some(dnd_source.1.clone()); + let source_id = dnd_source.1.desktop_info.id().to_string(); + self.pinned_list + .retain(|p| p.desktop_info.id() != source_id); + + self.dnd_offer = Some(DndOffer { + preview_index: index, + dock_item: Some(dnd_source.1.clone()), + }); } else { - // TODO dnd + self.dnd_offer = Some(DndOffer { + preview_index: index, + ..DndOffer::default() + }); return peek_dnd::() .map(Message::DndData) .map(cosmic::Action::App); @@ -1208,17 +1216,9 @@ impl cosmic::Application for CosmicAppList { } } Message::DndLeave => { - if let Some((_, toplevel_group, _, pinned_pos)) = self.dnd_source.as_ref() { - let mut pos = 0; - self.pinned_list.retain_mut(|pinned| { - let matched_id = - pinned.desktop_info.id() == toplevel_group.desktop_info.id(); - let pinned_match = pinned_pos.is_some_and(|pinned_pos| pinned_pos == pos); - let ret = !matched_id || pinned_match; - - pos += 1; - ret - }); + if let Some(dragged_item) = self.dragged_item.take() { + self.active_list.push(dragged_item); + self.dragged_item = None; } self.dnd_offer = None; } @@ -1227,16 +1227,16 @@ impl cosmic::Application for CosmicAppList { tracing::error!("Couldn't peek at hovered path."); return Task::none(); }; - if let Some(DndOffer { dock_item, .. }) = self.dnd_offer.as_mut() { - if let Ok(de) = fde::DesktopEntry::from_path(file_path.0, Some(&self.locales)) { - self.item_ctr += 1; - *dock_item = Some(DockItem { - id: self.item_ctr, - toplevels: Vec::new(), - original_app_id: de.id().to_string(), - desktop_info: de, - }); - } + if let Some(DndOffer { dock_item, .. }) = self.dnd_offer.as_mut() + && let Ok(de) = fde::DesktopEntry::from_path(file_path.0, Some(&self.locales)) + { + self.item_ctr += 1; + *dock_item = Some(DockItem { + id: self.item_ctr, + toplevels: Vec::new(), + original_app_id: de.id().to_string(), + desktop_info: de, + }); } } Message::DndDropFinished => { @@ -1818,25 +1818,9 @@ impl cosmic::Application for CosmicAppList { .as_ref() .and_then(|o| o.dock_item.as_ref().map(|item| (item, o.preview_index))) { - let filtered_is_focused = item - .toplevels - .iter() - .filter(|(info, _)| self.is_on_current_monitor_and_workspace(info)) - .any(|y| focused_item.contains(&y.0.foreign_toplevel)); - favorites.insert( index.min(favorites.len()), - item.as_icon( - &self.core.applet, - None, - false, - self.config.enable_drag_source, - self.gpus.as_deref(), - filtered_is_focused, - dot_radius, - self.core.main_window_id().unwrap(), - Some(&|info| self.is_on_current_monitor_and_workspace(info)), - ), + item.as_dragged_item(&self.core.applet), ); } else if self.is_listening_for_dnd && self.pinned_list.is_empty() { // show star indicating pinned_list is drag target diff --git a/cosmic-app-list/src/wayland_handler.rs b/cosmic-app-list/src/wayland_handler.rs index 03c16973d..334458135 100644 --- a/cosmic-app-list/src/wayland_handler.rs +++ b/cosmic-app-list/src/wayland_handler.rs @@ -624,11 +624,11 @@ pub(crate) fn wayland_handler( } WaylandRequest::Toplevel(req) => match req { ToplevelRequest::Activate(handle) => { - if let Some(cosmic_toplevel) = state.cosmic_toplevel(&handle) { - if let Some(seat) = state.seat_state.seats().next() { - let manager = &state.toplevel_manager_state.manager; - manager.activate(&cosmic_toplevel, &seat); - } + if let Some(cosmic_toplevel) = state.cosmic_toplevel(&handle) + && let Some(seat) = state.seat_state.seats().next() + { + let manager = &state.toplevel_manager_state.manager; + manager.activate(&cosmic_toplevel, &seat); } } ToplevelRequest::Minimize(handle) => { diff --git a/cosmic-applet-a11y/src/app.rs b/cosmic-applet-a11y/src/app.rs index ad5f2a1ee..acf29b05a 100644 --- a/cosmic-applet-a11y/src/app.rs +++ b/cosmic-applet-a11y/src/app.rs @@ -26,10 +26,9 @@ use cosmic::{ }; use cosmic_settings_a11y_manager_subscription::{ - self as cosmic_a11y_manager, AccessibilityEvent, AccessibilityRequest, ColorFilter, + AccessibilityEvent, AccessibilityRequest, ColorFilter, }; use cosmic_settings_accessibility_subscription::{self as accessibility}; -use std::sync::LazyLock; use tokio::sync::mpsc::UnboundedSender; pub fn run() -> cosmic::iced::Result { diff --git a/cosmic-applet-a11y/src/backend/wayland/mod.rs b/cosmic-applet-a11y/src/backend/wayland/mod.rs index fa9796f07..123405889 100644 --- a/cosmic-applet-a11y/src/backend/wayland/mod.rs +++ b/cosmic-applet-a11y/src/backend/wayland/mod.rs @@ -2,13 +2,12 @@ // SPDX-License-Identifier: GPL-3.0-only use anyhow; -use cctk::sctk::reexports::calloop::{self, channel::SyncSender}; +use cctk::sctk::reexports::calloop::{self}; use cosmic::iced::{ self, Subscription, - futures::{self, SinkExt, StreamExt, channel::mpsc}, + futures::{self, SinkExt}, stream, }; -use cosmic_protocols::a11y::v1::client::cosmic_a11y_manager_v1::Filter; use cosmic_settings_a11y_manager_subscription::{ self as thread, AccessibilityEvent, AccessibilityRequest, }; diff --git a/cosmic-applet-audio/src/lib.rs b/cosmic-applet-audio/src/lib.rs index 5f49d0f9b..e87946483 100644 --- a/cosmic-applet-audio/src/lib.rs +++ b/cosmic-applet-audio/src/lib.rs @@ -360,10 +360,9 @@ impl cosmic::Application for Audio { self.config.show_media_controls_in_top_panel = enabled; if let Ok(helper) = cosmic::cosmic_config::Config::new(Self::APP_ID, AudioAppletConfig::VERSION) + && let Err(err) = self.config.write_entry(&helper) { - if let Err(err) = self.config.write_entry(&helper) { - tracing::error!(?err, "Error writing config"); - } + tracing::error!(?err, "Error writing config"); } } Message::CloseRequested(id) => { diff --git a/cosmic-applet-audio/src/mouse_area.rs b/cosmic-applet-audio/src/mouse_area.rs index 6ae8547af..b837d60a7 100644 --- a/cosmic-applet-audio/src/mouse_area.rs +++ b/cosmic-applet-audio/src/mouse_area.rs @@ -5,7 +5,7 @@ use cosmic::iced::core::Point; use cosmic::iced::core::{ Clipboard, Element, Layout, Length, Rectangle, Shell, Size, Widget, - event::{self, Event}, + event::Event, layout, mouse, overlay, renderer, touch, widget::{Operation, Tree, tree}, }; @@ -191,7 +191,7 @@ where ) { self.content.as_widget_mut().update( &mut tree.children[0], - &event, + event, layout, cursor, renderer, @@ -205,7 +205,7 @@ where update( self, - &event, + event, layout, cursor, shell, @@ -308,96 +308,90 @@ fn update( state: &mut State, ) { if !cursor.is_over(layout.bounds()) { - if !state.is_out_of_bounds { - if widget + if !state.is_out_of_bounds + && widget .on_mouse_enter .as_ref() .or(widget.on_mouse_exit.as_ref()) .is_some() - { - if let Event::Mouse(mouse::Event::CursorMoved { .. }) = event { - state.is_out_of_bounds = true; - if let Some(message) = widget.on_mouse_exit.as_ref() { - shell.publish(message.clone()); - } - shell.capture_event(); - return; - } + && let Event::Mouse(mouse::Event::CursorMoved { .. }) = event + { + state.is_out_of_bounds = true; + if let Some(message) = widget.on_mouse_exit.as_ref() { + shell.publish(message.clone()); } + shell.capture_event(); + return; } return; } - if let Some(message) = widget.on_press.as_ref() { - if let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) + if let Some(message) = widget.on_press.as_ref() + && let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) | Event::Touch(touch::Event::FingerPressed { .. }) = event - { - state.drag_initiated = cursor.position(); - shell.publish(message.clone()); - shell.capture_event(); - return; - } + { + state.drag_initiated = cursor.position(); + shell.publish(message.clone()); + shell.capture_event(); + return; } - if let Some(message) = widget.on_release.as_ref() { - if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) + if let Some(message) = widget.on_release.as_ref() + && let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) | Event::Touch(touch::Event::FingerLifted { .. }) = event - { - state.drag_initiated = None; - shell.publish(message.clone()); - shell.capture_event(); - return; - } + { + state.drag_initiated = None; + shell.publish(message.clone()); + shell.capture_event(); + return; } - if let Some(message) = widget.on_right_press.as_ref() { - if let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Right)) = event { - shell.publish(message.clone()); - shell.capture_event(); - return; - } + if let Some(message) = widget.on_right_press.as_ref() + && let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Right)) = event + { + shell.publish(message.clone()); + shell.capture_event(); + return; } - if let Some(message) = widget.on_right_release.as_ref() { - if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Right)) = event { - shell.publish(message.clone()); - shell.capture_event(); - return; - } + if let Some(message) = widget.on_right_release.as_ref() + && let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Right)) = event + { + shell.publish(message.clone()); + shell.capture_event(); + return; } - if let Some(message) = widget.on_middle_press.as_ref() { - if let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Middle)) = event { - shell.publish(message.clone()); - shell.capture_event(); - return; - } + if let Some(message) = widget.on_middle_press.as_ref() + && let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Middle)) = event + { + shell.publish(message.clone()); + shell.capture_event(); + return; } - if let Some(message) = widget.on_middle_release.as_ref() { - if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Middle)) = event { - shell.publish(message.clone()); + if let Some(message) = widget.on_middle_release.as_ref() + && let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Middle)) = event + { + shell.publish(message.clone()); - shell.capture_event(); - return; - } + shell.capture_event(); + return; } if let Some(message) = widget .on_mouse_enter .as_ref() .or(widget.on_mouse_exit.as_ref()) + && let Event::Mouse(mouse::Event::CursorMoved { .. }) = event + && state.is_out_of_bounds { - if let Event::Mouse(mouse::Event::CursorMoved { .. }) = event { - if state.is_out_of_bounds { - state.is_out_of_bounds = false; - if widget.on_mouse_enter.is_some() { - shell.publish(message.clone()); - } - shell.capture_event(); - return; - } + state.is_out_of_bounds = false; + if widget.on_mouse_enter.is_some() { + shell.publish(message.clone()); } + shell.capture_event(); + return; } if state.drag_initiated.is_none() && widget.on_drag.is_some() { @@ -406,22 +400,20 @@ fn update( { state.drag_initiated = cursor.position(); } - } else if let Some((message, drag_source)) = widget.on_drag.as_ref().zip(state.drag_initiated) { - if let Some(position) = cursor.position() { - if position.distance(drag_source) > 1.0 { - state.drag_initiated = None; - shell.publish(message.clone()); - shell.capture_event(); - return; - } - } + } else if let Some((message, drag_source)) = widget.on_drag.as_ref().zip(state.drag_initiated) + && let Some(position) = cursor.position() + && position.distance(drag_source) > 1.0 + { + state.drag_initiated = None; + shell.publish(message.clone()); + shell.capture_event(); + return; } - if let Some(message) = widget.on_mouse_wheel.as_ref() { - if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event { - shell.publish((message)(*delta)); - shell.capture_event(); - return; - } + if let Some(message) = widget.on_mouse_wheel.as_ref() + && let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event + { + shell.publish((message)(*delta)); + shell.capture_event(); } } diff --git a/cosmic-applet-battery/src/app.rs b/cosmic-applet-battery/src/app.rs index 9233a33fd..201bcc6b2 100644 --- a/cosmic-applet-battery/src/app.rs +++ b/cosmic-applet-battery/src/app.rs @@ -40,7 +40,7 @@ use cosmic_settings_upower_subscription::{ }; use rustc_hash::FxHashMap; -use std::{path::PathBuf, sync::LazyLock, time::Duration}; +use std::{path::PathBuf, time::Duration}; use tokio::sync::mpsc::UnboundedSender; // XXX improve @@ -276,10 +276,10 @@ impl cosmic::Application for CosmicBatteryApplet { if !self.dragging_kbd_brightness { return Task::none(); } - if let Some(tx) = &self.kbd_sender { - if let Some(b) = self.kbd_brightness { - let _ = tx.send(KeyboardBacklightRequest::Set(b)); - } + if let Some(tx) = &self.kbd_sender + && let Some(b) = self.kbd_brightness + { + let _ = tx.send(KeyboardBacklightRequest::Set(b)); } return cosmic::iced::Task::perform( tokio::time::sleep(Duration::from_millis(200)), @@ -291,10 +291,10 @@ impl cosmic::Application for CosmicBatteryApplet { return Task::none(); } - if let Some(tx) = &self.settings_daemon_sender { - if let Some(b) = self.screen_brightness { - let _ = tx.send(settings_daemon::Request::SetDisplayBrightness(b)); - } + if let Some(tx) = &self.settings_daemon_sender + && let Some(b) = self.screen_brightness + { + let _ = tx.send(settings_daemon::Request::SetDisplayBrightness(b)); } return cosmic::iced::Task::perform( tokio::time::sleep(Duration::from_millis(200)), @@ -303,20 +303,20 @@ impl cosmic::Application for CosmicBatteryApplet { } Message::ReleaseKbdBrightness => { self.dragging_kbd_brightness = false; - if let Some(tx) = &self.kbd_sender { - if let Some(b) = self.kbd_brightness { - let _ = tx.send(KeyboardBacklightRequest::Set(b)); - } + if let Some(tx) = &self.kbd_sender + && let Some(b) = self.kbd_brightness + { + let _ = tx.send(KeyboardBacklightRequest::Set(b)); } } Message::ReleaseScreenBrightness => { self.dragging_screen_brightness = false; self.update_display(); - if let Some(tx) = &self.settings_daemon_sender { - if let Some(b) = self.screen_brightness { - let _ = tx.send(settings_daemon::Request::SetDisplayBrightness(b)); - } + if let Some(tx) = &self.settings_daemon_sender + && let Some(b) = self.screen_brightness + { + let _ = tx.send(settings_daemon::Request::SetDisplayBrightness(b)); } } Message::InitChargingLimit(enable) => { @@ -511,7 +511,7 @@ impl cosmic::Application for CosmicBatteryApplet { Task::none() } - fn view(&self) -> Element { + fn view(&self) -> Element<'_, Message> { let is_horizontal = match self.core.applet.anchor { PanelAnchor::Top | PanelAnchor::Bottom => true, PanelAnchor::Left | PanelAnchor::Right => false, @@ -753,66 +753,66 @@ impl cosmic::Application for CosmicBatteryApplet { ); } - if let Some(max_screen_brightness) = self.max_screen_brightness { - if let Some(screen_brightness) = self.screen_brightness { - content.push( - padded_control( - row![ - icon::from_name(self.display_icon_name.as_str()) - .size(24) - .symbolic(true), - slider( - 0..=max_screen_brightness, - screen_brightness, - Message::SetScreenBrightness - ) - .on_release(Message::ReleaseScreenBrightness), - container( - text(format!( - "{:.0}%", - self.screen_brightness_percent().unwrap_or(0.) * 100. - )) - .size(16) - ) - .width(Length::Fixed(40.0)) - .align_x(Alignment::End) - ] - .spacing(12), - ) - .into(), - ); - } + if let Some(max_screen_brightness) = self.max_screen_brightness + && let Some(screen_brightness) = self.screen_brightness + { + content.push( + padded_control( + row![ + icon::from_name(self.display_icon_name.as_str()) + .size(24) + .symbolic(true), + slider( + 0..=max_screen_brightness, + screen_brightness, + Message::SetScreenBrightness + ) + .on_release(Message::ReleaseScreenBrightness), + container( + text(format!( + "{:.0}%", + self.screen_brightness_percent().unwrap_or(0.) * 100. + )) + .size(16) + ) + .width(Length::Fixed(40.0)) + .align_x(Alignment::End) + ] + .spacing(12), + ) + .into(), + ); } - if let Some(max_kbd_brightness) = self.max_kbd_brightness { - if let Some(kbd_brightness) = self.kbd_brightness { - content.push( - padded_control( - row![ - icon::from_name("keyboard-brightness-symbolic") - .size(24) - .symbolic(true), - slider( - 0..=max_kbd_brightness, - kbd_brightness, - Message::SetKbdBrightness - ) - .on_release(Message::ReleaseKbdBrightness), - container( - text(format!( - "{:.0}%", - 100. * kbd_brightness as f64 / max_kbd_brightness as f64 - )) - .size(16) - ) - .width(Length::Fixed(40.0)) - .align_x(Alignment::End) - ] - .spacing(12), - ) - .into(), - ); - } + if let Some(max_kbd_brightness) = self.max_kbd_brightness + && let Some(kbd_brightness) = self.kbd_brightness + { + content.push( + padded_control( + row![ + icon::from_name("keyboard-brightness-symbolic") + .size(24) + .symbolic(true), + slider( + 0..=max_kbd_brightness, + kbd_brightness, + Message::SetKbdBrightness + ) + .on_release(Message::ReleaseKbdBrightness), + container( + text(format!( + "{:.0}%", + 100. * kbd_brightness as f64 / max_kbd_brightness as f64 + )) + .size(16) + ) + .width(Length::Fixed(40.0)) + .align_x(Alignment::End) + ] + .spacing(12), + ) + .into(), + ); } content.push( diff --git a/cosmic-applet-battery/src/backend/mod.rs b/cosmic-applet-battery/src/backend/mod.rs index 641798e40..3df8f9400 100644 --- a/cosmic-applet-battery/src/backend/mod.rs +++ b/cosmic-applet-battery/src/backend/mod.rs @@ -214,18 +214,18 @@ pub enum PowerProfileUpdate { // check if battery charging thresholds is set pub async fn get_charging_limit() -> anyhow::Result { - if let Ok(conn) = Connection::system().await { - if let Ok(backend) = get_power_backend(&conn, &BackendType::S76PowerDaemon).await { - match backend { - Backend::S76PowerDaemon(proxy) => { - if let Ok((start, end)) = proxy.get_charge_thresholds().await { - return Ok(end > start && end < 100); - } - } - Backend::PowerProfilesDaemon(_) => { - tracing::info!("Power Profiles Daemon is not supported."); + if let Ok(conn) = Connection::system().await + && let Ok(backend) = get_power_backend(&conn, &BackendType::S76PowerDaemon).await + { + match backend { + Backend::S76PowerDaemon(proxy) => { + if let Ok((start, end)) = proxy.get_charge_thresholds().await { + return Ok(end > start && end < 100); } } + Backend::PowerProfilesDaemon(_) => { + tracing::info!("Power Profiles Daemon is not supported."); + } } } anyhow::bail!("Unsupported") @@ -233,17 +233,17 @@ pub async fn get_charging_limit() -> anyhow::Result { // set battery charging thresholds via s76 power_daemon pub async fn set_charging_limit() -> Result<()> { - if let Ok(conn) = Connection::system().await { - if let Ok(backend) = get_power_backend(&conn, &BackendType::S76PowerDaemon).await { - match backend { - Backend::S76PowerDaemon(proxy) => { - let _ = proxy.set_charge_thresholds(&(70, 80)).await; - } - Backend::PowerProfilesDaemon(_) => { - tracing::info!( - "Setting charging limit via Power Profiles Daemon is not supported." - ); - } + if let Ok(conn) = Connection::system().await + && let Ok(backend) = get_power_backend(&conn, &BackendType::S76PowerDaemon).await + { + match backend { + Backend::S76PowerDaemon(proxy) => { + let _ = proxy.set_charge_thresholds(&(70, 80)).await; + } + Backend::PowerProfilesDaemon(_) => { + tracing::info!( + "Setting charging limit via Power Profiles Daemon is not supported." + ); } } } @@ -252,17 +252,17 @@ pub async fn set_charging_limit() -> Result<()> { // unset battery charging thresholds via s76 power_daemon pub async fn unset_charging_limit() -> Result<()> { - if let Ok(conn) = Connection::system().await { - if let Ok(backend) = get_power_backend(&conn, &BackendType::S76PowerDaemon).await { - match backend { - Backend::S76PowerDaemon(proxy) => { - let _ = proxy.set_charge_thresholds(&(90, 100)).await; - } - Backend::PowerProfilesDaemon(_) => { - tracing::info!( - "Unsetting charging limit via Power Profiles Daemon is not supported." - ); - } + if let Ok(conn) = Connection::system().await + && let Ok(backend) = get_power_backend(&conn, &BackendType::S76PowerDaemon).await + { + match backend { + Backend::S76PowerDaemon(proxy) => { + let _ = proxy.set_charge_thresholds(&(90, 100)).await; + } + Backend::PowerProfilesDaemon(_) => { + tracing::info!( + "Unsetting charging limit via Power Profiles Daemon is not supported." + ); } } } diff --git a/cosmic-applet-battery/src/dgpu.rs b/cosmic-applet-battery/src/dgpu.rs index 62325e1f5..dec85e1a6 100644 --- a/cosmic-applet-battery/src/dgpu.rs +++ b/cosmic-applet-battery/src/dgpu.rs @@ -525,11 +525,10 @@ async fn start_listening( } }, EventType::Change => { - if let Some(path) = event.devnode() { - if let Some(gpu) = monitor.gpus.iter_mut().find(|gpu| gpu.path == path) { + if let Some(path) = event.devnode() + && let Some(gpu) = monitor.gpus.iter_mut().find(|gpu| gpu.path == path) { gpu.interval.reset_immediately(); } - } } EventType::Remove => { if let Some(path) = event.devnode() { diff --git a/cosmic-applet-bluetooth/src/app.rs b/cosmic-applet-bluetooth/src/app.rs index 2ca95ec5f..dbb92bd57 100644 --- a/cosmic-applet-bluetooth/src/app.rs +++ b/cosmic-applet-bluetooth/src/app.rs @@ -24,7 +24,7 @@ use cosmic::{ widget::{button, divider, icon, scrollable, text}, }; use futures::FutureExt; -use std::{collections::HashMap, sync::LazyLock, time::Duration}; +use std::{collections::HashMap, time::Duration}; use tokio::sync::mpsc::Sender; use crate::{ @@ -145,7 +145,7 @@ impl cosmic::Application for CosmicBluetoothApplet { } Message::BluetoothEvent(e) => match e { BluerEvent::RequestResponse { - req, + req: _, state, err_msg, } => { diff --git a/cosmic-applet-bluetooth/src/bluetooth.rs b/cosmic-applet-bluetooth/src/bluetooth.rs index b3648acd5..9b9aaf14f 100644 --- a/cosmic-applet-bluetooth/src/bluetooth.rs +++ b/cosmic-applet-bluetooth/src/bluetooth.rs @@ -97,10 +97,10 @@ pub fn bluetooth_subscription( // Initialize connection. let mut session_state = loop { - if let Ok(session) = Session::new().await { - if let Ok(state) = BluerSessionState::new(session).await { - break state; - } + if let Ok(session) = Session::new().await + && let Ok(state) = BluerSessionState::new(session).await + { + break state; } retry_count = retry_count.saturating_add(1); @@ -748,18 +748,16 @@ impl BluerSessionState { (name == cname).then_some(id.to_string()) }) }) - { - if let Err(err) = tokio::process::Command::new("rfkill") + && let Err(err) = tokio::process::Command::new("rfkill") .env("PATH", rfkill_path_var()) .arg(if *enabled { "unblock" } else { "block" }) .arg(id) .output() .await - { - tracing::error!( - "Failed to set bluetooth state using rfkill. {err:?}" - ); - } + { + tracing::error!( + "Failed to set bluetooth state using rfkill. {err:?}" + ); } if *enabled { @@ -774,10 +772,8 @@ impl BluerSessionState { let res = device.pair().await; if let Err(err) = res { err_msg = Some(err.to_string()); - } else { - if let Err(err) = device.set_trusted(true).await { - tracing::error!(?err, "Failed to trust device."); - } + } else if let Err(err) = device.set_trusted(true).await { + tracing::error!(?err, "Failed to trust device."); } } } @@ -789,10 +785,8 @@ impl BluerSessionState { let res = device.connect().await; if let Err(err) = res { err_msg = Some(err.to_string()); - } else { - if let Err(err) = device.set_trusted(true).await { - tracing::error!(?err, "Failed to trust device."); - } + } else if let Err(err) = device.set_trusted(true).await { + tracing::error!(?err, "Failed to trust device."); } } } diff --git a/cosmic-applet-input-sources/src/lib.rs b/cosmic-applet-input-sources/src/lib.rs index 93e842832..4c0de3476 100644 --- a/cosmic-applet-input-sources/src/lib.rs +++ b/cosmic-applet-input-sources/src/lib.rs @@ -3,7 +3,6 @@ mod localize; -use cosmic::iced::{Alignment, Length}; use cosmic::{ app, app::Core, @@ -11,19 +10,17 @@ use cosmic::{ cosmic_config::{self, ConfigSet, CosmicConfigEntry}, cosmic_theme::Spacing, iced::Subscription, + iced::core::window, iced::{ Rectangle, Task, platform_specific::shell::commands::popup::{destroy_popup, get_popup}, - widget::{column, row}, window::Id, }, - iced::{core::window, runtime::Appearance}, prelude::*, surface, theme, widget::{ self, autosize, rectangle_tracker::{RectangleTracker, RectangleUpdate, rectangle_tracker_subscription}, - space, }, }; use cosmic_comp_config::CosmicCompConfig; @@ -192,12 +189,11 @@ impl cosmic::Application for Window { self.comp_config.xkb_config.layout = new_layout; self.comp_config.xkb_config.variant = new_variant; - if let Some(comp_config_handler) = &self.comp_config_handler { - if let Err(err) = + if let Some(comp_config_handler) = &self.comp_config_handler + && let Err(err) = comp_config_handler.set("xkb_config", &self.comp_config.xkb_config) - { - tracing::error!("Failed to set config 'xkb_config' {err}"); - } + { + tracing::error!("Failed to set config 'xkb_config' {err}"); } } Message::Surface(a) => { diff --git a/cosmic-applet-minimize/src/lib.rs b/cosmic-applet-minimize/src/lib.rs index e40a75511..307762b5a 100644 --- a/cosmic-applet-minimize/src/lib.rs +++ b/cosmic-applet-minimize/src/lib.rs @@ -316,7 +316,7 @@ impl cosmic::Application for Minimize { } else { (cross_padding, major_padding) }; - let theme = self.core.system_theme().cosmic(); + let _theme = self.core.system_theme().cosmic(); let icon_buttons = self.apps[..max_icon_count].iter().map(|app| { self.core .applet @@ -420,7 +420,7 @@ impl cosmic::Application for Minimize { (cross_padding, major_padding) }; let theme = self.core.system_theme().cosmic(); - let space_xxs = theme.space_xxs(); + let _space_xxs = theme.space_xxs(); let icon_buttons = self.apps[max_icon_count..].iter().map(|app| { tooltip( Element::from(crate::window_image::WindowImage::new( diff --git a/cosmic-applet-network/src/app.rs b/cosmic-applet-network/src/app.rs index 727d9b107..af40128e9 100644 --- a/cosmic-applet-network/src/app.rs +++ b/cosmic-applet-network/src/app.rs @@ -2,7 +2,6 @@ use anyhow::Context; use cosmic_dbus_networkmanager::settings::{NetworkManagerSettings, connection::Settings}; use cosmic_settings_network_manager_subscription::{ self as network_manager, NetworkManagerState, UUID, - active_conns::active_conns_subscription, available_wifi::{AccessPoint, NetworkType}, current_networks::ActiveConnectionInfo, hw_address::HwAddress, @@ -15,7 +14,6 @@ use std::{ borrow::Cow, collections::{BTreeMap, BTreeSet}, sync::{Arc, LazyLock}, - time::Duration, }; use cosmic::{ @@ -33,17 +31,16 @@ use cosmic::{ }, surface, theme, widget::{ - Column, Id, Row, button, column, container, divider, + Id, button, column, container, divider, icon::{self, from_name}, row, scrollable, secure_input, text, text_input, toggler, }, }; -use cosmic_dbus_networkmanager::interface::{ - access_point, - enums::{ActiveConnectionState, DeviceState, NmConnectivityState, NmState}, +use cosmic_dbus_networkmanager::interface::enums::{ + ActiveConnectionState, DeviceState, NmConnectivityState, }; -use futures::{StreamExt, channel::mpsc::TrySendError}; +use futures::StreamExt; use zbus::{Connection, zvariant::ObjectPath}; use crate::{config, fl}; @@ -400,39 +397,38 @@ impl CosmicNetworkApplet { if let Some((tx, conn)) = self.nm_sender.clone().zip(self.conn.clone()) { cosmic::task::future(async move { // Find the connection by UUID - if let Ok(nm_settings) = NetworkManagerSettings::new(&conn).await { - if let Ok(connections) = nm_settings.list_connections().await { - for connection in connections { - if let Ok(settings) = connection.get_settings().await { - let settings = Settings::new(settings); - if let Some(conn_settings) = &settings.connection { - if conn_settings.uuid.as_ref().is_some_and(|conn_uuid| { - conn_uuid.as_str() == uuid.as_ref() - }) { - let path = connection.inner().path().clone().to_owned(); - if let Err(err) = - tx.unbounded_send(network_manager::Request::Activate( - ObjectPath::try_from("/").unwrap(), - path, - )) - { - if err.is_disconnected() { - return zbus::Connection::system() - .await - .context( - "failed to create system dbus connection", - ) - .map_or_else( - |why| Message::Error(why.to_string()), - Message::NetworkManagerConnect, - ); - } - - tracing::error!("{err:?}"); - } - break; + if let Ok(nm_settings) = NetworkManagerSettings::new(&conn).await + && let Ok(connections) = nm_settings.list_connections().await + { + for connection in connections { + if let Ok(settings) = connection.get_settings().await { + let settings = Settings::new(settings); + if let Some(conn_settings) = &settings.connection + && conn_settings + .uuid + .as_ref() + .is_some_and(|conn_uuid| conn_uuid.as_str() == uuid.as_ref()) + { + let path = connection.inner().path().clone().to_owned(); + if let Err(err) = + tx.unbounded_send(network_manager::Request::Activate( + ObjectPath::try_from("/").unwrap(), + path, + )) + { + if err.is_disconnected() { + return zbus::Connection::system() + .await + .context("failed to create system dbus connection") + .map_or_else( + |why| Message::Error(why.to_string()), + Message::NetworkManagerConnect, + ); } + + tracing::error!("{err:?}"); } + break; } } } @@ -759,7 +755,7 @@ impl cosmic::Application for CosmicNetworkApplet { const APP_ID: &'static str = config::APP_ID; fn init(core: cosmic::app::Core, _flags: ()) -> (Self, app::Task) { - let mut applet = Self { + let applet = Self { core, icon_name: "network-wired-disconnected-symbolic".to_string(), token_tx: None, @@ -823,16 +819,15 @@ impl cosmic::Application for CosmicNetworkApplet { } Message::ToggleAirplaneMode(enabled) => { self.toggle_wifi_ctr += 1; - if let Some(tx) = self.nm_sender.as_mut() { - if let Err(err) = + if let Some(tx) = self.nm_sender.as_mut() + && let Err(err) = tx.unbounded_send(network_manager::Request::SetAirplaneMode(enabled)) - { - if err.is_disconnected() { - return system_conn().map(cosmic::Action::App); - } - - tracing::error!("{err:?}"); + { + if err.is_disconnected() { + return system_conn().map(cosmic::Action::App); } + + tracing::error!("{err:?}"); } } Message::SelectWirelessAccessPoint(access_point) => { @@ -862,21 +857,19 @@ impl cosmic::Application for CosmicNetworkApplet { .nm_state .known_access_points .contains(&access_point) - { - if let Err(err) = + && let Err(err) = tx.unbounded_send(network_manager::Request::SelectAccessPoint( access_point.ssid.clone(), access_point.network_type, self.secret_tx.clone(), self.active_device.as_ref().map(|d| d.interface.clone()), )) - { - if err.is_disconnected() { - return system_conn().map(cosmic::Action::App); - } - - tracing::error!("{err:?}"); + { + if err.is_disconnected() { + return system_conn().map(cosmic::Action::App); } + + tracing::error!("{err:?}"); } self.new_connection = Some(NewConnectionState::EnterPassword { access_point, @@ -1004,15 +997,14 @@ impl cosmic::Application for CosmicNetworkApplet { return self.connect_vpn(uuid.clone()); } Message::DeactivateVpn(name) => { - if let Some(tx) = self.nm_sender.as_ref() { - if let Err(err) = tx.unbounded_send(network_manager::Request::Deactivate(name)) - { - if err.is_disconnected() { - return system_conn().map(cosmic::Action::App); - } - - tracing::error!("{err:?}"); + if let Some(tx) = self.nm_sender.as_ref() + && let Err(err) = tx.unbounded_send(network_manager::Request::Deactivate(name)) + { + if err.is_disconnected() { + return system_conn().map(cosmic::Action::App); } + + tracing::error!("{err:?}"); } } Message::ToggleVpnList => { @@ -1153,9 +1145,9 @@ impl cosmic::Application for CosmicNetworkApplet { } => { if let network_manager::Request::SelectAccessPoint( ssid, - hw_address, + _hw_address, _network_type, - secret_tx, + _secret_tx, ) = &req { let conn_match = self @@ -1168,10 +1160,10 @@ impl cosmic::Application for CosmicNetworkApplet { .active_conns .iter_mut() .find(|ap| { - let ap_hw_address = match ap { + let _ap_hw_address = match ap { ActiveConnectionInfo::Wired { hw_address, .. } | ActiveConnectionInfo::WiFi { hw_address, .. } => { - HwAddress::from_str(&hw_address).unwrap() + HwAddress::from_str(hw_address).unwrap() } ActiveConnectionInfo::Vpn { .. } => HwAddress::default(), }; @@ -1192,8 +1184,8 @@ impl cosmic::Application for CosmicNetworkApplet { ssid, identity: _, password: _, - secret_tx, - interface + secret_tx: _, + interface: _ } = &req { if let Some(NewConnectionState::Waiting(access_point)) = @@ -1210,12 +1202,10 @@ impl cosmic::Application for CosmicNetworkApplet { } else if let Some(NewConnectionState::EnterPassword { access_point, .. }) = self.new_connection.as_ref() - { - if success && ssid.as_str() == access_point.ssid.as_ref() { + && success && ssid.as_str() == access_point.ssid.as_ref() { self.new_connection = None; self.show_visible_networks = false; } - } } else if self .new_connection .as_ref() @@ -1246,9 +1236,9 @@ impl cosmic::Application for CosmicNetworkApplet { } } cosmic_settings_network_manager_subscription::Event::WiFiCredentials { - ssid, - password, - security_type, + ssid: _, + password: _, + security_type: _, } => {} }, Message::NetworkManagerConnect(connection) => { @@ -1441,7 +1431,7 @@ impl cosmic::Application for CosmicNetworkApplet { } ActiveConnectionInfo::Wired { name, - hw_address, + hw_address: _, speed, ip_addresses, } => { @@ -1561,7 +1551,7 @@ impl cosmic::Application for CosmicNetworkApplet { .icon_size(16) .on_press(Message::ResetFailedKnownSsid( name.clone(), - HwAddress::from_str(&hw_address).unwrap(), + HwAddress::from_str(hw_address).unwrap(), )) .into(), ); @@ -1576,7 +1566,7 @@ impl cosmic::Application for CosmicNetworkApplet { ) .on_press(Message::Disconnect( Arc::from(name.as_str()), - HwAddress::from_str(&hw_address).unwrap(), + HwAddress::from_str(hw_address).unwrap(), )), )]) .align_x(Alignment::Center), @@ -1733,14 +1723,13 @@ impl cosmic::Application for CosmicNetworkApplet { } for known in &self.nm_state.nm_state.known_access_points { - if let Some(active_device) = self.active_device.as_ref() { - if active_device + if let Some(active_device) = self.active_device.as_ref() + && active_device .known_connections .iter() - .all(|c| &c.id != known.ssid.as_ref()) - { - continue; - } + .all(|c| c.id != known.ssid.as_ref()) + { + continue; } let mut btn_content = Vec::with_capacity(2); let ssid = text::body(known.ssid.as_ref()).width(Length::Fill); @@ -1872,43 +1861,43 @@ impl cosmic::Application for CosmicNetworkApplet { content = content.push(id); let is_enterprise = matches!(access_point.network_type, NetworkType::EAP); - let enter_password_col = - cosmic::widget::column::with_capacity(4) - .push_maybe(is_enterprise.then(|| text::body(fl!("identity")))) - .push_maybe(is_enterprise.then(|| { - text_input::text_input("", identity) - .on_input(|i| Message::IdentityUpdate(i)) - })) - .push(text::body(fl!("enter-password"))) - .push_maybe(description.as_ref().map(|d| text::body(d.clone()))) - .push( - text_input::secure_input( - "", - password.unsecure(), - Some(Message::TogglePasswordVisibility), - *password_hidden, - ) - .id(SECURE_INPUT_WIFI.clone()) - .on_input(|s| Message::PasswordUpdate(SecureString::from(s))) - .on_paste(|s| Message::PasswordUpdate(SecureString::from(s))) - .on_submit(|_| Message::ConnectWithPassword), + let enter_password_col = cosmic::widget::column::with_capacity(4) + .push_maybe(is_enterprise.then(|| text::body(fl!("identity")))) + .push_maybe(is_enterprise.then(|| { + text_input::text_input("", identity).on_input(Message::IdentityUpdate) + })) + .push(text::body(fl!("enter-password"))) + .push_maybe(description.as_ref().map(|d| text::body(d.clone()))) + .push( + text_input::secure_input( + "", + password.unsecure(), + Some(Message::TogglePasswordVisibility), + *password_hidden, ) - .push_maybe(access_point.wps_push.then(|| { + .id(SECURE_INPUT_WIFI.clone()) + .on_input(|s| Message::PasswordUpdate(SecureString::from(s))) + .on_paste(|s| Message::PasswordUpdate(SecureString::from(s))) + .on_submit(|_| Message::ConnectWithPassword), + ) + .push_maybe( + access_point.wps_push.then(|| { container(text::body(fl!("router-wps-button"))).padding(8) - })) - .push( - row::with_children([ - Element::from( - button::standard(fl!("cancel")) - .on_press(Message::CancelNewConnection), - ), - Element::from( - button::suggested(fl!("connect")) - .on_press(Message::ConnectWithPassword), - ), - ]) - .spacing(24), - ); + }), + ) + .push( + row::with_children([ + Element::from( + button::standard(fl!("cancel")) + .on_press(Message::CancelNewConnection), + ), + Element::from( + button::suggested(fl!("connect")) + .on_press(Message::ConnectWithPassword), + ), + ]) + .spacing(24), + ); let col = padded_control(enter_password_col.spacing(8).align_x(Alignment::Center)) .align_x(Alignment::Center); @@ -1987,7 +1976,7 @@ impl cosmic::Application for CosmicNetworkApplet { .filter(|ap| { let among_active = self.nm_state.nm_state.active_conns.iter().any(|a| { let hw_address = active_conn_hw_address(a); - ap.ssid.as_ref() == &a.name() && ap.hw_address == hw_address + ap.ssid.as_ref() == a.name() && ap.hw_address == hw_address }); let among_known = self.nm_state diff --git a/cosmic-applet-notifications/src/lib.rs b/cosmic-applet-notifications/src/lib.rs index 438696b98..ae0adb68d 100644 --- a/cosmic-applet-notifications/src/lib.rs +++ b/cosmic-applet-notifications/src/lib.rs @@ -20,14 +20,14 @@ use cosmic::{ window, }, surface, theme, - widget::{Column, button, cards, container, divider, icon, scrollable, space, text, toggler}, + widget::{Column, button, cards, container, divider, icon, scrollable, text, toggler}, }; use cosmic::iced::futures::executor::block_on; use cosmic_notifications_config::NotificationsConfig; use cosmic_notifications_util::{ActionId, Image, Notification, markup}; -use std::{borrow::Cow, collections::HashMap, path::PathBuf, sync::LazyLock}; +use std::{borrow::Cow, collections::HashMap}; use subscriptions::notifications::{self, NotificationsAppletProxy}; use tokio::sync::mpsc::Sender; use tracing::info; @@ -173,10 +173,10 @@ impl cosmic::Application for Notifications { } Message::DoNotDisturb(b) => { self.config.do_not_disturb = b; - if let Some(helper) = &self.config_helper { - if let Err(err) = self.config.write_entry(helper) { - tracing::error!("{:?}", err); - } + if let Some(helper) = &self.config_helper + && let Err(err) = self.config.write_entry(helper) + { + tracing::error!("{:?}", err); } } Message::NotificationEvent(event) => match event { @@ -279,7 +279,7 @@ impl cosmic::Application for Notifications { } } Message::CardsToggled(name, expanded) => { - let id = if let Some((id, _, n_expanded, ..)) = self + let _id = if let Some((id, _, n_expanded, ..)) = self .cards .iter_mut() .find(|c| c.1.iter().any(|notif| name == notif.app_name)) diff --git a/cosmic-applet-power/src/lib.rs b/cosmic-applet-power/src/lib.rs index 67725fbc4..575dc4707 100644 --- a/cosmic-applet-power/src/lib.rs +++ b/cosmic-applet-power/src/lib.rs @@ -16,7 +16,7 @@ use cosmic::{ window, }, surface, theme, - widget::{Space, button, divider, icon, space, text}, + widget::{button, divider, icon, space, text}, }; use std::sync::LazyLock; diff --git a/cosmic-applet-status-area/src/components/app.rs b/cosmic-applet-status-area/src/components/app.rs index 1071d7ac2..72e7bd2e6 100644 --- a/cosmic-applet-status-area/src/components/app.rs +++ b/cosmic-applet-status-area/src/components/app.rs @@ -11,7 +11,6 @@ use cosmic::{ iced::{ self, Length, Subscription, platform_specific::shell::commands::popup::{destroy_popup, get_popup}, - theme::Style, window, }, surface, @@ -103,7 +102,7 @@ impl App { let overflow_index = self.overflow_index().unwrap_or(0); let children = self.menus.iter().skip(overflow_index).map(|(id, menu)| { mouse_area( - menu_icon_button(&self.core.applet, &menu).on_press_down(Msg::TogglePopup(*id)), + menu_icon_button(&self.core.applet, menu).on_press_down(Msg::TogglePopup(*id)), ) .on_enter(Msg::Hovered(*id)) .into() @@ -162,10 +161,8 @@ impl cosmic::Application for App { app_id: Self::APP_ID.to_string(), exec: format!("activate:{}", id), }); - } else { - if let Some(menu) = self.menus.get(&id) { - return activate(id, &menu.item, None); - } + } else if let Some(menu) = self.menus.get(&id) { + return activate(id, &menu.item, None); } Task::none() } @@ -280,18 +277,18 @@ impl cosmic::Application for App { Msg::Token(u) => match u { TokenUpdate::Init(tx) => { self.token_tx = Some(tx); - return Task::none(); + Task::none() } TokenUpdate::Finished => { self.token_tx = None; - return Task::none(); + Task::none() } TokenUpdate::ActivationToken { token, exec: id } => { if let Some(id_str) = id.strip_prefix("activate:") { - if let Ok(real_id) = id_str.parse::() { - if let Some(menu) = self.menus.get(&real_id) { - return activate(real_id, &menu.item, token.clone()); - } + if let Ok(real_id) = id_str.parse::() + && let Some(menu) = self.menus.get(&real_id) + { + return activate(real_id, &menu.item, token.clone()); } return Task::none(); } @@ -308,7 +305,7 @@ impl cosmic::Application for App { ) .map(move |msg| cosmic::action::app(Msg::StatusMenu((id, msg)))); } - return Task::none(); + Task::none() } }, Msg::Hovered(id) => { @@ -362,15 +359,13 @@ impl cosmic::Application for App { Task::batch(cmds) } Msg::Surface(a) => { - return cosmic::task::message(cosmic::Action::Cosmic( - cosmic::app::Action::Surface(a), - )); + cosmic::task::message(cosmic::Action::Cosmic(cosmic::app::Action::Surface(a))) } Msg::ToggleOverflow => { if let Some(popup_id) = self.overflow_popup.take() { self.popup = None; self.open_menu = None; - return destroy_popup(popup_id); + destroy_popup(popup_id) } else if let Some(overflow_index) = self.overflow_index() { // If we don't have an overflow, create it let popup_id = self.next_popup_id(); @@ -399,9 +394,9 @@ impl cosmic::Application for App { } self.overflow_popup = Some(popup_id); - return get_popup(popup_settings); + get_popup(popup_settings) } else { - return Task::none(); + Task::none() } } Msg::HoveredOverflow => { @@ -472,7 +467,7 @@ impl cosmic::Application for App { .iter() .take(overflow_index.unwrap_or(self.menus.len())) .map(|(id, menu)| { - mouse_area(menu_icon_button(&self.core.applet, &menu).on_press(Msg::Activate(*id))) + mouse_area(menu_icon_button(&self.core.applet, menu).on_press(Msg::Activate(*id))) .on_right_press(Msg::TogglePopup(*id)) .on_enter(Msg::Hovered(*id)) .into() @@ -577,7 +572,7 @@ fn menu_icon_button<'a>( let icon = menu.icon_handle().clone(); let theme = cosmic::theme::active(); - let theme = theme.cosmic(); + let _theme = theme.cosmic(); let suggested = applet.suggested_size(true); let padding = applet.suggested_padding(true).1; diff --git a/cosmic-applet-status-area/src/components/status_menu.rs b/cosmic-applet-status-area/src/components/status_menu.rs index fedd79e40..0ab1f317c 100644 --- a/cosmic-applet-status-area/src/components/status_menu.rs +++ b/cosmic-applet-status-area/src/components/status_menu.rs @@ -8,7 +8,7 @@ use cosmic::{ iced, widget::icon::{self, IconFallback}, }; -use std::path::{Path, PathBuf}; +use std::path::Path; use crate::subscriptions::status_notifier_item::{IconUpdate, Layout, StatusNotifierItem}; diff --git a/cosmic-applet-status-area/src/status_notifier_watcher.rs b/cosmic-applet-status-area/src/status_notifier_watcher.rs index 1bb75d79c..5be06bbef 100644 --- a/cosmic-applet-status-area/src/status_notifier_watcher.rs +++ b/cosmic-applet-status-area/src/status_notifier_watcher.rs @@ -67,10 +67,10 @@ struct CosmicAppletStatusNotifierWatcher { #[zbus::interface(name = "com.system76.CosmicStatusNotifierWatcher")] impl CosmicAppletStatusNotifierWatcher { fn register_applet(&mut self, #[zbus(header)] hdr: Header<'_>) { - if let Some(sender) = hdr.sender() { - if self.unique_names.has_unique_name(sender) { - self.applets.insert(sender.to_owned()); - } + if let Some(sender) = hdr.sender() + && self.unique_names.has_unique_name(sender) + { + self.applets.insert(sender.to_owned()); } } } diff --git a/cosmic-applet-status-area/src/subscriptions/status_notifier_watcher/server.rs b/cosmic-applet-status-area/src/subscriptions/status_notifier_watcher/server.rs index 816a0be71..81bbdb3c3 100644 --- a/cosmic-applet-status-area/src/subscriptions/status_notifier_watcher/server.rs +++ b/cosmic-applet-status-area/src/subscriptions/status_notifier_watcher/server.rs @@ -118,20 +118,20 @@ pub async fn create_service(connection: &zbus::Connection) -> zbus::Result<()> { eprintln!("Lost bus name: {NAME}"); have_bus_name = false; } - } else if let BusName::Unique(name) = &args.name { - if args.new_owner.is_none() { - let mut interface = interface.get_mut().await; - if let Some(idx) = interface - .items - .iter() - .position(|(unique_name, _)| unique_name == name) - { - let ctxt = SignalEmitter::new(&connection, OBJECT_PATH).unwrap(); - let service = interface.items.remove(idx).1; - StatusNotifierWatcher::status_notifier_item_unregistered(&ctxt, &service) - .await - .unwrap(); - } + } else if let BusName::Unique(name) = &args.name + && args.new_owner.is_none() + { + let mut interface = interface.get_mut().await; + if let Some(idx) = interface + .items + .iter() + .position(|(unique_name, _)| unique_name == name) + { + let ctxt = SignalEmitter::new(&connection, OBJECT_PATH).unwrap(); + let service = interface.items.remove(idx).1; + StatusNotifierWatcher::status_notifier_item_unregistered(&ctxt, &service) + .await + .unwrap(); } } } diff --git a/cosmic-applet-tiling/src/wayland.rs b/cosmic-applet-tiling/src/wayland.rs index 5d028276a..14727b1fa 100644 --- a/cosmic-applet-tiling/src/wayland.rs +++ b/cosmic-applet-tiling/src/wayland.rs @@ -89,25 +89,24 @@ pub fn spawn_workspaces(tx: mpsc::Sender) -> SyncSender .insert_source(workspaces_rx, |e, (), state| match e { Event::Msg(AppRequest::TilingState(autotile)) => { if let Some(w) = state.workspace_state.workspace_groups().find_map(|g| { - if let Some(o) = state.expected_output.as_ref() { - if !g.outputs.contains(o) { - return None; - } + if let Some(o) = state.expected_output.as_ref() + && !g.outputs.contains(o) + { + return None; } g.workspaces .iter() .filter_map(|handle| state.workspace_state.workspace_info(handle)) .find(|w| w.state.contains(ext_workspace_handle_v1::State::Active)) - }) { - if let Some(cosmic_handle) = &w.cosmic_handle { - cosmic_handle.set_tiling_state(autotile); - state - .workspace_state - .workspace_manager() - .get() - .unwrap() - .commit(); - } + }) && let Some(cosmic_handle) = &w.cosmic_handle + { + cosmic_handle.set_tiling_state(autotile); + state + .workspace_state + .workspace_manager() + .get() + .unwrap() + .commit(); } } Event::Msg(AppRequest::DefaultBehavior(tiling)) => { @@ -221,10 +220,10 @@ impl OutputHandler for State { let info = self.output_state.info(&output).unwrap(); if info.name.as_deref() == Some(&self.configured_output) { self.expected_output = Some(output); - if self.have_workspaces { - if let Some(s) = self.tiling_state() { - let _ = block_on(self.tx.send(s)); - } + if self.have_workspaces + && let Some(s) = self.tiling_state() + { + let _ = block_on(self.tx.send(s)); } } } diff --git a/cosmic-applet-tiling/src/window.rs b/cosmic-applet-tiling/src/window.rs index 327d5d759..30ed860da 100644 --- a/cosmic-applet-tiling/src/window.rs +++ b/cosmic-applet-tiling/src/window.rs @@ -26,7 +26,7 @@ use cosmic::{ }; use cosmic_comp_config::{CosmicCompConfig, TileBehavior}; use cosmic_protocols::workspace::v2::client::zcosmic_workspace_handle_v2::TilingState; -use std::{thread, time::Instant}; +use std::thread; use tracing::error; const ID: &str = "com.system76.CosmicAppletTiling"; diff --git a/cosmic-applet-time/src/window.rs b/cosmic-applet-time/src/window.rs index a44d81ee7..f62aa05d3 100644 --- a/cosmic-applet-time/src/window.rs +++ b/cosmic-applet-time/src/window.rs @@ -67,10 +67,10 @@ fn get_system_locale() -> Locale { } // Try language-only fallback (e.g., "en" from "en-US") - if let Some(lang) = cleaned_locale.split('-').next() { - if let Ok(locale) = Locale::try_from_str(lang) { - return locale; - } + if let Some(lang) = cleaned_locale.split('-').next() + && let Ok(locale) = Locale::try_from_str(lang) + { + return locale; } } } @@ -361,7 +361,7 @@ impl cosmic::Application for Window { } fn subscription(&self) -> Subscription { - fn time_subscription(mut show_seconds: watch::Receiver) -> Subscription { + fn time_subscription(show_seconds: watch::Receiver) -> Subscription { struct Wrapper { inner: watch::Receiver, id: &'static str, @@ -376,7 +376,7 @@ impl cosmic::Application for Window { inner: show_seconds, id: "time-sub", }, - |Wrapper { inner, id }| { + |Wrapper { inner, id: _ }| { let mut show_seconds = inner.clone(); stream::channel(1, move |mut output: mpsc::Sender| async move { // Mark this receiver's state as changed so that it always receives an initial @@ -552,10 +552,10 @@ impl cosmic::Application for Window { } } Message::Tick => { - self.now = self.timezone.as_ref().map_or_else( - || Zoned::now(), - |tz| Zoned::now().with_time_zone(tz.clone()), - ); + self.now = self + .timezone + .as_ref() + .map_or_else(Zoned::now, |tz| Zoned::now().with_time_zone(tz.clone())); Task::none() } Message::Rectangle(u) => { @@ -668,9 +668,7 @@ impl cosmic::Application for Window { self.update(Message::Tick) } Message::Surface(a) => { - return cosmic::task::message(cosmic::Action::Cosmic( - cosmic::app::Action::Surface(a), - )); + cosmic::task::message(cosmic::Action::Cosmic(cosmic::app::Action::Surface(a))) } } } diff --git a/cosmic-panel-button/src/lib.rs b/cosmic-panel-button/src/lib.rs index 718744b09..03a460cf1 100644 --- a/cosmic-panel-button/src/lib.rs +++ b/cosmic-panel-button/src/lib.rs @@ -48,7 +48,7 @@ impl Button { icon: cosmic::widget::icon::Handle, ) -> cosmic::widget::Button<'a, Message> { let theme = cosmic::theme::active(); - let theme = theme.cosmic(); + let _theme = theme.cosmic(); let suggested = self.core.applet.suggested_size(icon.symbolic); let (major_padding, applet_padding_minor_axis) = @@ -218,21 +218,21 @@ pub fn run() -> iced::Result { for mut path in fde::default_paths() { path.push(&filename); - if let Ok(bytes) = fs::read_to_string(&path) { - if let Ok(entry) = DesktopEntry::from_str(&path, &bytes, Some(&locales)) { - desktop = Some(Desktop { - name: entry.name(&locales).map_or_else( - || panic!("Desktop file '{filename}' doesn't have `Name`"), - |x| x.to_string(), - ), - icon: entry.icon().map(|x| x.to_string()), - exec: entry.exec().map_or_else( - || panic!("Desktop file '{filename}' doesn't have `Exec`"), - |x| x.to_string(), - ), - }); - break; - } + if let Ok(bytes) = fs::read_to_string(&path) + && let Ok(entry) = DesktopEntry::from_str(&path, &bytes, Some(&locales)) + { + desktop = Some(Desktop { + name: entry.name(&locales).map_or_else( + || panic!("Desktop file '{filename}' doesn't have `Name`"), + |x| x.to_string(), + ), + icon: entry.icon().map(|x| x.to_string()), + exec: entry.exec().map_or_else( + || panic!("Desktop file '{filename}' doesn't have `Exec`"), + |x| x.to_string(), + ), + }); + break; } } let desktop = desktop.unwrap_or_else(|| {