Skip to content

Commit

Permalink
refactor: fix some pedantic clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeStanger committed Aug 14, 2024
1 parent 4d30819 commit 04f45cc
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/clients/music/mpris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/clients/sway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/clients/wayland/wlr_foreign_toplevel/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ where
ToplevelHandle {
handle: handle.clone(),
},
)
);
}
Event::Done if !lock!(data.inner).closed => {
{
Expand Down
18 changes: 8 additions & 10 deletions src/config/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
11 changes: 6 additions & 5 deletions src/ipc/server/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
}
Expand All @@ -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 {
Expand All @@ -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
Expand Down
17 changes: 8 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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:?}"),
};
Expand Down Expand Up @@ -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();
Expand Down
18 changes: 8 additions & 10 deletions src/modules/cairo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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:?}")
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/sway/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/modules/sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ 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)]
orientation: ModuleOrientation,

/// 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>,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/tray/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions src/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Popup {
button_id,
orientation,
&window,
output_size.clone(),
&output_size,
);
}
}
Expand Down Expand Up @@ -202,7 +202,7 @@ impl Popup {
button_id,
self.pos.orientation(),
&self.window,
self.output_size.clone(),
&self.output_size,
);
}
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 04f45cc

Please sign in to comment.