From be52984ec2375065e85f8f8ab9cd719910c0d9c3 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 1 Dec 2024 16:05:14 +0100 Subject: [PATCH 1/2] Remove NamedKey::Space This is not in the W3C spec, and doesn't make sense to special-case. --- src/changelog/unreleased.md | 1 + src/keyboard.rs | 5 ----- src/platform_impl/android/keycodes.rs | 2 +- src/platform_impl/apple/appkit/event.rs | 2 +- src/platform_impl/linux/common/xkb/keymap.rs | 2 +- src/platform_impl/orbital/event_loop.rs | 2 +- src/platform_impl/web/keyboard.rs | 1 - src/platform_impl/web/web_sys/event.rs | 1 - src/platform_impl/windows/keyboard_layout.rs | 2 +- 9 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 4c8616e158..6ed24cc085 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -193,6 +193,7 @@ changelog entry. `ButtonSource` as part of the new pointer event overhaul. - Remove `Force::altitude_angle`. - Removed `Window::inner_position`, use the new `Window::surface_position` instead. +- Removed `NamedKey::Space`, match on `Key::Character(" ")` instead. ### Fixed diff --git a/src/keyboard.rs b/src/keyboard.rs index da501b2dfc..ee0edb27d4 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -745,8 +745,6 @@ pub enum KeyCode { /// 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. /// /// [`KeyboardEvent.key`]: https://w3c.github.io/uievents-key/ #[non_exhaustive] @@ -807,8 +805,6 @@ pub enum NamedKey { 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`) @@ -1583,7 +1579,6 @@ impl NamedKey { NamedKey::Enter => Some("\r"), NamedKey::Backspace => Some("\x08"), NamedKey::Tab => Some("\t"), - NamedKey::Space => Some(" "), NamedKey::Escape => Some("\x1b"), _ => None, } diff --git a/src/platform_impl/android/keycodes.rs b/src/platform_impl/android/keycodes.rs index 207d549f3d..e65d5424cc 100644 --- a/src/platform_impl/android/keycodes.rs +++ b/src/platform_impl/android/keycodes.rs @@ -309,7 +309,7 @@ pub fn to_logical(key_char: Option, keycode: Keycode) -> Key { ShiftLeft => Key::Named(NamedKey::Shift), ShiftRight => Key::Named(NamedKey::Shift), Tab => Key::Named(NamedKey::Tab), - Space => Key::Named(NamedKey::Space), + Space => Key::Character(" ".into()), Sym => Key::Named(NamedKey::Symbol), Explorer => Key::Named(NamedKey::LaunchWebBrowser), Envelope => Key::Named(NamedKey::LaunchMail), diff --git a/src/platform_impl/apple/appkit/event.rs b/src/platform_impl/apple/appkit/event.rs index f71111b67f..f6eb3212b4 100644 --- a/src/platform_impl/apple/appkit/event.rs +++ b/src/platform_impl/apple/appkit/event.rs @@ -185,7 +185,7 @@ 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, diff --git a/src/platform_impl/linux/common/xkb/keymap.rs b/src/platform_impl/linux/common/xkb/keymap.rs index d9ac1838ef..0b42c502e4 100644 --- a/src/platform_impl/linux/common/xkb/keymap.rs +++ b/src/platform_impl/linux/common/xkb/keymap.rs @@ -724,7 +724,7 @@ pub fn keysym_to_key(keysym: u32) -> Key { keysyms::_3270_PrintScreen => NamedKey::PrintScreen, keysyms::_3270_Enter => NamedKey::Enter, - keysyms::space => NamedKey::Space, + keysyms::space => return Key::Character(" ".into()), // exclam..Sinh_kunddaliya // XFree86 diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 1b9cc6042c..c5f4bbfb2d 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -121,7 +121,7 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_RIGHT_SHIFT => (KeyCode::ShiftRight, Some(NamedKey::Shift)), orbclient::K_SEMICOLON => (KeyCode::Semicolon, None), orbclient::K_SLASH => (KeyCode::Slash, None), - orbclient::K_SPACE => (KeyCode::Space, Some(NamedKey::Space)), + orbclient::K_SPACE => (KeyCode::Space, None), orbclient::K_SUPER => (KeyCode::SuperLeft, Some(NamedKey::Super)), orbclient::K_TAB => (KeyCode::Tab, Some(NamedKey::Tab)), orbclient::K_TICK => (KeyCode::Backquote, None), diff --git a/src/platform_impl/web/keyboard.rs b/src/platform_impl/web/keyboard.rs index 6f8d69c760..c660639985 100644 --- a/src/platform_impl/web/keyboard.rs +++ b/src/platform_impl/web/keyboard.rs @@ -25,7 +25,6 @@ impl Key { "Meta" => NamedKey::Super, "Enter" => NamedKey::Enter, "Tab" => NamedKey::Tab, - " " => NamedKey::Space, "ArrowDown" => NamedKey::ArrowDown, "ArrowLeft" => NamedKey::ArrowLeft, "ArrowRight" => NamedKey::ArrowRight, diff --git a/src/platform_impl/web/web_sys/event.rs b/src/platform_impl/web/web_sys/event.rs index ed7f03ba8a..551e40a459 100644 --- a/src/platform_impl/web/web_sys/event.rs +++ b/src/platform_impl/web/web_sys/event.rs @@ -184,7 +184,6 @@ pub fn key_text(event: &KeyboardEvent) -> Option { Key::Character(text) => Some(text.clone()), Key::Named(NamedKey::Tab) => Some(SmolStr::new("\t")), Key::Named(NamedKey::Enter) => Some(SmolStr::new("\r")), - Key::Named(NamedKey::Space) => Some(SmolStr::new(" ")), _ => None, } .map(SmolStr::new) diff --git a/src/platform_impl/windows/keyboard_layout.rs b/src/platform_impl/windows/keyboard_layout.rs index a518886030..1ab0d2a68e 100644 --- a/src/platform_impl/windows/keyboard_layout.rs +++ b/src/platform_impl/windows/keyboard_layout.rs @@ -787,7 +787,7 @@ fn vkey_to_non_char_key( VK_NONCONVERT => Key::Named(NamedKey::NonConvert), VK_ACCEPT => Key::Named(NamedKey::Accept), VK_MODECHANGE => Key::Named(NamedKey::ModeChange), - VK_SPACE => Key::Named(NamedKey::Space), + VK_SPACE => Key::Character(" ".into()), VK_PRIOR => Key::Named(NamedKey::PageUp), VK_NEXT => Key::Named(NamedKey::PageDown), VK_END => Key::Named(NamedKey::End), From 6d46d5228b2ca4029b855114c67e36d41c0ecf9d Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 1 Dec 2024 16:04:35 +0100 Subject: [PATCH 2/2] Rename "super" key to "meta" This 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. --- Full list of changes: KeyCode: - SuperLeft -> MetaLeft - SuperRight -> MetaRight - Meta -> Super NamedKey::Meta is swapped with NamedKey::Super. ModifiersState::SUPER is renamed to ModifiersState::META. ModifiersState::super_key is renamed to ModifiersState::meta_key. ModifiersKeys::LSUPER and RSUPER are renamed to LMETA and RMETA. --- examples/window.rs | 6 +-- src/changelog/unreleased.md | 1 + src/event.rs | 4 +- src/keyboard.rs | 45 ++++++++------------ src/platform_impl/android/keycodes.rs | 8 ++-- src/platform_impl/apple/appkit/event.rs | 22 +++++----- src/platform_impl/apple/appkit/view.rs | 8 ++-- src/platform_impl/linux/common/xkb/keymap.rs | 20 +++++---- src/platform_impl/linux/common/xkb/state.rs | 2 +- src/platform_impl/orbital/event_loop.rs | 18 ++++---- src/platform_impl/web/keyboard.rs | 8 ++-- src/platform_impl/web/web_sys/event.rs | 4 +- src/platform_impl/windows/keyboard.rs | 8 ++-- src/platform_impl/windows/keyboard_layout.rs | 10 ++--- 14 files changed, 80 insertions(+), 84 deletions(-) diff --git a/examples/window.rs b/examples/window.rs index 3d87e2f8d9..17c97e83ae 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -1125,7 +1125,7 @@ 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, "Meta+"), (ModifiersState::ALT, "Alt+"), (ModifiersState::CONTROL, "Ctrl+"), (ModifiersState::SHIFT, "Shift+"), @@ -1224,10 +1224,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), diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 6ed24cc085..fe110765d2 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -161,6 +161,7 @@ changelog entry. - In the same spirit rename `DeviceEvent::MouseMotion` to `PointerMotion`. - Remove `Force::Calibrated::altitude_angle`. - On X11, use bottom-right corner for IME hotspot in `Window::set_ime_cursor_area`. +- Renamed "super" key to "meta", to match the naming in the W3C specification. ### Removed diff --git a/src/event.rs b/src/event.rs index 94ed8a2584..6f702c8dea 100644 --- a/src/event.rs +++ b/src/event.rs @@ -910,12 +910,12 @@ impl Modifiers { /// The state of the left super key. pub fn lsuper_state(&self) -> ModifiersKeyState { - self.mod_state(ModifiersKeys::LSUPER) + self.mod_state(ModifiersKeys::LMETA) } /// The state of the right super key. pub fn rsuper_state(&self) -> ModifiersKeyState { - self.mod_state(ModifiersKeys::RSUPER) + self.mod_state(ModifiersKeys::RMETA) } fn mod_state(&self, modifier: ModifiersKeys) -> ModifiersKeyState { diff --git a/src/keyboard.rs b/src/keyboard.rs index ee0edb27d4..861d86b1a6 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -283,11 +283,7 @@ impl PartialEq 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 +416,7 @@ pub enum KeyCode { /// CapsLock or CapsLock, /// The application context menu key, which is typically found between the right - /// Super key and the right Control key. + /// Meta key and the right Control key. ContextMenu, /// Control or ControlLeft, @@ -429,9 +425,9 @@ pub enum KeyCode { /// Enter or . Labeled Return on Apple keyboards. Enter, /// The Windows, , Command, or other OS symbol key. - SuperLeft, + MetaLeft, /// The Windows, , Command, or other OS symbol key. - SuperRight, + MetaRight, /// Shift or ShiftLeft, /// Shift or @@ -613,8 +609,8 @@ pub enum KeyCode { AudioVolumeMute, AudioVolumeUp, WakeUp, - // Legacy modifier key. Also called "Super" in certain places. - Meta, + // Legacy modifier key. + Super, // Legacy modifier key. Hyper, Turbo, @@ -741,10 +737,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.) +/// This conforms to the UI Events Specification's [`KeyboardEvent.key`]. /// /// [`KeyboardEvent.key`]: https://w3c.github.io/uievents-key/ #[non_exhaustive] @@ -789,16 +782,14 @@ 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. + Super, // Legacy modifier key. 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`. @@ -860,7 +851,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 @@ -1704,7 +1695,7 @@ 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; } } @@ -1724,9 +1715,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) } } @@ -1759,7 +1750,7 @@ 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; } } diff --git a/src/platform_impl/android/keycodes.rs b/src/platform_impl/android/keycodes.rs index e65d5424cc..e1f77fe00e 100644 --- a/src/platform_impl/android/keycodes.rs +++ b/src/platform_impl/android/keycodes.rs @@ -143,8 +143,8 @@ pub fn to_physical_key(keycode: Keycode) -> PhysicalKey { Keycode::AltLeft => KeyCode::AltLeft, Keycode::AltRight => KeyCode::AltRight, - Keycode::MetaLeft => KeyCode::SuperLeft, - Keycode::MetaRight => KeyCode::SuperRight, + Keycode::MetaLeft => KeyCode::MetaLeft, + Keycode::MetaRight => KeyCode::MetaRight, Keycode::LeftBracket => KeyCode::BracketLeft, Keycode::RightBracket => KeyCode::BracketRight, @@ -340,8 +340,8 @@ pub fn to_logical(key_char: Option, keycode: Keycode) -> Key { CtrlRight => Key::Named(NamedKey::Control), CapsLock => Key::Named(NamedKey::CapsLock), ScrollLock => Key::Named(NamedKey::ScrollLock), - MetaLeft => Key::Named(NamedKey::Super), - MetaRight => Key::Named(NamedKey::Super), + MetaLeft => Key::Named(NamedKey::Meta), + MetaRight => Key::Named(NamedKey::Meta), Function => Key::Named(NamedKey::Fn), Sysrq => Key::Named(NamedKey::PrintScreen), Break => Key::Named(NamedKey::Pause), diff --git a/src/platform_impl/apple/appkit/event.rs b/src/platform_impl/apple/appkit/event.rs index f6eb3212b4..51a0425aa0 100644 --- a/src/platform_impl/apple/appkit/event.rs +++ b/src/platform_impl/apple/appkit/event.rs @@ -188,8 +188,8 @@ pub fn code_to_key(key: PhysicalKey, scancode: u16) -> Key { 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, @@ -246,8 +246,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, @@ -335,11 +335,11 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers { pressed_mods.set(ModifiersKeys::RALT, flags.contains(NX_DEVICERALTKEYMASK)); state.set( - ModifiersState::SUPER, + ModifiersState::META, flags.contains(NSEventModifierFlags::NSEventModifierFlagCommand), ); - pressed_mods.set(ModifiersKeys::LSUPER, flags.contains(NX_DEVICELCMDKEYMASK)); - pressed_mods.set(ModifiersKeys::RSUPER, flags.contains(NX_DEVICERCMDKEYMASK)); + pressed_mods.set(ModifiersKeys::LMETA, flags.contains(NX_DEVICELCMDKEYMASK)); + pressed_mods.set(ModifiersKeys::RMETA, flags.contains(NX_DEVICERCMDKEYMASK)); Modifiers { state, pressed_mods } } @@ -419,8 +419,8 @@ pub(crate) fn physicalkey_to_scancode(physical_key: PhysicalKey) -> Option 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::AltLeft => Some(0x3a), KeyCode::ControlLeft => Some(0x3b), @@ -538,8 +538,8 @@ pub(crate) fn scancode_to_physicalkey(scancode: u32) -> PhysicalKey { 0x33 => KeyCode::Backspace, // 0x34 => unknown, 0x35 => KeyCode::Escape, - 0x36 => KeyCode::SuperRight, - 0x37 => KeyCode::SuperLeft, + 0x36 => KeyCode::MetaRight, + 0x37 => KeyCode::MetaLeft, 0x38 => KeyCode::ShiftLeft, 0x39 => KeyCode::CapsLock, 0x3a => KeyCode::AltLeft, diff --git a/src/platform_impl/apple/appkit/view.rs b/src/platform_impl/apple/appkit/view.rs index e8bdffa809..9198e6519d 100644 --- a/src/platform_impl/apple/appkit/view.rs +++ b/src/platform_impl/apple/appkit/view.rs @@ -82,7 +82,7 @@ fn key_to_modifier(key: &Key) -> Option { 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, } @@ -93,7 +93,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!(), } } @@ -103,7 +103,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!(), } } @@ -1132,7 +1132,7 @@ fn replace_event(event: &NSEvent, option_as_alt: OptionAsAlt) -> Retained true, _ => false, } && !ev_mods.control_key() - && !ev_mods.super_key(); + && !ev_mods.meta_key(); if ignore_alt_characters { let ns_chars = unsafe { diff --git a/src/platform_impl/linux/common/xkb/keymap.rs b/src/platform_impl/linux/common/xkb/keymap.rs index 0b42c502e4..5c3df70cf8 100644 --- a/src/platform_impl/linux/common/xkb/keymap.rs +++ b/src/platform_impl/linux/common/xkb/keymap.rs @@ -166,8 +166,8 @@ pub fn scancode_to_physicalkey(scancode: u32) -> PhysicalKey { 122 => KeyCode::Lang1, 123 => KeyCode::Lang2, 124 => KeyCode::IntlYen, - 125 => KeyCode::SuperLeft, - 126 => KeyCode::SuperRight, + 125 => KeyCode::MetaLeft, + 126 => KeyCode::MetaRight, 127 => KeyCode::ContextMenu, 128 => KeyCode::BrowserStop, 129 => KeyCode::Again, @@ -419,8 +419,8 @@ pub fn physicalkey_to_scancode(key: PhysicalKey) -> Option { KeyCode::Lang1 => Some(122), KeyCode::Lang2 => Some(123), KeyCode::IntlYen => Some(124), - KeyCode::SuperLeft => Some(125), - KeyCode::SuperRight => Some(126), + KeyCode::MetaLeft => Some(125), + KeyCode::MetaRight => Some(126), KeyCode::ContextMenu => Some(127), KeyCode::BrowserStop => Some(128), KeyCode::Again => Some(129), @@ -622,16 +622,18 @@ pub fn keysym_to_key(keysym: u32) -> Key { keysyms::Control_R => NamedKey::Control, keysyms::Caps_Lock => NamedKey::CapsLock, // keysyms::Shift_Lock => NamedKey::ShiftLock, - - // keysyms::Meta_L => NamedKey::Meta, - // keysyms::Meta_R => NamedKey::Meta, keysyms::Alt_L => NamedKey::Alt, keysyms::Alt_R => NamedKey::Alt, - keysyms::Super_L => NamedKey::Super, - keysyms::Super_R => NamedKey::Super, keysyms::Hyper_L => NamedKey::Hyper, keysyms::Hyper_R => NamedKey::Hyper, + // Browsers map X11's Super keys to Meta, so we do that as well. + keysyms::Super_L => NamedKey::Meta, + keysyms::Super_R => NamedKey::Meta, + // The actual Meta keys do not seem to be used by browsers, so we don't do that either. + // keysyms::Meta_L => NamedKey::Meta, + // keysyms::Meta_R => NamedKey::Meta, + // XKB function and modifier keys // keysyms::ISO_Lock => NamedKey::IsoLock, // keysyms::ISO_Level2_Latch => NamedKey::IsoLevel2Latch, diff --git a/src/platform_impl/linux/common/xkb/state.rs b/src/platform_impl/linux/common/xkb/state.rs index 27c055aa20..31bcec8b3f 100644 --- a/src/platform_impl/linux/common/xkb/state.rs +++ b/src/platform_impl/linux/common/xkb/state.rs @@ -183,7 +183,7 @@ impl From for crate::keyboard::ModifiersState { to_mods.set(crate::keyboard::ModifiersState::SHIFT, mods.shift); to_mods.set(crate::keyboard::ModifiersState::CONTROL, mods.ctrl); to_mods.set(crate::keyboard::ModifiersState::ALT, mods.alt); - to_mods.set(crate::keyboard::ModifiersState::SUPER, mods.logo); + to_mods.set(crate::keyboard::ModifiersState::META, mods.logo); to_mods } } diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index c5f4bbfb2d..fec80246b6 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -122,7 +122,7 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_SEMICOLON => (KeyCode::Semicolon, None), orbclient::K_SLASH => (KeyCode::Slash, None), orbclient::K_SPACE => (KeyCode::Space, None), - orbclient::K_SUPER => (KeyCode::SuperLeft, Some(NamedKey::Super)), + orbclient::K_SUPER => (KeyCode::MetaLeft, Some(NamedKey::Meta)), orbclient::K_TAB => (KeyCode::Tab, Some(NamedKey::Tab)), orbclient::K_TICK => (KeyCode::Backquote, None), orbclient::K_UP => (KeyCode::ArrowUp, Some(NamedKey::ArrowUp)), @@ -152,8 +152,8 @@ bitflags! { const RCTRL = 1 << 3; const LALT = 1 << 4; const RALT = 1 << 5; - const LSUPER = 1 << 6; - const RSUPER = 1 << 7; + const LMETA = 1 << 6; + const RMETA = 1 << 7; } } @@ -203,8 +203,8 @@ impl EventState { KeyCode::ControlRight => self.keyboard.set(KeyboardModifierState::RCTRL, pressed), KeyCode::AltLeft => self.keyboard.set(KeyboardModifierState::LALT, pressed), KeyCode::AltRight => self.keyboard.set(KeyboardModifierState::RALT, pressed), - KeyCode::SuperLeft => self.keyboard.set(KeyboardModifierState::LSUPER, pressed), - KeyCode::SuperRight => self.keyboard.set(KeyboardModifierState::RSUPER, pressed), + KeyCode::MetaLeft => self.keyboard.set(KeyboardModifierState::LMETA, pressed), + KeyCode::MetaRight => self.keyboard.set(KeyboardModifierState::RMETA, pressed), _ => (), } } @@ -262,14 +262,14 @@ impl EventState { pressed_mods.set(ModifiersKeys::LALT, self.keyboard.contains(KeyboardModifierState::LALT)); pressed_mods.set(ModifiersKeys::RALT, self.keyboard.contains(KeyboardModifierState::RALT)); - if self.keyboard.intersects(KeyboardModifierState::LSUPER | KeyboardModifierState::RSUPER) { - state |= ModifiersState::SUPER + if self.keyboard.intersects(KeyboardModifierState::LMETA | KeyboardModifierState::RMETA) { + state |= ModifiersState::META } pressed_mods - .set(ModifiersKeys::LSUPER, self.keyboard.contains(KeyboardModifierState::LSUPER)); + .set(ModifiersKeys::LMETA, self.keyboard.contains(KeyboardModifierState::LMETA)); pressed_mods - .set(ModifiersKeys::RSUPER, self.keyboard.contains(KeyboardModifierState::RSUPER)); + .set(ModifiersKeys::RMETA, self.keyboard.contains(KeyboardModifierState::RMETA)); Modifiers { state, pressed_mods } } diff --git a/src/platform_impl/web/keyboard.rs b/src/platform_impl/web/keyboard.rs index c660639985..d0484ef54f 100644 --- a/src/platform_impl/web/keyboard.rs +++ b/src/platform_impl/web/keyboard.rs @@ -21,8 +21,9 @@ impl Key { "Shift" => NamedKey::Shift, "Symbol" => NamedKey::Symbol, "SymbolLock" => NamedKey::SymbolLock, + "Super" => NamedKey::Super, "Hyper" => NamedKey::Hyper, - "Meta" => NamedKey::Super, + "Meta" => NamedKey::Meta, "Enter" => NamedKey::Enter, "Tab" => NamedKey::Tab, "ArrowDown" => NamedKey::ArrowDown, @@ -380,8 +381,8 @@ impl PhysicalKey { "ControlLeft" => KeyCode::ControlLeft, "ControlRight" => KeyCode::ControlRight, "Enter" => KeyCode::Enter, - "MetaLeft" => KeyCode::SuperLeft, - "MetaRight" => KeyCode::SuperRight, + "MetaLeft" => KeyCode::MetaLeft, + "MetaRight" => KeyCode::MetaRight, "ShiftLeft" => KeyCode::ShiftLeft, "ShiftRight" => KeyCode::ShiftRight, "Space" => KeyCode::Space, @@ -464,6 +465,7 @@ impl PhysicalKey { "AudioVolumeMute" => KeyCode::AudioVolumeMute, "AudioVolumeUp" => KeyCode::AudioVolumeUp, "WakeUp" => KeyCode::WakeUp, + "Super" => KeyCode::Super, "Hyper" => KeyCode::Hyper, "Turbo" => KeyCode::Turbo, "Abort" => KeyCode::Abort, diff --git a/src/platform_impl/web/web_sys/event.rs b/src/platform_impl/web/web_sys/event.rs index 551e40a459..dbecbf395e 100644 --- a/src/platform_impl/web/web_sys/event.rs +++ b/src/platform_impl/web/web_sys/event.rs @@ -215,7 +215,7 @@ pub fn keyboard_modifiers(event: &KeyboardEvent) -> ModifiersState { state |= ModifiersState::ALT; } if event.meta_key() { - state |= ModifiersState::SUPER; + state |= ModifiersState::META; } state @@ -234,7 +234,7 @@ pub fn mouse_modifiers(event: &MouseEvent) -> ModifiersState { state |= ModifiersState::ALT; } if event.meta_key() { - state |= ModifiersState::SUPER; + state |= ModifiersState::META; } state diff --git a/src/platform_impl/windows/keyboard.rs b/src/platform_impl/windows/keyboard.rs index d360a1d363..24418f4f57 100644 --- a/src/platform_impl/windows/keyboard.rs +++ b/src/platform_impl/windows/keyboard.rs @@ -978,8 +978,8 @@ pub(crate) fn physicalkey_to_scancode(physical_key: PhysicalKey) -> Option KeyCode::ControlLeft => Some(0x001d), KeyCode::ControlRight => Some(0xe01d), KeyCode::Enter => Some(0x001c), - KeyCode::SuperLeft => Some(0xe05b), - KeyCode::SuperRight => Some(0xe05c), + KeyCode::MetaLeft => Some(0xe05b), + KeyCode::MetaRight => Some(0xe05c), KeyCode::ShiftLeft => Some(0x002a), KeyCode::ShiftRight => Some(0x0036), KeyCode::Space => Some(0x0039), @@ -1147,8 +1147,8 @@ pub(crate) fn scancode_to_physicalkey(scancode: u32) -> PhysicalKey { 0x001d => KeyCode::ControlLeft, 0xe01d => KeyCode::ControlRight, 0x001c => KeyCode::Enter, - 0xe05b => KeyCode::SuperLeft, - 0xe05c => KeyCode::SuperRight, + 0xe05b => KeyCode::MetaLeft, + 0xe05c => KeyCode::MetaRight, 0x002a => KeyCode::ShiftLeft, 0x0036 => KeyCode::ShiftRight, 0x0039 => KeyCode::Space, diff --git a/src/platform_impl/windows/keyboard_layout.rs b/src/platform_impl/windows/keyboard_layout.rs index 1ab0d2a68e..fb124d854d 100644 --- a/src/platform_impl/windows/keyboard_layout.rs +++ b/src/platform_impl/windows/keyboard_layout.rs @@ -279,7 +279,7 @@ impl LayoutCache { mods.set(ModifiersState::SHIFT, key_pressed(VK_SHIFT)); mods.set(ModifiersState::CONTROL, key_pressed(VK_CONTROL) && !filter_out_altgr); mods.set(ModifiersState::ALT, key_pressed(VK_MENU) && !filter_out_altgr); - mods.set(ModifiersState::SUPER, key_pressed(VK_LWIN) || key_pressed(VK_RWIN)); + mods.set(ModifiersState::META, key_pressed(VK_LWIN) || key_pressed(VK_RWIN)); mods } @@ -584,8 +584,8 @@ fn keycode_to_vkey(keycode: KeyCode, hkl: u64) -> VIRTUAL_KEY { KeyCode::ControlLeft => VK_LCONTROL, KeyCode::ControlRight => VK_RCONTROL, KeyCode::Enter => VK_RETURN, - KeyCode::SuperLeft => VK_LWIN, - KeyCode::SuperRight => VK_RWIN, + KeyCode::MetaLeft => VK_LWIN, + KeyCode::MetaRight => VK_RWIN, KeyCode::ShiftLeft => VK_RSHIFT, KeyCode::ShiftRight => VK_LSHIFT, KeyCode::Space => VK_SPACE, @@ -803,8 +803,8 @@ fn vkey_to_non_char_key( VK_INSERT => Key::Named(NamedKey::Insert), VK_DELETE => Key::Named(NamedKey::Delete), VK_HELP => Key::Named(NamedKey::Help), - VK_LWIN => Key::Named(NamedKey::Super), - VK_RWIN => Key::Named(NamedKey::Super), + VK_LWIN => Key::Named(NamedKey::Meta), + VK_RWIN => Key::Named(NamedKey::Meta), VK_APPS => Key::Named(NamedKey::ContextMenu), VK_SLEEP => Key::Named(NamedKey::Standby),