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:
Mads Marquart 2025-03-23 12:56:01 +01:00 committed by GitHub
parent 7e13248be3
commit cdbdd974fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 118 additions and 97 deletions

View file

@ -1163,7 +1163,16 @@ fn modifiers_to_string(mods: ModifiersState) -> String {
let mut mods_line = String::new();
// Always add + since it's printed as a part of the bindings.
for (modifier, desc) in [
(ModifiersState::SUPER, "Super+"),
(
ModifiersState::META,
if cfg!(target_os = "windows") {
"Win+"
} else if cfg!(target_vendor = "apple") {
"Cmd+"
} else {
"Super+"
},
),
(ModifiersState::ALT, "Alt+"),
(ModifiersState::CONTROL, "Ctrl+"),
(ModifiersState::SHIFT, "Shift+"),
@ -1264,10 +1273,10 @@ const KEY_BINDINGS: &[Binding<&'static str>] = &[
Binding::new("Z", ModifiersState::CONTROL, Action::ToggleCursorVisibility),
// K.
Binding::new("K", ModifiersState::empty(), Action::SetTheme(None)),
Binding::new("K", ModifiersState::SUPER, Action::SetTheme(Some(Theme::Light))),
Binding::new("K", ModifiersState::META, Action::SetTheme(Some(Theme::Light))),
Binding::new("K", ModifiersState::CONTROL, Action::SetTheme(Some(Theme::Dark))),
#[cfg(macos_platform)]
Binding::new("T", ModifiersState::SUPER, Action::CreateNewTab),
Binding::new("T", ModifiersState::META, Action::CreateNewTab),
#[cfg(macos_platform)]
Binding::new("O", ModifiersState::CONTROL, Action::CycleOptionAsAlt),
Binding::new("S", ModifiersState::CONTROL, Action::Message),