From f99c4bae49e10345887fca7035cfa9c8afa421f4 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sun, 15 Oct 2023 08:51:34 +0100 Subject: [PATCH] Fixes for KeyCode / PhysicalKey split --- src/platform_impl/macos/event.rs | 14 ++++++++------ src/platform_impl/macos/view.rs | 4 ++-- src/platform_impl/windows/keyboard.rs | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/platform_impl/macos/event.rs b/src/platform_impl/macos/event.rs index dd8c9699602..5418752ca1d 100644 --- a/src/platform_impl/macos/event.rs +++ b/src/platform_impl/macos/event.rs @@ -176,10 +176,7 @@ pub(crate) fn create_key_event( None }; - let location = match physical_key { - PhysicalKey::Code(code) => code_to_location(code), - _ => KeyLocation::Standard, - }; + let location = code_to_location(physical_key); KeyEvent { location, @@ -198,7 +195,7 @@ pub(crate) fn create_key_event( pub fn code_to_key(key: PhysicalKey, scancode: u16) -> Key { let code = match key { PhysicalKey::Code(code) => code, - PhysicalKey::Unidentified(code) => return Key::Unidentified(code), + PhysicalKey::Unidentified(code) => return Key::Unidentified(code.into()), }; match code { @@ -258,7 +255,12 @@ pub fn code_to_key(key: PhysicalKey, scancode: u16) -> Key { } } -pub fn code_to_location(code: KeyCode) -> KeyLocation { +pub fn code_to_location(code: PhysicalKey) -> KeyLocation { + let code = match key { + PhysicalKey::Code(code) => code, + PhysicalKey::Unidentified(code) => return KeyLocation::Standard, + }; + match code { KeyCode::SuperRight => KeyLocation::Right, KeyCode::SuperLeft => KeyLocation::Left, diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 574c8bad95f..eb9ed3684c7 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -951,7 +951,7 @@ impl WinitView { if phys_mod.contains(ModLocationMask::LEFT) { let mut event = event.clone(); event.location = KeyLocation::Left; - event.physical_key = get_left_modifier_code(&event.logical_key); + event.physical_key = get_left_modifier_code(&event.logical_key).into(); events.push_back(WindowEvent::KeyboardInput { device_id: DEVICE_ID, event, @@ -960,7 +960,7 @@ impl WinitView { } if phys_mod.contains(ModLocationMask::RIGHT) { event.location = KeyLocation::Right; - event.physical_key = get_right_modifier_code(&event.logical_key); + event.physical_key = get_right_modifier_code(&event.logical_key).into(); events.push_back(WindowEvent::KeyboardInput { device_id: DEVICE_ID, event, diff --git a/src/platform_impl/windows/keyboard.rs b/src/platform_impl/windows/keyboard.rs index 86e9c984dea..1aed1f5fc43 100644 --- a/src/platform_impl/windows/keyboard.rs +++ b/src/platform_impl/windows/keyboard.rs @@ -658,7 +658,7 @@ impl PartialKeyEventInfo { }; KeyEvent { - physical_key: self.code, + physical_key: self.physical_key, logical_key, text, location: self.location,