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
|
|
@ -1,4 +1,5 @@
|
|||
//! Types related to the keyboard.
|
||||
#![cfg_attr(feature = "serde", allow(deprecated))] // https://github.com/serde-rs/serde/issues/2195
|
||||
|
||||
// This file contains a substantial portion of the UI Events Specification by the W3C. In
|
||||
// particular, the variant names within `Key` and `KeyCode` and their documentation are modified
|
||||
|
|
@ -283,11 +284,7 @@ impl PartialEq<PhysicalKey> for NativeKeyCode {
|
|||
|
||||
/// Code representing the location of a physical key
|
||||
///
|
||||
/// This mostly conforms to the UI Events Specification's [`KeyboardEvent.code`] with a few
|
||||
/// exceptions:
|
||||
/// - The keys that the specification calls "MetaLeft" and "MetaRight" are named "SuperLeft" and
|
||||
/// "SuperRight" here.
|
||||
/// - The key that the specification calls "Super" is reported as `Unidentified` here.
|
||||
/// This conforms to the UI Events Specification's [`KeyboardEvent.code`].
|
||||
///
|
||||
/// [`KeyboardEvent.code`]: https://w3c.github.io/uievents-code/#code-value-tables
|
||||
#[non_exhaustive]
|
||||
|
|
@ -420,7 +417,7 @@ pub enum KeyCode {
|
|||
/// <kbd>CapsLock</kbd> or <kbd>⇪</kbd>
|
||||
CapsLock,
|
||||
/// The application context menu key, which is typically found between the right
|
||||
/// <kbd>Super</kbd> key and the right <kbd>Control</kbd> key.
|
||||
/// <kbd>Meta</kbd> key and the right <kbd>Control</kbd> key.
|
||||
ContextMenu,
|
||||
/// <kbd>Control</kbd> or <kbd>⌃</kbd>
|
||||
ControlLeft,
|
||||
|
|
@ -429,9 +426,9 @@ pub enum KeyCode {
|
|||
/// <kbd>Enter</kbd> or <kbd>↵</kbd>. Labeled <kbd>Return</kbd> on Apple keyboards.
|
||||
Enter,
|
||||
/// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd>, or other OS symbol key.
|
||||
SuperLeft,
|
||||
MetaLeft,
|
||||
/// The Windows, <kbd>⌘</kbd>, <kbd>Command</kbd>, or other OS symbol key.
|
||||
SuperRight,
|
||||
MetaRight,
|
||||
/// <kbd>Shift</kbd> or <kbd>⇧</kbd>
|
||||
ShiftLeft,
|
||||
/// <kbd>Shift</kbd> or <kbd>⇧</kbd>
|
||||
|
|
@ -613,9 +610,11 @@ pub enum KeyCode {
|
|||
AudioVolumeMute,
|
||||
AudioVolumeUp,
|
||||
WakeUp,
|
||||
// Legacy modifier key. Also called "Super" in certain places.
|
||||
Meta,
|
||||
// Legacy modifier key.
|
||||
#[deprecated = "marked as legacy in the spec, use Meta instead"]
|
||||
Super,
|
||||
// Legacy modifier key.
|
||||
#[deprecated = "marked as legacy in the spec, use Meta instead"]
|
||||
Hyper,
|
||||
Turbo,
|
||||
Abort,
|
||||
|
|
@ -741,12 +740,7 @@ pub enum KeyCode {
|
|||
|
||||
/// A [`Key::Named`] value
|
||||
///
|
||||
/// This mostly conforms to the UI Events Specification's [`KeyboardEvent.key`] with a few
|
||||
/// exceptions:
|
||||
/// - The `Super` variant here, is named `Meta` in the aforementioned specification. (There's
|
||||
/// another key which the specification calls `Super`. That does not exist here.)
|
||||
/// - The `Space` variant here, can be identified by the character it generates in the
|
||||
/// specification.
|
||||
/// This conforms to the UI Events Specification's [`KeyboardEvent.key`].
|
||||
///
|
||||
/// [`KeyboardEvent.key`]: https://w3c.github.io/uievents-key/
|
||||
#[non_exhaustive]
|
||||
|
|
@ -791,24 +785,22 @@ pub enum NamedKey {
|
|||
/// The Symbol modifier key (used on some virtual keyboards).
|
||||
Symbol,
|
||||
SymbolLock,
|
||||
// Legacy modifier key. Also called "Super" in certain places.
|
||||
Meta,
|
||||
// Legacy modifier key.
|
||||
#[deprecated = "marked as legacy in the spec, use Meta instead"]
|
||||
Super,
|
||||
// Legacy modifier key.
|
||||
#[deprecated = "marked as legacy in the spec, use Meta instead"]
|
||||
Hyper,
|
||||
/// Used to enable "super" modifier function for interpreting concurrent or subsequent keyboard
|
||||
/// Used to enable "meta" modifier function for interpreting concurrent or subsequent keyboard
|
||||
/// input. This key value is used for the "Windows Logo" key and the Apple `Command` or `⌘`
|
||||
/// key.
|
||||
///
|
||||
/// Note: In some contexts (e.g. the Web) this is referred to as the "Meta" key.
|
||||
Super,
|
||||
Meta,
|
||||
/// The `Enter` or `↵` key. Used to activate current selection or accept current input. This
|
||||
/// key value is also used for the `Return` (Macintosh numpad) key. This key value is also
|
||||
/// used for the Android `KEYCODE_DPAD_CENTER`.
|
||||
Enter,
|
||||
/// The Horizontal Tabulation `Tab` key.
|
||||
Tab,
|
||||
/// Used in text to insert a space between words. Usually located below the character keys.
|
||||
Space,
|
||||
/// Navigate or traverse downward. (`KEYCODE_DPAD_DOWN`)
|
||||
ArrowDown,
|
||||
/// Navigate or traverse leftward. (`KEYCODE_DPAD_LEFT`)
|
||||
|
|
@ -864,7 +856,7 @@ pub enum NamedKey {
|
|||
Attn,
|
||||
Cancel,
|
||||
/// Show the application’s context menu.
|
||||
/// This key is commonly found between the right `Super` key and the right `Control` key.
|
||||
/// This key is commonly found between the right `Meta` key and the right `Control` key.
|
||||
ContextMenu,
|
||||
/// The `Esc` key. This key was originally used to initiate an escape sequence, but is
|
||||
/// now more generally used to exit or "escape" the current context, such as closing a dialog
|
||||
|
|
@ -1583,7 +1575,6 @@ impl NamedKey {
|
|||
NamedKey::Enter => Some("\r"),
|
||||
NamedKey::Backspace => Some("\x08"),
|
||||
NamedKey::Tab => Some("\t"),
|
||||
NamedKey::Space => Some(" "),
|
||||
NamedKey::Escape => Some("\x1b"),
|
||||
_ => None,
|
||||
}
|
||||
|
|
@ -1709,7 +1700,9 @@ bitflags! {
|
|||
/// The "alt" key.
|
||||
const ALT = 0b100 << 6;
|
||||
/// This is the "windows" key on PC and "command" key on Mac.
|
||||
const SUPER = 0b100 << 9;
|
||||
const META = 0b100 << 9;
|
||||
#[deprecated = "use META instead"]
|
||||
const SUPER = Self::META.bits();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1729,9 +1722,9 @@ impl ModifiersState {
|
|||
self.intersects(Self::ALT)
|
||||
}
|
||||
|
||||
/// Returns `true` if the super key is pressed.
|
||||
pub fn super_key(&self) -> bool {
|
||||
self.intersects(Self::SUPER)
|
||||
/// Returns `true` if the meta key is pressed.
|
||||
pub fn meta_key(&self) -> bool {
|
||||
self.intersects(Self::META)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1764,7 +1757,11 @@ bitflags! {
|
|||
const RCONTROL = 0b0000_1000;
|
||||
const LALT = 0b0001_0000;
|
||||
const RALT = 0b0010_0000;
|
||||
const LSUPER = 0b0100_0000;
|
||||
const RSUPER = 0b1000_0000;
|
||||
const LMETA = 0b0100_0000;
|
||||
const RMETA = 0b1000_0000;
|
||||
#[deprecated = "use LMETA instead"]
|
||||
const LSUPER = Self::LMETA.bits();
|
||||
#[deprecated = "use RMETA instead"]
|
||||
const RSUPER = Self::RMETA.bits();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue