1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 15:04:36 +03:00

window/gui: remove raw/phys fallback fields from KeyEvent

Since we now have RawKeyEvent and a sane way to indicate handling,
we don't need these any more, and it simplifies key dispatch to
remove them.

refs: #1483
This commit is contained in:
Wez Furlong 2022-01-03 09:13:55 -07:00
parent 2616efa72e
commit 5f26746286
6 changed files with 6 additions and 125 deletions

View File

@ -290,57 +290,6 @@ impl super::TermWindow {
let modifiers = window_mods_to_termwiz_mods(window_key.modifiers);
// If we know the underlying raw code, let's first try any mappings
// defined for those.
if let Some(raw_code) = window_key.raw_code {
let raw_code_key = KeyCode::RawCode(raw_code);
if self.process_key(
&pane,
context,
&raw_code_key,
window_key.raw_modifiers,
leader_active,
leader_mod,
OnlyKeyBindings::Yes,
) {
return;
}
}
// Then, check for mappings using physical key location
if let Some(phys) = window_key.phys_code {
let phys_code_key = KeyCode::Physical(phys);
if self.process_key(
&pane,
context,
&phys_code_key,
window_key.raw_modifiers,
leader_active,
leader_mod,
OnlyKeyBindings::Yes,
) {
return;
}
}
// We may know the decoded platform key, but prior to any composition
// defined by the system (eg: prior to dead key expansion).
if let Some(key) = &window_key.raw_key {
if self.process_key(
&pane,
context,
key,
window_key.raw_modifiers,
leader_active,
leader_mod,
OnlyKeyBindings::Yes,
) {
return;
}
}
if self.process_key(
&pane,
context,

View File

@ -568,15 +568,6 @@ pub struct KeyEvent {
/// Which modifiers are down
pub modifiers: Modifiers,
/// The raw unprocessed key press if it was different from
/// the processed/composed version
pub raw_key: Option<KeyCode>,
pub raw_modifiers: Modifiers,
pub raw_code: Option<u32>,
/// The physical location of the key on an ANSI-Standard US layout
pub phys_code: Option<PhysKeyCode>,
/// How many times this key repeats
pub repeat_count: u16,
@ -619,12 +610,6 @@ impl KeyEvent {
self.key = key;
self.modifiers = modifiers;
if let Some(raw) = self.raw_key.take() {
let (key, modifiers) = normalize_shift(raw, self.raw_modifiers);
self.raw_key.replace(key);
self.raw_modifiers = modifiers;
}
self
}
@ -636,12 +621,6 @@ impl KeyEvent {
self.key = key;
self.modifiers = modifiers;
if let Some(raw) = self.raw_key.take() {
let (key, modifiers) = normalize_ctrl(raw, self.raw_modifiers);
self.raw_key.replace(key);
self.raw_modifiers = modifiers;
}
self
}
}

View File

@ -1415,11 +1415,7 @@ impl WindowView {
let event = KeyEvent {
key,
raw_key: None,
modifiers,
raw_modifiers: Modifiers::NONE,
raw_code: None,
phys_code: None,
repeat_count: 1,
key_is_down: true,
}
@ -1461,11 +1457,7 @@ impl WindowView {
let event = KeyEvent {
key,
raw_key: None,
modifiers: Modifiers::NONE,
raw_modifiers: Modifiers::NONE,
raw_code: None,
phys_code: None,
repeat_count: 1,
key_is_down,
}
@ -2034,11 +2026,7 @@ impl WindowView {
let mut event = KeyEvent {
key,
raw_key,
modifiers,
raw_modifiers,
raw_code: Some(virtual_key as u32),
phys_code,
repeat_count: 1,
key_is_down,
}

View File

@ -1298,10 +1298,6 @@ unsafe fn ime_composition(
Ok(s) => {
let key = KeyEvent {
key: KeyCode::Composed(s),
raw_key: None,
raw_modifiers: Modifiers::NONE,
raw_code: None,
phys_code: None,
modifiers: Modifiers::NONE,
repeat_count: 1,
key_is_down: true,
@ -1885,10 +1881,6 @@ unsafe fn key(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option<L
// dead key combination
let key = KeyEvent {
key: KeyCode::Char(c),
raw_key: None,
raw_modifiers: Modifiers::NONE,
raw_code: Some(wparam as u32),
phys_code,
modifiers,
repeat_count: 1,
key_is_down: !releasing,
@ -1988,34 +1980,15 @@ unsafe fn key(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option<L
};
if let Some(key) = key {
let is_composed = raw != Some(key.clone()) || modifiers != raw_modifiers;
// Urgh, special case for ctrl and non-latin layouts.
// FIXME: verify this behavior: Urgh, special case for ctrl and non-latin layouts.
// In order to avoid a situation like #678, if CTRL is the only
// modifier and we've got composed text, then discard the composed
// text.
let key = if is_composed && modifiers == Modifiers::CTRL && raw.is_some() {
KeyEvent {
key: raw.unwrap(),
raw_key: None,
raw_modifiers,
raw_code: Some(wparam as u32),
phys_code,
modifiers,
repeat_count: repeat,
key_is_down: !releasing,
}
} else {
KeyEvent {
key,
raw_key: if is_composed { raw } else { None },
raw_modifiers,
raw_code: Some(wparam as u32),
phys_code,
modifiers,
repeat_count: repeat,
key_is_down: !releasing,
}
let key = KeyEvent {
key,
modifiers,
repeat_count: repeat,
key_is_down: !releasing,
}
.normalize_shift();

View File

@ -249,10 +249,6 @@ impl Keyboard {
let event = KeyEvent {
key: kc,
modifiers: raw_modifiers,
raw_key: None,
raw_modifiers,
raw_code: Some(xcode),
phys_code,
repeat_count: 1,
key_is_down: pressed,
}

View File

@ -426,10 +426,6 @@ impl XWindowInner {
pub fn dispatch_ime_text(&mut self, text: &str) {
let key_event = KeyEvent {
key: KeyCode::Composed(text.into()),
raw_key: None,
raw_modifiers: Modifiers::NONE,
raw_code: None,
phys_code: None,
modifiers: Modifiers::NONE,
repeat_count: 1,
key_is_down: true,