Fix clippy lints

This commit is contained in:
elkowar 2024-02-17 12:34:47 +01:00 committed by ElKowar
parent 82a429a569
commit 031a2b52ec
12 changed files with 26 additions and 49 deletions

View File

@ -45,12 +45,8 @@ impl EwwConfig {
let config = Config::generate_from_main_file(files, yuck_path)?;
// run some validations on the configuration
let magic_globals: Vec<_> = inbuilt::INBUILT_VAR_NAMES
.iter()
.chain(inbuilt::MAGIC_CONSTANT_NAMES)
.into_iter()
.map(|x| VarName::from(*x))
.collect();
let magic_globals: Vec<_> =
inbuilt::INBUILT_VAR_NAMES.iter().chain(inbuilt::MAGIC_CONSTANT_NAMES).map(|x| VarName::from(*x)).collect();
yuck::config::validate::validate(&config, magic_globals)?;
for (name, def) in &config.widget_definitions {

View File

@ -6,4 +6,3 @@ pub mod system_stats;
pub mod window_definition;
pub use eww_config::*;
pub use script_var::*;
pub use window_definition::*;

View File

@ -197,8 +197,8 @@ mod platform_x11 {
let strut_list: Vec<u8> = match strut_def.side {
Side::Left => vec![dist + mon_x, 0, 0, 0, mon_x, mon_end_y, 0, 0, 0, 0, 0, 0],
Side::Right => vec![0, root_window_geometry.width as u32 - mon_end_x + dist, 0, 0, 0, 0, mon_x, mon_end_y, 0, 0, 0, 0],
Side::Top => vec![0, 0, dist + mon_y as u32, 0, 0, 0, 0, 0, mon_x, mon_end_x, 0, 0],
Side::Bottom => vec![0, 0, 0, root_window_geometry.height as u32 - mon_end_y + dist, 0, 0, 0, 0, 0, 0, mon_x as u32, mon_end_x],
Side::Top => vec![0, 0, dist + mon_y, 0, 0, 0, 0, 0, mon_x, mon_end_x, 0, 0],
Side::Bottom => vec![0, 0, 0, root_window_geometry.height as u32 - mon_end_y + dist, 0, 0, 0, 0, 0, 0, mon_x, mon_end_x],
// This should never happen but if it does the window will be anchored on the
// right of the screen
}.iter().flat_map(|x| x.to_le_bytes().to_vec()).collect();

View File

@ -1,7 +1,4 @@
use derive_more::*;
pub trait Rectangular {
fn get_rect(&self) -> Rect;
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Display)]
#[display(fmt = ".x*.y:.width*.height")]
@ -11,15 +8,3 @@ pub struct Rect {
pub width: i32,
pub height: i32,
}
impl Rectangular for Rect {
fn get_rect(&self) -> Rect {
*self
}
}
impl Rectangular for gdk::Rectangle {
fn get_rect(&self) -> Rect {
Rect { x: self.x(), y: self.y(), width: self.width(), height: self.height() }
}
}

View File

@ -189,7 +189,7 @@ fn listen_for_daemon_response(mut recv: DaemonResponseReceiver) {
/// attempt to send a command to the daemon and send it the given action repeatedly.
fn handle_server_command(paths: &EwwPaths, action: &ActionWithServer, connect_attempts: usize) -> Result<Option<DaemonResponse>> {
log::debug!("Trying to find server process at socket {}", paths.get_ipc_socket_file().display());
let mut stream = attempt_connect(&paths.get_ipc_socket_file(), connect_attempts).context("Failed to connect to daemon")?;
let mut stream = attempt_connect(paths.get_ipc_socket_file(), connect_attempts).context("Failed to connect to daemon")?;
log::debug!("Connected to Eww server ({}).", &paths.get_ipc_socket_file().display());
client::do_server_call(&mut stream, action).context("Error while forwarding command to server")
}

View File

@ -236,7 +236,7 @@ impl ListenVarHandler {
crate::try_logging_errors!(format!("Executing listen var-command {}", &var.command) => {
let mut handle = unsafe {
tokio::process::Command::new("sh")
.args(&["-c", &var.command])
.args(["-c", &var.command])
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.stdin(std::process::Stdio::null())

View File

@ -26,7 +26,7 @@ pub fn initialize_server<B: DisplayBackend>(
) -> Result<ForkResult> {
let (ui_send, mut ui_recv) = tokio::sync::mpsc::unbounded_channel();
std::env::set_current_dir(&paths.get_config_dir())
std::env::set_current_dir(paths.get_config_dir())
.with_context(|| format!("Failed to change working directory to {}", paths.get_config_dir().display()))?;
log::info!("Loading paths: {}", &paths);
@ -42,7 +42,7 @@ pub fn initialize_server<B: DisplayBackend>(
};
if should_daemonize {
let fork_result = do_detach(&paths.get_log_file())?;
let fork_result = do_detach(paths.get_log_file())?;
if fork_result == ForkResult::Parent {
return Ok(ForkResult::Parent);

View File

@ -156,27 +156,24 @@ impl WidgetImpl for CircProgPriv {
fn draw(&self, cr: &cairo::Context) -> Inhibit {
let res: Result<()> = try {
let value = *self.value.borrow();
let start_at = *self.start_at.borrow() as f64;
let thickness = *self.thickness.borrow() as f64;
let clockwise = *self.clockwise.borrow() as bool;
let start_at = *self.start_at.borrow();
let thickness = *self.thickness.borrow();
let clockwise = *self.clockwise.borrow();
let styles = self.obj().style_context();
let margin = styles.margin(gtk::StateFlags::NORMAL);
// Padding is not supported yet
let fg_color: gdk::RGBA = styles.color(gtk::StateFlags::NORMAL);
let bg_color: gdk::RGBA = styles.style_property_for_state("background-color", gtk::StateFlags::NORMAL).get()?;
let (start_angle, end_angle) = if clockwise {
(0.0, perc_to_rad(value as f64))
} else {
(perc_to_rad(100.0 - value as f64), 2f64 * std::f64::consts::PI)
};
let (start_angle, end_angle) =
if clockwise { (0.0, perc_to_rad(value)) } else { (perc_to_rad(100.0 - value), 2f64 * std::f64::consts::PI) };
let total_width = self.obj().allocated_width() as f64;
let total_height = self.obj().allocated_height() as f64;
let center = (total_width / 2.0, total_height / 2.0);
let circle_width = total_width - margin.left as f64 - margin.right as f64;
let circle_height = total_height as f64 - margin.top as f64 - margin.bottom as f64;
let circle_height = total_height - margin.top as f64 - margin.bottom as f64;
let outer_ring = f64::min(circle_width, circle_height) / 2.0;
let inner_ring = (f64::min(circle_width, circle_height) / 2.0) - thickness;

View File

@ -179,7 +179,7 @@ impl WidgetImpl for GraphPriv {
let (min, max) = {
let mut max = *self.max.borrow();
let min = *self.min.borrow();
let dynamic = *self.dynamic.borrow() as bool;
let dynamic = *self.dynamic.borrow();
if dynamic {
// Check for points higher than max
for (_, value) in history {

View File

@ -11,7 +11,7 @@ pub mod widget_definitions;
/// This command may use placeholders which will be replaced by the values of the arguments given.
/// This can either be the placeholder `{}`, which will be replaced by the first argument,
/// Or a placeholder like `{0}`, `{1}`, etc, which will refer to the respective argument.
pub(self) fn run_command<T>(timeout: std::time::Duration, cmd: &str, args: &[T])
fn run_command<T>(timeout: std::time::Duration, cmd: &str, args: &[T])
where
T: 'static + std::fmt::Display + Send + Sync + Clone,
{

View File

@ -83,7 +83,7 @@ pub const BUILTIN_WIDGET_NAMES: &[&str] = &[
WIDGET_NAME_STACK,
];
//// widget definitions
/// widget definitions
pub(super) fn widget_use_to_gtk_widget(bargs: &mut BuilderArgs) -> Result<gtk::Widget> {
let gtk_widget = match bargs.widget_use.name.as_str() {
WIDGET_NAME_BOX => build_gtk_box(bargs)?.upcast(),
@ -1050,7 +1050,7 @@ fn build_circular_progress_bar(bargs: &mut BuilderArgs) -> Result<CircProg> {
// @prop thickness - the thickness of the circle
prop(thickness: as_f64) { w.set_property("thickness", thickness); },
// @prop clockwise - wether the progress bar spins clockwise or counter clockwise
prop(clockwise: as_bool) { w.set_property("clockwise", &clockwise); },
prop(clockwise: as_bool) { w.set_property("clockwise", clockwise); },
});
Ok(w)
}
@ -1062,11 +1062,11 @@ fn build_graph(bargs: &mut BuilderArgs) -> Result<super::graph::Graph> {
let w = super::graph::Graph::new();
def_widget!(bargs, _g, w, {
// @prop value - the value, between 0 - 100
prop(value: as_f64) { w.set_property("value", &value); },
prop(value: as_f64) { w.set_property("value", value); },
// @prop thickness - the thickness of the line
prop(thickness: as_f64) { w.set_property("thickness", &thickness); },
prop(thickness: as_f64) { w.set_property("thickness", thickness); },
// @prop time-range - the range of time to show
prop(time_range: as_duration) { w.set_property("time-range", &(time_range.as_millis() as u64)); },
prop(time_range: as_duration) { w.set_property("time-range", time_range.as_millis() as u64); },
// @prop min - the minimum value to show (defaults to 0 if value_max is provided)
// @prop max - the maximum value to show
prop(min: as_f64 = 0, max: as_f64 = 100) {
@ -1075,14 +1075,14 @@ fn build_graph(bargs: &mut BuilderArgs) -> Result<super::graph::Graph> {
format!("Graph's min ({min}) should never be higher than max ({max})")
)).into());
}
w.set_property("min", &min);
w.set_property("max", &max);
w.set_property("min", min);
w.set_property("max", max);
},
// @prop dynamic - whether the y range should dynamically change based on value
prop(dynamic: as_bool) { w.set_property("dynamic", &dynamic); },
prop(dynamic: as_bool) { w.set_property("dynamic", dynamic); },
// @prop line-style - changes the look of the edges in the graph. Values: "miter" (default), "round",
// "bevel"
prop(line_style: as_string) { w.set_property("line-style", &line_style); },
prop(line_style: as_string) { w.set_property("line-style", line_style); },
});
Ok(w)
}

View File

@ -77,7 +77,7 @@ impl WindowArguments {
}
if local_variables.len() != window_def.expected_args.len() {
let unexpected_vars: Vec<_> = local_variables.keys().cloned().filter(|n| !expected_args.contains(&n.0)).collect();
let unexpected_vars: Vec<_> = local_variables.keys().filter(|&n| !expected_args.contains(&n.0)).cloned().collect();
bail!(
"variables {} unexpectedly defined when creating window with id '{}'",
unexpected_vars.join(", "),