Added Modifier-only keybinding support
This commit is contained in:
parent
d051f41de6
commit
37fb26a403
4 changed files with 73 additions and 18 deletions
|
|
@ -90,11 +90,11 @@ pub struct KeyPattern {
|
|||
pub modifiers: KeyModifiers,
|
||||
/// The actual key, that was pressed
|
||||
#[serde(deserialize_with = "deserialize_Keysym")]
|
||||
pub key: u32,
|
||||
pub key: Option<u32>,
|
||||
}
|
||||
|
||||
impl KeyPattern {
|
||||
pub fn new(modifiers: impl Into<KeyModifiers>, key: u32) -> KeyPattern {
|
||||
pub fn new(modifiers: impl Into<KeyModifiers>, key: Option<u32>) -> KeyPattern {
|
||||
KeyPattern {
|
||||
modifiers: modifiers.into(),
|
||||
key,
|
||||
|
|
@ -117,7 +117,12 @@ impl ToString for KeyPattern {
|
|||
if self.modifiers.shift {
|
||||
result += "Shift+";
|
||||
}
|
||||
result += &keysym_get_name(self.key);
|
||||
|
||||
if let Some(key) = self.key {
|
||||
result += &keysym_get_name(key);
|
||||
} else {
|
||||
result.remove(result.len() - 1);
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
|
@ -176,7 +181,7 @@ fn insert_binding(
|
|||
for key in keys {
|
||||
let pattern = KeyPattern {
|
||||
modifiers: modifiers.clone(),
|
||||
key,
|
||||
key: Some(key),
|
||||
};
|
||||
if !key_bindings.contains_key(&pattern) {
|
||||
key_bindings.insert(pattern, action.clone());
|
||||
|
|
|
|||
|
|
@ -56,13 +56,18 @@ where
|
|||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn deserialize_Keysym<'de, D>(deserializer: D) -> Result<Keysym, D::Error>
|
||||
pub fn deserialize_Keysym<'de, D>(deserializer: D) -> Result<Option<Keysym>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
use serde::de::{Error, Unexpected};
|
||||
|
||||
let name = String::deserialize(deserializer)?;
|
||||
let name: Option<String> = Option::deserialize(deserializer)?;
|
||||
if name.is_none() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let name = name.unwrap();
|
||||
//let name = format!("KEY_{}", code);
|
||||
match xkb::keysym_from_name(&name, xkb::KEYSYM_NO_FLAGS) {
|
||||
KeySyms::KEY_NoSymbol => match xkb::keysym_from_name(&name, xkb::KEYSYM_CASE_INSENSITIVE) {
|
||||
|
|
@ -76,9 +81,9 @@ where
|
|||
name,
|
||||
xkb::keysym_get_name(x)
|
||||
);
|
||||
Ok(x)
|
||||
Ok(Some(x))
|
||||
}
|
||||
},
|
||||
x => Ok(x),
|
||||
x => Ok(Some(x)),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue