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