mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-16 14:21:03 +02:00
Merge pull request #708 from JakeStanger/refactor/clippy
refactor: fix some pedantic clippy warnings
This commit is contained in:
commit
7c07bbef57
12 changed files with 43 additions and 46 deletions
|
@ -346,7 +346,7 @@ impl Bar {
|
|||
|
||||
/// Sets the window visibility status
|
||||
pub fn set_visible(&self, visible: bool) {
|
||||
self.window.set_visible(visible)
|
||||
self.window.set_visible(visible);
|
||||
}
|
||||
|
||||
pub fn set_exclusive(&self, exclusive: bool) {
|
||||
|
|
|
@ -54,6 +54,7 @@ impl Client {
|
|||
vec![]
|
||||
}
|
||||
});
|
||||
|
||||
// Acquire the lock of current_player before players to avoid deadlock.
|
||||
// There are places where we lock on current_player and players, but we always lock on current_player first.
|
||||
// This is because we almost never need to lock on players without locking on current_player.
|
||||
|
|
|
@ -56,7 +56,7 @@ impl Client {
|
|||
T::EVENT_TYPE,
|
||||
Box::new(move |event| {
|
||||
let event = T::from_event(event).expect("event type mismatch");
|
||||
f(event)
|
||||
f(event);
|
||||
}),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -146,7 +146,7 @@ where
|
|||
ToplevelHandle {
|
||||
handle: handle.clone(),
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
Event::Done if !lock!(data.inner).closed => {
|
||||
{
|
||||
|
|
|
@ -37,20 +37,18 @@ impl<'de> Deserialize<'de> for MonitorConfig {
|
|||
|
||||
pub fn deserialize_layer<'de, D>(deserializer: D) -> Result<gtk_layer_shell::Layer, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
use gtk_layer_shell::Layer;
|
||||
|
||||
let value = Option::<String>::deserialize(deserializer)?;
|
||||
value
|
||||
.map(|v| match v.as_str() {
|
||||
"background" => Ok(Layer::Background),
|
||||
"bottom" => Ok(Layer::Bottom),
|
||||
"top" => Ok(Layer::Top),
|
||||
"overlay" => Ok(Layer::Overlay),
|
||||
_ => Err(serde::de::Error::custom("invalid value for orientation")),
|
||||
})
|
||||
.unwrap_or(Ok(Layer::Top))
|
||||
value.map_or(Ok(Layer::Top), |v| match v.as_str() {
|
||||
"background" => Ok(Layer::Background),
|
||||
"bottom" => Ok(Layer::Bottom),
|
||||
"top" => Ok(Layer::Top),
|
||||
"overlay" => Ok(Layer::Overlay),
|
||||
_ => Err(serde::de::Error::custom("invalid value for orientation")),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "schema")]
|
||||
|
|
|
@ -6,12 +6,13 @@ use crate::Ironbar;
|
|||
use std::rc::Rc;
|
||||
|
||||
pub fn handle_command(command: BarCommand, ironbar: &Rc<Ironbar>) -> Response {
|
||||
use BarCommandType::*;
|
||||
|
||||
let bar = ironbar.bar_by_name(&command.name);
|
||||
let Some(bar) = bar else {
|
||||
return Response::error("Invalid bar name");
|
||||
};
|
||||
|
||||
use BarCommandType::*;
|
||||
match command.subcommand {
|
||||
Show => set_visible(&bar, true),
|
||||
Hide => set_visible(&bar, false),
|
||||
|
@ -21,14 +22,14 @@ pub fn handle_command(command: BarCommand, ironbar: &Rc<Ironbar>) -> Response {
|
|||
value: bar.visible().to_string(),
|
||||
},
|
||||
|
||||
ShowPopup { widget_name } => show_popup(&bar, widget_name),
|
||||
ShowPopup { widget_name } => show_popup(&bar, &widget_name),
|
||||
HidePopup => hide_popup(&bar),
|
||||
SetPopupVisible {
|
||||
widget_name,
|
||||
visible,
|
||||
} => {
|
||||
if visible {
|
||||
show_popup(&bar, widget_name)
|
||||
show_popup(&bar, &widget_name)
|
||||
} else {
|
||||
hide_popup(&bar)
|
||||
}
|
||||
|
@ -37,7 +38,7 @@ pub fn handle_command(command: BarCommand, ironbar: &Rc<Ironbar>) -> Response {
|
|||
if bar.popup().visible() {
|
||||
hide_popup(&bar)
|
||||
} else {
|
||||
show_popup(&bar, widget_name)
|
||||
show_popup(&bar, &widget_name)
|
||||
}
|
||||
}
|
||||
GetPopupVisible => Response::OkValue {
|
||||
|
@ -56,7 +57,7 @@ fn set_visible(bar: &Bar, visible: bool) -> Response {
|
|||
Response::Ok
|
||||
}
|
||||
|
||||
fn show_popup(bar: &Bar, widget_name: String) -> Response {
|
||||
fn show_popup(bar: &Bar, widget_name: &str) -> Response {
|
||||
let popup = bar.popup();
|
||||
|
||||
// only one popup per bar, so hide if open for another widget
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -88,7 +88,7 @@ fn run_with_args() {
|
|||
match args.command {
|
||||
Some(command) => {
|
||||
if args.debug {
|
||||
eprintln!("REQUEST: {command:?}")
|
||||
eprintln!("REQUEST: {command:?}");
|
||||
}
|
||||
|
||||
let rt = create_runtime();
|
||||
|
@ -97,10 +97,10 @@ fn run_with_args() {
|
|||
match ipc.send(command, args.debug).await {
|
||||
Ok(res) => {
|
||||
if args.debug {
|
||||
eprintln!("RESPONSE: {res:?}")
|
||||
eprintln!("RESPONSE: {res:?}");
|
||||
}
|
||||
|
||||
cli::handle_response(res, args.format.unwrap_or_default())
|
||||
cli::handle_response(res, args.format.unwrap_or_default());
|
||||
}
|
||||
Err(err) => error!("{err:?}"),
|
||||
};
|
||||
|
@ -374,12 +374,11 @@ fn load_output_bars(
|
|||
let map = INDEX_MAP.get_or_init(|| Mutex::new(vec![]));
|
||||
|
||||
let index = lock!(map).iter().position(|n| n == monitor_name);
|
||||
let index = match index {
|
||||
Some(index) => index,
|
||||
None => {
|
||||
lock!(map).push(monitor_name.clone());
|
||||
lock!(map).len() - 1
|
||||
}
|
||||
let index = if let Some(index) = index {
|
||||
index
|
||||
} else {
|
||||
lock!(map).push(monitor_name.clone());
|
||||
lock!(map).len() - 1
|
||||
};
|
||||
|
||||
let config = ironbar.config.borrow();
|
||||
|
|
|
@ -74,7 +74,7 @@ impl Module<gtk::Box> for CairoModule {
|
|||
where
|
||||
<Self as Module<gtk::Box>>::SendMessage: Clone,
|
||||
{
|
||||
let path = self.path.to_path_buf();
|
||||
let path = self.path.clone();
|
||||
|
||||
let tx = context.tx.clone();
|
||||
spawn(async move {
|
||||
|
@ -160,16 +160,14 @@ impl Module<gtk::Box> for CairoModule {
|
|||
let ptr = unsafe { cr.clone().into_glib_ptr().cast() };
|
||||
|
||||
// mlua needs a valid return type, even if we don't return anything
|
||||
|
||||
if let Err(err) =
|
||||
function.call::<_, Option<bool>>((id.as_str(), LightUserData(ptr)))
|
||||
{
|
||||
match err {
|
||||
Error::RuntimeError(message) => {
|
||||
let message = message.split_once("]:").expect("to exist").1;
|
||||
error!("[lua runtime error] {}:{message}", path.display())
|
||||
}
|
||||
_ => error!("{err}"),
|
||||
if let Error::RuntimeError(message) = err {
|
||||
let message = message.split_once("]:").expect("to exist").1;
|
||||
error!("[lua runtime error] {}:{message}", path.display());
|
||||
} else {
|
||||
error!("{err}");
|
||||
}
|
||||
|
||||
return Propagation::Stop;
|
||||
|
@ -196,10 +194,10 @@ impl Module<gtk::Box> for CairoModule {
|
|||
match res {
|
||||
Ok(script) => {
|
||||
match lua.load(&script).exec() {
|
||||
Ok(_) => {},
|
||||
Ok(()) => {},
|
||||
Err(Error::SyntaxError { message, ..}) => {
|
||||
let message = message.split_once("]:").expect("to exist").1;
|
||||
error!("[lua syntax error] {}:{message}", self.path.display())
|
||||
error!("[lua syntax error] {}:{message}", self.path.display());
|
||||
},
|
||||
Err(err) => error!("lua error: {err:?}")
|
||||
}
|
||||
|
|
|
@ -70,10 +70,10 @@ impl Module<Label> for SwayModeModule {
|
|||
let on_mode = move |mode: ModeEvent| {
|
||||
trace!("mode: {:?}", mode);
|
||||
label.set_use_markup(mode.pango_markup);
|
||||
if mode.change != "default" {
|
||||
label.set_markup(&mode.change)
|
||||
} else {
|
||||
if mode.change == "default" {
|
||||
label.set_markup("");
|
||||
} else {
|
||||
label.set_markup(&mode.change);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ pub struct SysInfoModule {
|
|||
|
||||
/// The orientation of text for the labels.
|
||||
///
|
||||
/// **Valid options**: `horizontal`, `vertical, `h`, `v`
|
||||
/// **Valid options**: `horizontal`, `vertical`, `h`, `v`
|
||||
/// <br>
|
||||
/// **Default** : `horizontal`
|
||||
#[serde(default)]
|
||||
|
@ -41,7 +41,7 @@ pub struct SysInfoModule {
|
|||
|
||||
/// The orientation by which the labels are laid out.
|
||||
///
|
||||
/// **Valid options**: `horizontal`, `vertical, `h`, `v`
|
||||
/// **Valid options**: `horizontal`, `vertical`, `h`, `v`
|
||||
/// <br>
|
||||
/// **Default** : `horizontal`
|
||||
direction: Option<ModuleOrientation>,
|
||||
|
|
|
@ -94,7 +94,7 @@ fn get_image_from_pixmap(item: &TrayMenu, size: u32) -> Result<Image> {
|
|||
return Err(Report::msg("empty pixmap"));
|
||||
}
|
||||
|
||||
let mut pixels = pixmap.pixels.to_vec();
|
||||
let mut pixels = pixmap.pixels.clone();
|
||||
|
||||
for i in (0..pixels.len()).step_by(4) {
|
||||
let alpha = pixels[i];
|
||||
|
|
|
@ -169,7 +169,7 @@ impl Popup {
|
|||
button_id,
|
||||
orientation,
|
||||
&window,
|
||||
output_size.clone(),
|
||||
&output_size,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ impl Popup {
|
|||
button_id,
|
||||
self.pos.orientation(),
|
||||
&self.window,
|
||||
self.output_size.clone(),
|
||||
&self.output_size,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ impl Popup {
|
|||
button_id: usize,
|
||||
orientation: Orientation,
|
||||
window: &ApplicationWindow,
|
||||
output_size: Rc<RefCell<(i32, i32)>>,
|
||||
output_size: &Rc<RefCell<(i32, i32)>>,
|
||||
) {
|
||||
let button = buttons
|
||||
.iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue