#[derive(Debug)]
pub struct ExecBind {
pub mods: Vec<Mod>,
pub key: Box<str>,
pub exec: String,
pub behavior: ExecBindBehavior,
pub desc: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExecBindBehavior {
PressOnce,
Repeating,
Release,
TransparentReleaseIgnoringMods {
unless_keys_down: Option<(&'static str, &'static str)>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mod {
Alt,
Super,
Ctrl,
Shift,
}
impl From<crate::Modifier> for Mod {
fn from(value: crate::Modifier) -> Self {
match value {
crate::Modifier::Alt => Self::Alt,
crate::Modifier::Ctrl => Self::Ctrl,
crate::Modifier::Super => Self::Super,
}
}
}
pub fn is_modifier_keysym(key: &str) -> bool {
const MODIFIER_KEYSYMS: [&str; 10] = [
"Super_L",
"Super_R",
"Alt_L",
"Alt_R",
"Control_L",
"Control_R",
"Meta_L",
"Meta_R",
"Hyper_L",
"Hyper_R",
];
MODIFIER_KEYSYMS
.iter()
.any(|keysym| key.eq_ignore_ascii_case(keysym))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_modifier_keysym_true() {
for keysym in [
"sUpEr_l",
"Super_R",
"aLt_l",
"Alt_R",
"cOnTrOl_l",
"Control_R",
"mEtA_l",
"Meta_R",
"hYpEr_l",
"Hyper_R",
] {
assert!(is_modifier_keysym(keysym), "{keysym} invalid");
}
}
#[test]
fn is_modifier_keysym_false() {
for keysym in ["Tab", "Shift", "Shift_R", "Shift_L", "grave", "a"] {
assert!(!is_modifier_keysym(keysym), "{keysym} invalid");
}
}
}