Skip to content

Commit

Permalink
Fixes for KeyCode / PhysicalKey split
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Oct 15, 2023
1 parent 3e87fe2 commit f99c4ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/platform_impl/macos/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ impl PartialKeyEventInfo {
};

KeyEvent {
physical_key: self.code,
physical_key: self.physical_key,
logical_key,
text,
location: self.location,
Expand Down

0 comments on commit f99c4ba

Please sign in to comment.