1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-17 14:51:04 +02:00

refactor: fix some strict clippy warnings

This commit is contained in:
Jake Stanger 2024-12-29 00:40:12 +00:00
parent 87a6523367
commit 5136637752
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
6 changed files with 51 additions and 60 deletions

View file

@ -82,13 +82,12 @@ impl Clients {
#[cfg(feature = "workspaces")] #[cfg(feature = "workspaces")]
pub fn workspaces(&mut self) -> ClientResult<dyn compositor::WorkspaceClient> { pub fn workspaces(&mut self) -> ClientResult<dyn compositor::WorkspaceClient> {
let client = match &self.workspaces { let client = if let Some(workspaces) = &self.workspaces {
Some(workspaces) => workspaces.clone(), workspaces.clone()
None => { } else {
let client = compositor::Compositor::create_workspace_client(self)?; let client = compositor::Compositor::create_workspace_client(self)?;
self.workspaces.replace(client.clone()); self.workspaces.replace(client.clone());
client client
}
}; };
Ok(client) Ok(client)
@ -96,14 +95,13 @@ impl Clients {
#[cfg(feature = "sway")] #[cfg(feature = "sway")]
pub fn sway(&mut self) -> ClientResult<sway::Client> { pub fn sway(&mut self) -> ClientResult<sway::Client> {
let client = match &self.sway { let client = if let Some(client) = &self.sway {
Some(client) => client.clone(), client.clone()
None => { } else {
let client = await_sync(async { sway::Client::new().await })?; let client = await_sync(async { sway::Client::new().await })?;
let client = Arc::new(client); let client = Arc::new(client);
self.sway.replace(client.clone()); self.sway.replace(client.clone());
client client
}
}; };
Ok(client) Ok(client)
@ -134,26 +132,24 @@ impl Clients {
#[cfg(feature = "network_manager")] #[cfg(feature = "network_manager")]
pub fn network_manager(&mut self) -> ClientResult<networkmanager::Client> { pub fn network_manager(&mut self) -> ClientResult<networkmanager::Client> {
match &self.network_manager { if let Some(client) = &self.network_manager {
Some(client) => Ok(client.clone()), Ok(client.clone())
None => { } else {
let client = networkmanager::create_client()?; let client = networkmanager::create_client()?;
self.network_manager = Some(client.clone()); self.network_manager = Some(client.clone());
Ok(client) Ok(client)
} }
} }
}
#[cfg(feature = "notifications")] #[cfg(feature = "notifications")]
pub fn notifications(&mut self) -> ClientResult<swaync::Client> { pub fn notifications(&mut self) -> ClientResult<swaync::Client> {
let client = match &self.notifications { let client = if let Some(client) = &self.notifications {
Some(client) => client.clone(), client.clone()
None => { } else {
let client = await_sync(async { swaync::Client::new().await })?; let client = await_sync(async { swaync::Client::new().await })?;
let client = Arc::new(client); let client = Arc::new(client);
self.notifications.replace(client.clone()); self.notifications.replace(client.clone());
client client
}
}; };
Ok(client) Ok(client)
@ -161,14 +157,13 @@ impl Clients {
#[cfg(feature = "tray")] #[cfg(feature = "tray")]
pub fn tray(&mut self) -> ClientResult<tray::Client> { pub fn tray(&mut self) -> ClientResult<tray::Client> {
let client = match &self.tray { let client = if let Some(client) = &self.tray {
Some(client) => client.clone(), client.clone()
None => { } else {
let client = await_sync(async { tray::Client::new().await })?; let client = await_sync(async { tray::Client::new().await })?;
let client = Arc::new(client); let client = Arc::new(client);
self.tray.replace(client.clone()); self.tray.replace(client.clone());
client client
}
}; };
Ok(client) Ok(client)
@ -176,13 +171,12 @@ impl Clients {
#[cfg(feature = "upower")] #[cfg(feature = "upower")]
pub fn upower(&mut self) -> ClientResult<zbus::fdo::PropertiesProxy<'static>> { pub fn upower(&mut self) -> ClientResult<zbus::fdo::PropertiesProxy<'static>> {
let client = match &self.upower { let client = if let Some(client) = &self.upower {
Some(client) => client.clone(), client.clone()
None => { } else {
let client = await_sync(async { upower::create_display_proxy().await })?; let client = await_sync(async { upower::create_display_proxy().await })?;
self.upower.replace(client.clone()); self.upower.replace(client.clone());
client client
}
}; };
Ok(client) Ok(client)

View file

@ -97,10 +97,10 @@ pub trait IronbarLabelExt {
impl IronbarLabelExt for Label { impl IronbarLabelExt for Label {
fn set_label_escaped(&self, label: &str) { fn set_label_escaped(&self, label: &str) {
if !label.contains("<span") { if label.contains("<span") {
self.set_label(&markup_escape_text(label));
} else {
self.set_label(label); self.set_label(label);
} else {
self.set_label(&markup_escape_text(label));
} }
} }

View file

@ -1,7 +1,6 @@
use color_eyre::Result; use color_eyre::Result;
use gtk::prelude::*; use gtk::prelude::*;
use serde::Deserialize; use serde::Deserialize;
use std::ops::Deref;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use super::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use super::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
@ -183,19 +182,19 @@ impl Module<gtk::Box> for KeysModule {
if self.show_caps { if self.show_caps {
caps.add_class("key"); caps.add_class("key");
caps.add_class("caps"); caps.add_class("caps");
container.add(caps.deref()); container.add(&*caps);
} }
if self.show_num { if self.show_num {
num.add_class("key"); num.add_class("key");
num.add_class("num"); num.add_class("num");
container.add(num.deref()); container.add(&*num);
} }
if self.show_scroll { if self.show_scroll {
scroll.add_class("key"); scroll.add_class("key");
scroll.add_class("scroll"); scroll.add_class("scroll");
container.add(scroll.deref()); container.add(&*scroll);
} }
let icons = self.icons; let icons = self.icons;

View file

@ -1,5 +1,4 @@
use std::cell::RefMut; use std::cell::RefMut;
use std::ops::Deref;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; use std::sync::Arc;
@ -200,8 +199,8 @@ impl Module<Button> for MusicModule {
label.truncate(truncate); label.truncate(truncate);
} }
button_contents.add(icon_pause.deref()); button_contents.add(&*icon_pause);
button_contents.add(icon_play.deref()); button_contents.add(&*icon_play);
button_contents.add(&label); button_contents.add(&label);
{ {
@ -328,7 +327,7 @@ impl Module<Button> for MusicModule {
volume_icon.add_class("icon"); volume_icon.add_class("icon");
volume_box.pack_start(&volume_slider, true, true, 0); volume_box.pack_start(&volume_slider, true, true, 0);
volume_box.pack_end(volume_icon.deref(), false, false, 0); volume_box.pack_end(&*volume_icon, false, false, 0);
main_container.add(&album_image); main_container.add(&album_image);
main_container.add(&info_box); main_container.add(&info_box);
@ -559,7 +558,7 @@ impl IconPrefixedLabel {
icon.add_class("icon-box"); icon.add_class("icon-box");
label.add_class("label"); label.add_class("label");
container.add(icon.deref()); container.add(&*icon);
container.add(&label); container.add(&label);
Self { label, container } Self { label, container }

View file

@ -109,8 +109,7 @@ impl Module<gtk::Box> for TrayModule {
) -> Result<ModuleParts<gtk::Box>> { ) -> Result<ModuleParts<gtk::Box>> {
let orientation = self let orientation = self
.direction .direction
.map(Orientation::from) .map_or(info.bar_position.orientation(), Orientation::from);
.unwrap_or(info.bar_position.orientation());
// We use a `Box` here instead of the (supposedly correct) `MenuBar` // We use a `Box` here instead of the (supposedly correct) `MenuBar`
// as the latter has issues on Sway with menus focus-stealing from the bar. // as the latter has issues on Sway with menus focus-stealing from the bar.

View file

@ -155,7 +155,7 @@ fn reorder_workspaces(container: &gtk::Box, sort_order: SortOrder) {
let label = if sort_order == SortOrder::Label { let label = if sort_order == SortOrder::Label {
child child
.downcast_ref::<gtk::Button>() .downcast_ref::<gtk::Button>()
.and_then(|button| button.label()) .and_then(ButtonExt::label)
.unwrap_or_else(|| child.widget_name()) .unwrap_or_else(|| child.widget_name())
} else { } else {
child.widget_name() child.widget_name()