Skip to content

Commit

Permalink
Use if_chain as reminder for rust-lang/rust#53667
Browse files Browse the repository at this point in the history
  • Loading branch information
CrendKing committed Jun 11, 2024
1 parent 4846cbc commit 2339249
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = '2021'
duration-str = '*'
enigo = { version = '*', default-features = false, features = ['serde', 'wayland'] }
gilrs = { version = '*', features = ['serde'] }
if_chain = '*'
lazy_static = '*'
serde = '*'
shlex = '*'
Expand Down
7 changes: 5 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::time::Duration;

use duration_str::deserialize_duration;
use if_chain::if_chain;

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
Expand Down Expand Up @@ -49,8 +50,10 @@ impl Config {
return Err("Trigger zone smaller than dead zone");
}

if let Some(activator) = &self.alternative_activator {
if self.main.contains_key(activator) {
if_chain! {
if let Some(activator) = &self.alternative_activator;
if self.main.contains_key(activator);
then {
return Err("Activator for alternative set is remapped");
}
}
Expand Down
18 changes: 11 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::atomic::{AtomicBool, Ordering};

use enigo::{Direction, Enigo, Keyboard, Mouse};
use gilrs::{Axis, Event, EventType, Gilrs};
use if_chain::if_chain;
use lazy_static::lazy_static;

use crate::atomic_f32::AtomicF32;
Expand Down Expand Up @@ -45,8 +46,10 @@ lazy_static! {
}

fn press_input(input_name: &str, is_press_down: bool) {
if let Some(activator) = &CONFIG.alternative_activator {
if input_name == activator.as_ref() {
if_chain! {
if let Some(activator) = &CONFIG.alternative_activator;
if input_name == activator.as_ref();
then {
IS_ALTERNATIVE_ACTIVE.store(is_press_down, Ordering::Relaxed);
return;
}
Expand Down Expand Up @@ -110,11 +113,12 @@ fn press_input(input_name: &str, is_press_down: bool) {
.unwrap();
}
Remap::Command(cmdline) => {
if is_press_down {
if let Some(components) = shlex::split(cmdline) {
if !components.is_empty() {
std::process::Command::new(&components[0]).args(&components[1..]).spawn().unwrap();
}
if_chain! {
if is_press_down;
if let Some(components) = shlex::split(cmdline);
if !components.is_empty();
then {
std::process::Command::new(&components[0]).args(&components[1..]).spawn().unwrap();
}
}
}
Expand Down

0 comments on commit 2339249

Please sign in to comment.