From 20b09c451496dc89f56213b1aa88c47451fe8840 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 7 Apr 2019 07:25:37 +0200 Subject: [PATCH] Add additional numpad key mappings (#805) * Add additional numpad key mappings Since some platforms have already used the existing `Add`, `Subtract` and `Divide` codes to map numpad keys, the X11 and Wayland platform has been updated to achieve parity between platforms. On macOS only the `Subtract` numpad key had to be added. Since the numpad key is different from the normal keys, an alternative option would be to add new `NumpadAdd`, `NumpadSubtract` and `NumpadDivide` actions, however I think in this case it should be fine to map them to the same virtual key code. * Add Numpad PageUp/Down, Home and End on Wayland --- CHANGELOG.md | 3 +++ src/platform_impl/linux/wayland/keyboard.rs | 7 +++++++ src/platform_impl/linux/x11/events.rs | 6 +++--- src/platform_impl/macos/event_loop.rs | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ea4f9d8..fc7c2c99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,9 @@ - On Windows, cursor grabs used to get perpetually canceled when the grabbing window lost focus. Now, cursor grabs automatically get re-initialized when the window regains focus and the mouse moves over the client area. - On Windows, only vertical mouse wheel events were handled. Now, horizontal mouse wheel events are also handled. - On Windows, ignore the AltGr key when populating the `ModifersState` type. +- On Linux, the numpad's add, subtract and divide keys are now mapped to the `Add`, `Subtract` and `Divide` virtual key codes +- On macOS, the numpad's subtract key has been added to the `Subtract` mapping +- On Wayland, the numpad's home, end, page up and page down keys are now mapped to the `Home`, `End`, `PageUp` and `PageDown` virtual key codes # Version 0.18.1 (2018-12-30) diff --git a/src/platform_impl/linux/wayland/keyboard.rs b/src/platform_impl/linux/wayland/keyboard.rs index 420d0ab6..d0930949 100644 --- a/src/platform_impl/linux/wayland/keyboard.rs +++ b/src/platform_impl/linux/wayland/keyboard.rs @@ -295,6 +295,13 @@ fn keysym_to_vkey(keysym: u32) -> Option { keysyms::XKB_KEY_KP_Separator => Some(VirtualKeyCode::NumpadComma), keysyms::XKB_KEY_KP_Enter => Some(VirtualKeyCode::NumpadEnter), keysyms::XKB_KEY_KP_Equal => Some(VirtualKeyCode::NumpadEquals), + keysyms::XKB_KEY_KP_Add => Some(VirtualKeyCode::Add), + keysyms::XKB_KEY_KP_Subtract => Some(VirtualKeyCode::Subtract), + keysyms::XKB_KEY_KP_Divide => Some(VirtualKeyCode::Divide), + keysyms::XKB_KEY_KP_Page_Up => Some(VirtualKeyCode::PageUp), + keysyms::XKB_KEY_KP_Page_Down => Some(VirtualKeyCode::PageDown), + keysyms::XKB_KEY_KP_Home => Some(VirtualKeyCode::Home), + keysyms::XKB_KEY_KP_End => Some(VirtualKeyCode::End), // => Some(VirtualKeyCode::OEM102), // => Some(VirtualKeyCode::Period), // => Some(VirtualKeyCode::Playpause), diff --git a/src/platform_impl/linux/x11/events.rs b/src/platform_impl/linux/x11/events.rs index 037ee4c4..85306413 100644 --- a/src/platform_impl/linux/x11/events.rs +++ b/src/platform_impl/linux/x11/events.rs @@ -82,11 +82,11 @@ pub fn keysym_to_element(keysym: libc::c_uint) -> Option { ffi::XK_KP_Delete => events::VirtualKeyCode::Delete, ffi::XK_KP_Equal => events::VirtualKeyCode::NumpadEquals, //ffi::XK_KP_Multiply => events::VirtualKeyCode::NumpadMultiply, - //ffi::XK_KP_Add => events::VirtualKeyCode::NumpadAdd, + ffi::XK_KP_Add => events::VirtualKeyCode::Add, //ffi::XK_KP_Separator => events::VirtualKeyCode::Kp_separator, - //ffi::XK_KP_Subtract => events::VirtualKeyCode::NumpadSubtract, + ffi::XK_KP_Subtract => events::VirtualKeyCode::Subtract, //ffi::XK_KP_Decimal => events::VirtualKeyCode::Kp_decimal, - //ffi::XK_KP_Divide => events::VirtualKeyCode::NumpadDivide, + ffi::XK_KP_Divide => events::VirtualKeyCode::Divide, ffi::XK_KP_0 => events::VirtualKeyCode::Numpad0, ffi::XK_KP_1 => events::VirtualKeyCode::Numpad1, ffi::XK_KP_2 => events::VirtualKeyCode::Numpad2, diff --git a/src/platform_impl/macos/event_loop.rs b/src/platform_impl/macos/event_loop.rs index 8442da6d..42ad8cb4 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -683,6 +683,7 @@ pub fn scancode_to_keycode(code: c_ushort) -> Option { 0x4a => events::VirtualKeyCode::VolumeDown, 0x4b => events::VirtualKeyCode::Divide, 0x4c => events::VirtualKeyCode::NumpadEnter, + 0x4e => events::VirtualKeyCode::Subtract, //0x4d => unkown, 0x4e => events::VirtualKeyCode::Subtract, 0x4f => events::VirtualKeyCode::F18,