Add consume config

main
Tait Hoyem 2 years ago
parent 3e622b7192
commit af323a0f16

@ -56,6 +56,7 @@ pub struct Hotkey {
pub keysym: evdev::Key,
pub modifiers: Vec<Modifier>,
pub command: String,
pub consume: bool,
}
#[derive(Debug, PartialEq, Copy, Clone)]
@ -77,8 +78,8 @@ pub enum Modifier {
}
impl Hotkey {
pub fn new(mode: String, keysym: evdev::Key, modifiers: Vec<Modifier>, command: String) -> Self {
Hotkey { mode, keysym, modifiers, command }
pub fn new(mode: String, keysym: evdev::Key, modifiers: Vec<Modifier>, command: String, consume: bool) -> Self {
Hotkey { mode, keysym, modifiers, command, consume }
}
}
@ -282,9 +283,9 @@ fn parse_contents(contents: String) -> Result<Vec<Hotkey>, Error> {
'hotkey_parse: for (key, command) in extracted_keys.iter().zip(extracted_commands.iter()) {
println!("{} {}", key, command);
let (mode, keysym, modifiers) =
let (mode, keysym, modifiers, consume) =
parse_keybind(key, line_number + 1, &key_to_evdev_key, &mod_to_mod_enum)?;
let hotkey = Hotkey { mode, keysym, modifiers, command: command.to_string() };
let hotkey = Hotkey { mode, keysym, modifiers, command: command.to_string(), consume };
// Ignore duplicate hotkeys
for i in hotkeys.iter() {
@ -307,7 +308,7 @@ fn parse_keybind(
line_nr: u32,
key_to_evdev_key: &HashMap<&str, evdev::Key>,
mod_to_mod_enum: &HashMap<&str, Modifier>,
) -> Result<(String, evdev::Key, Vec<Modifier>), Error> {
) -> Result<(String, evdev::Key, Vec<Modifier>, bool), Error> {
let line = line.split('#').next().unwrap();
let tokens: Vec<String> =
line.split('+').map(|s| s.trim().to_lowercase()).filter(|s| s != "_").collect();
@ -318,6 +319,7 @@ fn parse_keybind(
if token.starts_with("[") && token.ends_with("]") {
continue;
}
if token.to_string() == "!" { continue; }
if key_to_evdev_key.contains_key(token.as_str()) {
// Can't have a key that's like a modifier
if token != last_token {
@ -335,6 +337,12 @@ fn parse_keybind(
// Translate keypress into evdev key
let keysym = key_to_evdev_key.get(last_token).unwrap();
let consume = if tokens
.iter()
.filter(|s| s.to_string() == "!")
.map(|s| s.to_string())
.collect::<Vec<String>>()
.len() == 1 { true } else { false };
let mode = tokens
.iter()
.filter(|s| s.starts_with("[") && s.ends_with("]"))
@ -350,7 +358,7 @@ fn parse_keybind(
.map(|token| *mod_to_mod_enum.get(token.as_str()).unwrap())
.collect();
Ok((mode, *keysym, modifiers))
Ok((mode, *keysym, modifiers, consume))
}
fn extract_curly_brace(line: &str) -> Vec<String> {

@ -175,6 +175,7 @@ pub fn key_listener() {
evdev::Key::KEY_A,
default_test_modifier,
String::from("notify-send \"it works\""),
false,
),
ran_at: SystemTime::now(),
};

Loading…
Cancel
Save