mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 13:52:55 +03:00
input: key assignments now default to physical mappings
This commit adjusts the config parsing layer so that: ``` return { keys = { {key="a", ...} } } ``` is now treated as being implicitly the same as `key="phys:A"`. You can explicitly use `key="mapped:a"` to use the post-keyboard-map processed value of a key to trigger an assignment, rather than the physical key location. refs: #1483
This commit is contained in:
parent
83fbba0615
commit
29eb6dde23
@ -70,7 +70,13 @@ fn make_map() -> HashMap<String, KeyCode> {
|
||||
macro_rules! m {
|
||||
($($val:ident),* $(,)?) => {
|
||||
$(
|
||||
map.insert(stringify!($val).to_string(), KeyCode::$val);
|
||||
let v = KeyCode::$val;
|
||||
if let Some(phys) = v.to_phys() {
|
||||
map.insert(stringify!($val).to_string(), KeyCode::Physical(phys));
|
||||
map.insert(format!("mapped:{}", stringify!($val)), v);
|
||||
} else {
|
||||
map.insert(stringify!($val).to_string(), v);
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
@ -139,18 +145,36 @@ fn make_map() -> HashMap<String, KeyCode> {
|
||||
ApplicationDownArrow,
|
||||
);
|
||||
|
||||
map.insert("Backspace".to_string(), KeyCode::Char('\u{8}'));
|
||||
map.insert("Delete".to_string(), KeyCode::Char('\u{7f}'));
|
||||
map.insert("Enter".to_string(), KeyCode::Char('\r'));
|
||||
map.insert("Escape".to_string(), KeyCode::Char('\u{1b}'));
|
||||
map.insert("Tab".to_string(), KeyCode::Char('\t'));
|
||||
for (label, phys) in &[
|
||||
("Backspace", PhysKeyCode::Backspace),
|
||||
("Delete", PhysKeyCode::Delete),
|
||||
("Enter", PhysKeyCode::Return),
|
||||
("Escape", PhysKeyCode::Escape),
|
||||
("Tab", PhysKeyCode::Tab),
|
||||
] {
|
||||
map.insert(label.to_string(), KeyCode::Physical(*phys));
|
||||
map.insert(format!("mapped:{}", label), phys.to_key_code());
|
||||
}
|
||||
|
||||
for i in 0..=9 {
|
||||
map.insert(format!("Numpad{}", i), KeyCode::Numpad(i));
|
||||
let k = KeyCode::Numpad(i);
|
||||
map.insert(
|
||||
format!("Numpad{}", i),
|
||||
KeyCode::Physical(k.to_phys().unwrap()),
|
||||
);
|
||||
// Not sure how likely someone is to remap the numpad, but...
|
||||
map.insert(format!("mapped:Numpad{}", i), k);
|
||||
}
|
||||
|
||||
for i in 1..=24 {
|
||||
map.insert(format!("F{}", i), KeyCode::Function(i));
|
||||
let k = KeyCode::Function(i);
|
||||
if let Some(phys) = k.to_phys() {
|
||||
map.insert(format!("F{}", i), KeyCode::Physical(phys));
|
||||
map.insert(format!("mapped:F{}", i), k);
|
||||
} else {
|
||||
// 21 and up don't have phys equivalents
|
||||
map.insert(format!("F{}", i), k);
|
||||
}
|
||||
}
|
||||
|
||||
map
|
||||
@ -211,9 +235,26 @@ where
|
||||
return Ok(KeyCode::RawCode(num));
|
||||
}
|
||||
|
||||
if let Some(mapped) = s.strip_prefix("mapped:") {
|
||||
let chars: Vec<char> = mapped.chars().collect();
|
||||
return if chars.len() == 1 {
|
||||
Ok(KeyCode::Char(chars[0]))
|
||||
} else {
|
||||
Err(serde::de::Error::custom(format!(
|
||||
"invalid KeyCode string {}",
|
||||
s
|
||||
)))
|
||||
};
|
||||
}
|
||||
|
||||
let chars: Vec<char> = s.chars().collect();
|
||||
if chars.len() == 1 {
|
||||
Ok(KeyCode::Char(chars[0]))
|
||||
let k = KeyCode::Char(chars[0]);
|
||||
if let Some(phys) = k.to_phys() {
|
||||
Ok(KeyCode::Physical(phys))
|
||||
} else {
|
||||
Ok(k)
|
||||
}
|
||||
} else {
|
||||
Err(serde::de::Error::custom(format!(
|
||||
"invalid KeyCode string {}",
|
||||
|
Loading…
Reference in New Issue
Block a user