fix clippy warnings
This commit is contained in:
1 parent
7b88083020
commit
bdc3ba435f
39 files changed
+825
-688
No files matched your search
@@ -64,7 +64,7 @@ pub(super) fn nonnegative_theme_value(value: f64, field: &'static str) -> Result
|
||||
if value.is_finite() && value >= 0.0 {
|
||||
Ok(value)
|
||||
} else {
|
||||
Err(ConfigError::InvalidThemeValue {
|
||||
Err(ConfigError::ThemeValue {
|
||||
field,
|
||||
value: value.to_string(),
|
||||
})
|
||||
@@ -75,7 +75,7 @@ pub(super) fn finite_theme_value(value: f64, field: &'static str) -> Result<f64,
|
||||
if value.is_finite() {
|
||||
Ok(value)
|
||||
} else {
|
||||
Err(ConfigError::InvalidThemeValue {
|
||||
Err(ConfigError::ThemeValue {
|
||||
field,
|
||||
value: value.to_string(),
|
||||
})
|
||||
@@ -86,7 +86,7 @@ pub(super) fn unit_theme_value(value: f64, field: &'static str) -> Result<f64, C
|
||||
if value.is_finite() && (0.0..=1.0).contains(&value) {
|
||||
Ok(value)
|
||||
} else {
|
||||
Err(ConfigError::InvalidThemeValue {
|
||||
Err(ConfigError::ThemeValue {
|
||||
field,
|
||||
value: value.to_string(),
|
||||
})
|
||||
@@ -96,7 +96,7 @@ pub(super) fn unit_theme_value(value: f64, field: &'static str) -> Result<f64, C
|
||||
pub(super) fn parse_color(value: &str, field: &'static str) -> Result<RgbaColor, ConfigError> {
|
||||
let digits = value.strip_prefix('#').unwrap_or(value);
|
||||
if !digits.is_ascii() || !matches!(digits.len(), 6 | 8) {
|
||||
return Err(ConfigError::InvalidThemeValue {
|
||||
return Err(ConfigError::ThemeValue {
|
||||
field,
|
||||
value: value.to_owned(),
|
||||
});
|
||||
@@ -108,13 +108,13 @@ pub(super) fn parse_color(value: &str, field: &'static str) -> Result<RgbaColor,
|
||||
.zip(parse_channel(4))
|
||||
.map(|((red, green), blue)| (red, green, blue))
|
||||
else {
|
||||
return Err(ConfigError::InvalidThemeValue {
|
||||
return Err(ConfigError::ThemeValue {
|
||||
field,
|
||||
value: value.to_owned(),
|
||||
});
|
||||
};
|
||||
let alpha = if digits.len() == 8 {
|
||||
parse_channel(6).ok_or_else(|| ConfigError::InvalidThemeValue {
|
||||
parse_channel(6).ok_or_else(|| ConfigError::ThemeValue {
|
||||
field,
|
||||
value: value.to_owned(),
|
||||
})?
|
||||
|
||||
@@ -23,16 +23,13 @@ impl Config {
|
||||
for configured in &self.bindings {
|
||||
let identity = binding_identity(configured, &keymap)?;
|
||||
if !supplied.insert(identity.clone()) {
|
||||
return Err(ConfigError::InvalidBinding(format!(
|
||||
"duplicate binding {:?}",
|
||||
configured.keys
|
||||
)));
|
||||
return Err(ConfigError::Binding(format!("duplicate binding {:?}", configured.keys)));
|
||||
}
|
||||
|
||||
bindings.retain(|binding| binding_identity_for_runtime(binding) != identity);
|
||||
if configured.disabled {
|
||||
if configured.action.is_some() || configured.argument.is_some() {
|
||||
return Err(ConfigError::InvalidBinding(format!(
|
||||
return Err(ConfigError::Binding(format!(
|
||||
"disabled binding {:?} cannot have an action or argument",
|
||||
configured.keys
|
||||
)));
|
||||
@@ -49,12 +46,10 @@ impl Config {
|
||||
pub(super) fn validate_commands(commands: &HashMap<String, Vec<String>>) -> Result<(), ConfigError> {
|
||||
for (name, argv) in commands {
|
||||
if name.trim().is_empty() {
|
||||
return Err(ConfigError::InvalidBinding("command names cannot be empty".to_owned()));
|
||||
return Err(ConfigError::Binding("command names cannot be empty".to_owned()));
|
||||
}
|
||||
if argv.is_empty() || argv[0].is_empty() {
|
||||
return Err(ConfigError::InvalidBinding(format!(
|
||||
"command {name:?} must contain a program"
|
||||
)));
|
||||
return Err(ConfigError::Binding(format!("command {name:?} must contain a program")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +69,7 @@ pub(crate) fn physical_keymap(input: &InputSettings) -> Result<xkb::Keymap, Conf
|
||||
options,
|
||||
xkb::KEYMAP_COMPILE_NO_FLAGS,
|
||||
)
|
||||
.ok_or_else(|| ConfigError::InvalidBinding("failed to compile the XKB keymap".to_owned()))
|
||||
.ok_or_else(|| ConfigError::Binding("failed to compile the XKB keymap".to_owned()))
|
||||
}
|
||||
|
||||
pub(super) fn parse_binding(
|
||||
@@ -83,7 +78,7 @@ pub(super) fn parse_binding(
|
||||
keymap: &xkb::Keymap,
|
||||
) -> Result<Binding, ConfigError> {
|
||||
if configured.disabled {
|
||||
return Err(ConfigError::InvalidBinding(format!(
|
||||
return Err(ConfigError::Binding(format!(
|
||||
"disabled binding {:?} cannot be executed",
|
||||
configured.keys
|
||||
)));
|
||||
@@ -93,7 +88,7 @@ pub(super) fn parse_binding(
|
||||
let action = configured
|
||||
.action
|
||||
.as_deref()
|
||||
.ok_or_else(|| ConfigError::InvalidBinding(format!("binding {:?} has no action", configured.keys)))?;
|
||||
.ok_or_else(|| ConfigError::Binding(format!("binding {:?} has no action", configured.keys)))?;
|
||||
let action = parse_action(action, configured.argument.as_deref(), commands)?;
|
||||
let trigger = match identity.match_mode {
|
||||
BindingMatch::Keysym => BindingTrigger::Keysym(identity.key),
|
||||
@@ -123,7 +118,7 @@ pub(super) fn binding_identity(
|
||||
let (modifiers, key) = parse_chord(&configured.keys)?;
|
||||
if let Some((fingers, direction)) = parse_swipe(&key) {
|
||||
if configured.match_mode == BindingMatch::Physical || modifiers != BindingModifiers::default() {
|
||||
return Err(ConfigError::InvalidBinding(
|
||||
return Err(ConfigError::Binding(
|
||||
"swipes cannot use keyboard modifiers or physical key matching".into(),
|
||||
));
|
||||
}
|
||||
@@ -139,13 +134,13 @@ pub(super) fn binding_identity(
|
||||
.key_by_name(&key.to_ascii_uppercase())
|
||||
.map(Keycode::raw)
|
||||
.ok_or_else(|| {
|
||||
ConfigError::InvalidBinding(format!(
|
||||
ConfigError::Binding(format!(
|
||||
"unknown XKB physical key name {key:?} in {:?}",
|
||||
configured.keys
|
||||
))
|
||||
})?,
|
||||
BindingMatch::Swipe => {
|
||||
return Err(ConfigError::InvalidBinding(
|
||||
return Err(ConfigError::Binding(
|
||||
"gesture keys must use Swipe3Left/Right/Up/Down (3–5 fingers)".into(),
|
||||
));
|
||||
}
|
||||
@@ -178,7 +173,7 @@ pub(super) fn parse_chord(chord: &str) -> Result<(BindingModifiers, String), Con
|
||||
|
||||
for component in chord.split('+').map(str::trim) {
|
||||
if component.is_empty() {
|
||||
return Err(ConfigError::InvalidBinding(format!("invalid key chord {chord:?}")));
|
||||
return Err(ConfigError::Binding(format!("invalid key chord {chord:?}")));
|
||||
}
|
||||
|
||||
let slot = match component.to_ascii_lowercase().as_str() {
|
||||
@@ -190,17 +185,17 @@ pub(super) fn parse_chord(chord: &str) -> Result<(BindingModifiers, String), Con
|
||||
};
|
||||
if let Some(slot) = slot {
|
||||
if *slot {
|
||||
return Err(ConfigError::InvalidBinding(format!("duplicate modifier in {chord:?}")));
|
||||
return Err(ConfigError::Binding(format!("duplicate modifier in {chord:?}")));
|
||||
}
|
||||
*slot = true;
|
||||
} else if key.replace(component.to_owned()).is_some() {
|
||||
return Err(ConfigError::InvalidBinding(format!(
|
||||
return Err(ConfigError::Binding(format!(
|
||||
"key chord {chord:?} contains more than one key"
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
let key = key.ok_or_else(|| ConfigError::InvalidBinding(format!("key chord {chord:?} does not contain a key")))?;
|
||||
let key = key.ok_or_else(|| ConfigError::Binding(format!("key chord {chord:?} does not contain a key")))?;
|
||||
Ok((modifiers, key))
|
||||
}
|
||||
|
||||
@@ -236,7 +231,7 @@ pub(super) fn parse_keysym(name: &str) -> Result<u32, ConfigError> {
|
||||
symbol = xkb::keysym_from_name(&normalized, xkb::KEYSYM_CASE_INSENSITIVE);
|
||||
}
|
||||
if symbol.raw() == keysyms::KEY_NoSymbol {
|
||||
Err(ConfigError::InvalidBinding(format!("unknown keysym {name:?}")))
|
||||
Err(ConfigError::Binding(format!("unknown keysym {name:?}")))
|
||||
} else {
|
||||
Ok(symbol.raw())
|
||||
}
|
||||
@@ -249,7 +244,7 @@ pub(super) fn parse_action(
|
||||
) -> Result<BindingAction, ConfigError> {
|
||||
let no_argument = || {
|
||||
if argument.is_some() {
|
||||
Err(ConfigError::InvalidBinding(format!(
|
||||
Err(ConfigError::Binding(format!(
|
||||
"action {action:?} does not accept an argument"
|
||||
)))
|
||||
} else {
|
||||
@@ -257,7 +252,7 @@ pub(super) fn parse_action(
|
||||
}
|
||||
};
|
||||
let required_argument =
|
||||
|| argument.ok_or_else(|| ConfigError::InvalidBinding(format!("action {action:?} requires an argument")));
|
||||
|| argument.ok_or_else(|| ConfigError::Binding(format!("action {action:?} requires an argument")));
|
||||
|
||||
match action {
|
||||
"none" => {
|
||||
@@ -276,7 +271,7 @@ pub(super) fn parse_action(
|
||||
let command = required_argument()?;
|
||||
let argv = commands
|
||||
.get(command)
|
||||
.ok_or_else(|| ConfigError::InvalidBinding(format!("unknown command {command:?}")))?;
|
||||
.ok_or_else(|| ConfigError::Binding(format!("unknown command {command:?}")))?;
|
||||
Ok(BindingAction::Spawn(argv.clone()))
|
||||
}
|
||||
"close" => {
|
||||
@@ -332,7 +327,7 @@ pub(super) fn parse_action(
|
||||
no_argument()?;
|
||||
Ok(BindingAction::ToggleKeybindingGuide)
|
||||
}
|
||||
_ => Err(ConfigError::InvalidBinding(format!("unknown action {action:?}"))),
|
||||
_ => Err(ConfigError::Binding(format!("unknown action {action:?}"))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,14 +337,14 @@ pub(super) fn parse_direction(argument: &str) -> Result<Direction, ConfigError>
|
||||
"right" => Ok(Direction::Right),
|
||||
"up" => Ok(Direction::Up),
|
||||
"down" => Ok(Direction::Down),
|
||||
_ => Err(ConfigError::InvalidBinding(format!("invalid direction {argument:?}"))),
|
||||
_ => Err(ConfigError::Binding(format!("invalid direction {argument:?}"))),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn parse_workspace(argument: &str) -> Result<u8, ConfigError> {
|
||||
match argument.parse() {
|
||||
Ok(workspace) if workspace > 0 => Ok(workspace),
|
||||
_ => Err(ConfigError::InvalidBinding(format!("invalid workspace {argument:?}"))),
|
||||
_ => Err(ConfigError::Binding(format!("invalid workspace {argument:?}"))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,7 +454,7 @@ pub enum BindingAction {
|
||||
impl Binding {
|
||||
pub(crate) fn portal_trigger(chord: &str) -> Result<Self, ConfigError> {
|
||||
if chord.len() > 256 {
|
||||
return Err(ConfigError::InvalidBinding("Shortcut is too long".into()));
|
||||
return Err(ConfigError::Binding("Shortcut is too long".into()));
|
||||
}
|
||||
let parts = chord.split('+').collect::<Vec<_>>();
|
||||
if parts
|
||||
@@ -468,7 +463,7 @@ impl Binding {
|
||||
.count()
|
||||
> 1
|
||||
{
|
||||
return Err(ConfigError::InvalidBinding("Duplicate NUM modifier".into()));
|
||||
return Err(ConfigError::Binding("Duplicate NUM modifier".into()));
|
||||
}
|
||||
let chord = parts
|
||||
.into_iter()
|
||||
@@ -482,7 +477,7 @@ impl Binding {
|
||||
&& matches!(symbol, keysyms::KEY_Escape | keysyms::KEY_F1..=keysyms::KEY_F12))
|
||||
|| (keysyms::KEY_XF86Switch_VT_1..=keysyms::KEY_XF86Switch_VT_12).contains(&symbol)
|
||||
{
|
||||
return Err(ConfigError::InvalidBinding("Reserved system shortcut".into()));
|
||||
return Err(ConfigError::Binding("Reserved system shortcut".into()));
|
||||
}
|
||||
Ok(Self {
|
||||
modifiers,
|
||||
|
||||
@@ -3,26 +3,26 @@ use super::*;
|
||||
impl Config {
|
||||
pub fn input_settings(&self) -> Result<InputSettings, ConfigError> {
|
||||
if self.input.xkb_layout.trim().is_empty() {
|
||||
return Err(ConfigError::InvalidInputValue {
|
||||
return Err(ConfigError::InputValue {
|
||||
field: "xkb_layout",
|
||||
value: self.input.xkb_layout.clone(),
|
||||
});
|
||||
}
|
||||
if self.input.repeat_rate <= 0 {
|
||||
return Err(ConfigError::InvalidInputValue {
|
||||
return Err(ConfigError::InputValue {
|
||||
field: "repeat_rate",
|
||||
value: self.input.repeat_rate.to_string(),
|
||||
});
|
||||
}
|
||||
if self.input.repeat_delay_ms < 0 {
|
||||
return Err(ConfigError::InvalidInputValue {
|
||||
return Err(ConfigError::InputValue {
|
||||
field: "repeat_delay_ms",
|
||||
value: self.input.repeat_delay_ms.to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
if !(16..=1000).contains(&self.input.touchpad.swipe_threshold) {
|
||||
return Err(ConfigError::InvalidInputValue {
|
||||
return Err(ConfigError::InputValue {
|
||||
field: "touchpad.swipe_threshold",
|
||||
value: self.input.touchpad.swipe_threshold.to_string(),
|
||||
});
|
||||
@@ -56,7 +56,7 @@ impl Config {
|
||||
let stiffness = positive_animation_value(self.animations.spring.stiffness, "spring.stiffness")?;
|
||||
let damping = self.animations.spring.damping;
|
||||
if !damping.is_finite() || damping < 0.0 {
|
||||
return Err(ConfigError::InvalidAnimationValue {
|
||||
return Err(ConfigError::AnimationValue {
|
||||
field: "spring.damping",
|
||||
value: damping,
|
||||
});
|
||||
@@ -92,7 +92,7 @@ pub(super) fn positive_animation_value(value: f64, field: &'static str) -> Resul
|
||||
if value.is_finite() && value > 0.0 {
|
||||
Ok(value)
|
||||
} else {
|
||||
Err(ConfigError::InvalidAnimationValue { field, value })
|
||||
Err(ConfigError::AnimationValue { field, value })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ pub(super) fn nonnegative_layout_value(value: f64, field: &'static str) -> Resul
|
||||
if value.is_finite() && value >= 0.0 {
|
||||
Ok(value)
|
||||
} else {
|
||||
Err(ConfigError::InvalidLayoutValue { field, value })
|
||||
Err(ConfigError::LayoutValue { field, value })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ pub(super) fn parse_column_width(value: &ColumnWidthValue, field: &'static str)
|
||||
match value {
|
||||
ColumnWidthValue::Proportion(value) if value.is_finite() && *value > 0.0 => Ok(ColumnWidth::Proportion(*value)),
|
||||
ColumnWidthValue::Named(value) if value.eq_ignore_ascii_case("full") => Ok(ColumnWidth::Full),
|
||||
value => Err(ConfigError::InvalidColumnWidth {
|
||||
value => Err(ConfigError::ColumnWidth {
|
||||
field,
|
||||
value: match value {
|
||||
ColumnWidthValue::Proportion(value) => value.to_string(),
|
||||
|
||||
@@ -9,19 +9,13 @@ impl Config {
|
||||
.map(|profile| {
|
||||
let name = profile.name.trim();
|
||||
if name.is_empty() {
|
||||
return Err(ConfigError::InvalidOutputProfile(
|
||||
"profile names cannot be empty".to_owned(),
|
||||
));
|
||||
return Err(ConfigError::OutputProfile("profile names cannot be empty".to_owned()));
|
||||
}
|
||||
if !names.insert(name.to_owned()) {
|
||||
return Err(ConfigError::InvalidOutputProfile(format!(
|
||||
"duplicate profile name {name:?}"
|
||||
)));
|
||||
return Err(ConfigError::OutputProfile(format!("duplicate profile name {name:?}")));
|
||||
}
|
||||
if profile.outputs.is_empty() {
|
||||
return Err(ConfigError::InvalidOutputProfile(format!(
|
||||
"profile {name:?} has no outputs"
|
||||
)));
|
||||
return Err(ConfigError::OutputProfile(format!("profile {name:?} has no outputs")));
|
||||
}
|
||||
|
||||
let mut matchers = HashSet::new();
|
||||
@@ -31,17 +25,17 @@ impl Config {
|
||||
.map(|output| {
|
||||
let matcher = output.matcher.trim();
|
||||
if matcher.is_empty() {
|
||||
return Err(ConfigError::InvalidOutputProfile(format!(
|
||||
return Err(ConfigError::OutputProfile(format!(
|
||||
"profile {name:?} contains an empty output matcher"
|
||||
)));
|
||||
}
|
||||
if !matchers.insert(matcher.to_owned()) {
|
||||
return Err(ConfigError::InvalidOutputProfile(format!(
|
||||
return Err(ConfigError::OutputProfile(format!(
|
||||
"profile {name:?} repeats output matcher {matcher:?}"
|
||||
)));
|
||||
}
|
||||
if !output.scale.is_finite() || output.scale <= 0.0 {
|
||||
return Err(ConfigError::InvalidOutputProfile(format!(
|
||||
return Err(ConfigError::OutputProfile(format!(
|
||||
"profile {name:?} output {matcher:?} has invalid scale {}",
|
||||
output.scale
|
||||
)));
|
||||
@@ -56,7 +50,7 @@ impl Config {
|
||||
.as_deref()
|
||||
.map(parse_output_mode)
|
||||
.transpose()
|
||||
.map_err(ConfigError::InvalidOutputProfile)?,
|
||||
.map_err(ConfigError::OutputProfile)?,
|
||||
scale: output.scale,
|
||||
transform: output.transform,
|
||||
position: output.position,
|
||||
|
||||
Reference in new issue
Block a user