Align NamedKey and KeyCode more closely with the W3C specs (#4018)
By removing `NamedKey::Space` and rename "super" key to "meta".
- `NamedKey::Space` is not in the spec, and doesn't make sense to
special-case. We use `Key::Character("")` instead..
I've added an extra check on the Windows backend, to ensure that the code
functionally works the same before and after. Whether that check is
desirable or not can be figured out later.
- "super" is inconsistent with the W3C spec, and while it's arguably not the
best name, it's worse that Winit is diverging and choosing a different name.
List of renamings:
- `KeyCode::SuperLeft` -> `KeyCode::MetaLeft`
- `KeyCode::SuperRight` -> `KeyCode::MetaRight`
- `KeyCode::Meta` -> `KeyCode::Super`
- `NamedKey::Meta` -> `NamedKey::Super`
- `NamedKey::Super` -> `NamedKey::Meta`
- `ModifiersState::SUPER` -> `ModifiersState::META` (deprecated)
- `ModifiersState::super_key` -> `ModifiersState::meta_key`
- `ModifiersKeys::LSUPER` -> `ModifiersKeys::LMETA`
- `ModifiersKeys::RSUPER` -> `ModifiersKeys::RMETA`
This commit is contained in:
parent
7e13248be3
commit
cdbdd974fb
14 changed files with 118 additions and 97 deletions
|
|
@ -168,11 +168,11 @@ pub fn code_to_key(key: PhysicalKey, scancode: u16) -> Key {
|
|||
Key::Named(match code {
|
||||
KeyCode::Enter => NamedKey::Enter,
|
||||
KeyCode::Tab => NamedKey::Tab,
|
||||
KeyCode::Space => NamedKey::Space,
|
||||
KeyCode::Space => return Key::Character(" ".into()),
|
||||
KeyCode::Backspace => NamedKey::Backspace,
|
||||
KeyCode::Escape => NamedKey::Escape,
|
||||
KeyCode::SuperRight => NamedKey::Super,
|
||||
KeyCode::SuperLeft => NamedKey::Super,
|
||||
KeyCode::MetaRight => NamedKey::Meta,
|
||||
KeyCode::MetaLeft => NamedKey::Meta,
|
||||
KeyCode::ShiftLeft => NamedKey::Shift,
|
||||
KeyCode::AltLeft => NamedKey::Alt,
|
||||
KeyCode::ControlLeft => NamedKey::Control,
|
||||
|
|
@ -242,8 +242,8 @@ pub fn code_to_location(key: PhysicalKey) -> KeyLocation {
|
|||
};
|
||||
|
||||
match code {
|
||||
KeyCode::SuperRight => KeyLocation::Right,
|
||||
KeyCode::SuperLeft => KeyLocation::Left,
|
||||
KeyCode::MetaRight => KeyLocation::Right,
|
||||
KeyCode::MetaLeft => KeyLocation::Left,
|
||||
KeyCode::ShiftLeft => KeyLocation::Left,
|
||||
KeyCode::AltLeft => KeyLocation::Left,
|
||||
KeyCode::ControlLeft => KeyLocation::Left,
|
||||
|
|
@ -326,9 +326,9 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers {
|
|||
pressed_mods.set(ModifiersKeys::LALT, flags.contains(NX_DEVICELALTKEYMASK));
|
||||
pressed_mods.set(ModifiersKeys::RALT, flags.contains(NX_DEVICERALTKEYMASK));
|
||||
|
||||
state.set(ModifiersState::SUPER, flags.contains(NSEventModifierFlags::Command));
|
||||
pressed_mods.set(ModifiersKeys::LSUPER, flags.contains(NX_DEVICELCMDKEYMASK));
|
||||
pressed_mods.set(ModifiersKeys::RSUPER, flags.contains(NX_DEVICERCMDKEYMASK));
|
||||
state.set(ModifiersState::META, flags.contains(NSEventModifierFlags::Command));
|
||||
pressed_mods.set(ModifiersKeys::LMETA, flags.contains(NX_DEVICELCMDKEYMASK));
|
||||
pressed_mods.set(ModifiersKeys::RMETA, flags.contains(NX_DEVICERCMDKEYMASK));
|
||||
|
||||
Modifiers { state, pressed_mods }
|
||||
}
|
||||
|
|
@ -409,8 +409,8 @@ pub(crate) fn physicalkey_to_scancode(physical_key: PhysicalKey) -> Option<u32>
|
|||
KeyCode::Backquote => Some(0x32),
|
||||
KeyCode::Backspace => Some(0x33),
|
||||
KeyCode::Escape => Some(0x35),
|
||||
KeyCode::SuperRight => Some(0x36),
|
||||
KeyCode::SuperLeft => Some(0x37),
|
||||
KeyCode::MetaRight => Some(0x36),
|
||||
KeyCode::MetaLeft => Some(0x37),
|
||||
KeyCode::ShiftLeft => Some(0x38),
|
||||
KeyCode::CapsLock => Some(0x39),
|
||||
KeyCode::AltLeft => Some(0x3a),
|
||||
|
|
@ -555,8 +555,8 @@ pub(crate) fn scancode_to_physicalkey(scancode: u32) -> PhysicalKey {
|
|||
0x33 => KeyCode::Backspace,
|
||||
// 0x34 => unknown, // kVK_Powerbook_KeypadEnter
|
||||
0x35 => KeyCode::Escape,
|
||||
0x36 => KeyCode::SuperRight,
|
||||
0x37 => KeyCode::SuperLeft,
|
||||
0x36 => KeyCode::MetaRight,
|
||||
0x37 => KeyCode::MetaLeft,
|
||||
0x38 => KeyCode::ShiftLeft,
|
||||
0x39 => KeyCode::CapsLock,
|
||||
0x3a => KeyCode::AltLeft,
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ fn key_to_modifier(key: &Key) -> Option<ModifiersState> {
|
|||
match key {
|
||||
Key::Named(NamedKey::Alt) => Some(ModifiersState::ALT),
|
||||
Key::Named(NamedKey::Control) => Some(ModifiersState::CONTROL),
|
||||
Key::Named(NamedKey::Super) => Some(ModifiersState::SUPER),
|
||||
Key::Named(NamedKey::Meta) => Some(ModifiersState::META),
|
||||
Key::Named(NamedKey::Shift) => Some(ModifiersState::SHIFT),
|
||||
_ => None,
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ fn get_right_modifier_code(key: &Key) -> KeyCode {
|
|||
Key::Named(NamedKey::Alt) => KeyCode::AltRight,
|
||||
Key::Named(NamedKey::Control) => KeyCode::ControlRight,
|
||||
Key::Named(NamedKey::Shift) => KeyCode::ShiftRight,
|
||||
Key::Named(NamedKey::Super) => KeyCode::SuperRight,
|
||||
Key::Named(NamedKey::Meta) => KeyCode::MetaRight,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ fn get_left_modifier_code(key: &Key) -> KeyCode {
|
|||
Key::Named(NamedKey::Alt) => KeyCode::AltLeft,
|
||||
Key::Named(NamedKey::Control) => KeyCode::ControlLeft,
|
||||
Key::Named(NamedKey::Shift) => KeyCode::ShiftLeft,
|
||||
Key::Named(NamedKey::Super) => KeyCode::SuperLeft,
|
||||
Key::Named(NamedKey::Meta) => KeyCode::MetaLeft,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
@ -1103,7 +1103,7 @@ fn replace_event(event: &NSEvent, option_as_alt: OptionAsAlt) -> Retained<NSEven
|
|||
OptionAsAlt::Both if ev_mods.alt_key() => true,
|
||||
_ => false,
|
||||
} && !ev_mods.control_key()
|
||||
&& !ev_mods.super_key();
|
||||
&& !ev_mods.meta_key();
|
||||
|
||||
if ignore_alt_characters {
|
||||
let ns_chars = unsafe {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue