1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-27 15:37:29 +03:00

win32: add extended/enhanced key concept for win32 input mode

refs: https://github.com/wez/wezterm/issues/2009
refs: https://github.com/microsoft/terminal/issues/13134#issuecomment-1148000328
This commit is contained in:
Wez Furlong 2022-06-08 07:38:02 -07:00
parent a0e2a805d9
commit d85b7bf3b9
3 changed files with 26 additions and 12 deletions

View File

@ -232,22 +232,13 @@ impl InputMap {
pub fn is_leader(&self, key: &KeyCode, mods: Modifiers) -> Option<std::time::Duration> {
if let Some((leader_key, leader_mods, timeout)) = self.leader.as_ref() {
if *leader_key == *key && *leader_mods == Self::remove_positional_mods(mods) {
if *leader_key == *key && *leader_mods == mods.remove_positional_mods() {
return Some(timeout.clone());
}
}
None
}
fn remove_positional_mods(mods: Modifiers) -> Modifiers {
mods - (Modifiers::LEFT_ALT
| Modifiers::RIGHT_ALT
| Modifiers::LEFT_CTRL
| Modifiers::RIGHT_CTRL
| Modifiers::LEFT_SHIFT
| Modifiers::RIGHT_SHIFT)
}
pub fn has_table(&self, name: &str) -> bool {
self.keys.by_name.contains_key(name)
}
@ -264,13 +255,13 @@ impl InputMap {
};
table
.get(&key.normalize_shift(Self::remove_positional_mods(mods)))
.get(&key.normalize_shift(mods.remove_positional_mods()))
.cloned()
}
pub fn lookup_mouse(&self, event: MouseEventTrigger, mods: Modifiers) -> Option<KeyAssignment> {
self.mouse
.get(&(event, Self::remove_positional_mods(mods)))
.get(&(event, mods.remove_positional_mods()))
.cloned()
}
}

View File

@ -466,6 +466,7 @@ bitflags! {
const RIGHT_CTRL = 1<<9;
const LEFT_SHIFT = 1<<10;
const RIGHT_SHIFT = 1<<11;
const ENHANCED_KEY = 1<<12;
}
}
@ -524,6 +525,7 @@ impl ToString for Modifiers {
(Self::RIGHT_CTRL, "RIGHT_CTRL"),
(Self::LEFT_SHIFT, "LEFT_SHIFT"),
(Self::RIGHT_SHIFT, "RIGHT_SHIFT"),
(Self::ENHANCED_KEY, "ENHANCED_KEY"),
] {
if !self.contains(value) {
continue;
@ -538,6 +540,22 @@ impl ToString for Modifiers {
}
}
impl Modifiers {
/// Remove positional and other "supplemental" bits that
/// are used to carry around implementation details, but that
/// are not bits that should be matched when matching key
/// assignments.
pub fn remove_positional_mods(self) -> Self {
self - (Self::LEFT_ALT
| Self::RIGHT_ALT
| Self::LEFT_CTRL
| Self::RIGHT_CTRL
| Self::LEFT_SHIFT
| Self::RIGHT_SHIFT
| Self::ENHANCED_KEY)
}
}
/// These keycodes identify keys based on their physical
/// position on an ANSI-standard US keyboard.
#[derive(
@ -1169,6 +1187,7 @@ impl KeyEvent {
// defines the dwControlKeyState values
let mut control_key_state = 0;
const SHIFT_PRESSED: usize = 0x10;
const ENHANCED_KEY: usize = 0x100;
const RIGHT_ALT_PRESSED: usize = 0x01;
const LEFT_ALT_PRESSED: usize = 0x02;
const LEFT_CTRL_PRESSED: usize = 0x08;
@ -1194,6 +1213,9 @@ impl KeyEvent {
if self.modifiers.contains(Modifiers::LEFT_CTRL) {
control_key_state |= LEFT_CTRL_PRESSED;
}
if self.modifiers.contains(Modifiers::ENHANCED_KEY) {
control_key_state |= ENHANCED_KEY;
}
let key_down = if self.key_is_down { 1 } else { 0 };

View File

@ -2216,6 +2216,7 @@ unsafe fn key(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option<L
if keys[VK_RCONTROL as usize] & 0x80 != 0 {
modifiers |= Modifiers::RIGHT_CTRL;
}
modifiers.set(Modifiers::ENHANCED_KEY, is_extended);
if inner.keyboard_info.has_alt_gr()
&& (keys[VK_RMENU as usize] & 0x80 != 0)