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 21bb990
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 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(key: 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
7 changes: 3 additions & 4 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2512,8 +2512,8 @@ unsafe fn handle_raw_input<T: 'static>(userdata: &ThreadMsgTargetData<T>, data:
PhysicalKey::from_scancode(scancode as u32)
};
if keyboard.VKey == VK_SHIFT {
match physical_key {
PhysicalKey::Code(code) => match code {
if let PhysicalKey::Code(code) = physical_key {
match code {
KeyCode::NumpadDecimal
| KeyCode::Numpad0
| KeyCode::Numpad1
Expand Down Expand Up @@ -2543,8 +2543,7 @@ unsafe fn handle_raw_input<T: 'static>(userdata: &ThreadMsgTargetData<T>, data:
return;
}
_ => (),
},
_ => (),
}
}
}
userdata.send_event(Event::DeviceEvent {
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 21bb990

Please sign in to comment.