From a2db4c0a320aafc10d240c432fe5ef4e4d84629d Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 29 Aug 2020 13:38:41 +0000 Subject: [PATCH] Unify Minus/Subtract virtual keycodes On all platforms other than Linux/X11, the Subtract key was uniformly used only for the Numpad. To make this cross-platform compatible, the `-` key will now map to `Minus` on X11 instead of `Subtract`. Since people have been confused about the difference between `Minus` and `Subtract` in the past, the `Subtract` key has also been renamed to `NumpadSubtract`. This is a breaking change that might be annoying to downstream since there's no direct improvement, but it should help new users in the future. Alternatively this could just be documented, rather than explicitly mentioning the Numpad in the name. --- CHANGELOG.md | 2 ++ src/event.rs | 8 ++++---- src/platform_impl/linux/wayland/keyboard.rs | 3 +-- src/platform_impl/linux/x11/events.rs | 4 ++-- src/platform_impl/macos/event.rs | 2 +- src/platform_impl/web/stdweb/event.rs | 2 +- src/platform_impl/web/web_sys/event.rs | 2 +- src/platform_impl/windows/event.rs | 2 +- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8077d4a..cc4386ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ - **Breaking:** On Web, `set_cursor_position` and `set_cursor_grab` will now always return an error. - **Breaking:** `PixelDelta` scroll events now return a `PhysicalPosition`. - On NetBSD, fixed crash due to incorrect detection of the main thread. +- **Breaking:** The virtual key code `Subtract` has been renamed to `NumpadSubtract` +- **Breaking:** On X11, `-` key is mapped to the `Minus` virtual key code, instead of `Subtract` # 0.22.2 (2020-05-16) diff --git a/src/event.rs b/src/event.rs index 9e9320c2..134421ac 100644 --- a/src/event.rs +++ b/src/event.rs @@ -892,6 +892,10 @@ pub enum VirtualKeyCode { Numpad7, Numpad8, Numpad9, + NumpadComma, + NumpadEnter, + NumpadEquals, + NumpadSubtract, AbntC1, AbntC2, @@ -930,9 +934,6 @@ pub enum VirtualKeyCode { NavigateBackward, NextTrack, NoConvert, - NumpadComma, - NumpadEnter, - NumpadEquals, OEM102, Period, PlayPause, @@ -947,7 +948,6 @@ pub enum VirtualKeyCode { Slash, Sleep, Stop, - Subtract, Sysrq, Tab, Underline, diff --git a/src/platform_impl/linux/wayland/keyboard.rs b/src/platform_impl/linux/wayland/keyboard.rs index 8f911888..fb9219e0 100644 --- a/src/platform_impl/linux/wayland/keyboard.rs +++ b/src/platform_impl/linux/wayland/keyboard.rs @@ -340,7 +340,7 @@ fn keysym_to_vkey(keysym: u32) -> Option { 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_Subtract => Some(VirtualKeyCode::NumpadSubtract), 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), @@ -360,7 +360,6 @@ fn keysym_to_vkey(keysym: u32) -> Option { keysyms::XKB_KEY_slash => Some(VirtualKeyCode::Slash), // => Some(VirtualKeyCode::Sleep), // => Some(VirtualKeyCode::Stop), - // => Some(VirtualKeyCode::Subtract), // => Some(VirtualKeyCode::Sysrq), keysyms::XKB_KEY_Tab => Some(VirtualKeyCode::Tab), keysyms::XKB_KEY_ISO_Left_Tab => Some(VirtualKeyCode::Tab), diff --git a/src/platform_impl/linux/x11/events.rs b/src/platform_impl/linux/x11/events.rs index 1b4996e7..f7d98b98 100644 --- a/src/platform_impl/linux/x11/events.rs +++ b/src/platform_impl/linux/x11/events.rs @@ -84,7 +84,7 @@ pub fn keysym_to_element(keysym: libc::c_uint) -> Option { //ffi::XK_KP_Multiply => VirtualKeyCode::NumpadMultiply, ffi::XK_KP_Add => VirtualKeyCode::Add, //ffi::XK_KP_Separator => VirtualKeyCode::Kp_separator, - ffi::XK_KP_Subtract => VirtualKeyCode::Subtract, + ffi::XK_KP_Subtract => VirtualKeyCode::NumpadSubtract, //ffi::XK_KP_Decimal => VirtualKeyCode::Kp_decimal, ffi::XK_KP_Divide => VirtualKeyCode::Divide, ffi::XK_KP_0 => VirtualKeyCode::Numpad0, @@ -186,7 +186,7 @@ pub fn keysym_to_element(keysym: libc::c_uint) -> Option { //ffi::XK_asterisk => VirtualKeyCode::Asterisk, ffi::XK_plus => VirtualKeyCode::Add, ffi::XK_comma => VirtualKeyCode::Comma, - ffi::XK_minus => VirtualKeyCode::Subtract, + ffi::XK_minus => VirtualKeyCode::Minus, ffi::XK_period => VirtualKeyCode::Period, ffi::XK_slash => VirtualKeyCode::Slash, ffi::XK_0 => VirtualKeyCode::Key0, diff --git a/src/platform_impl/macos/event.rs b/src/platform_impl/macos/event.rs index 6e231940..dd12c973 100644 --- a/src/platform_impl/macos/event.rs +++ b/src/platform_impl/macos/event.rs @@ -169,7 +169,7 @@ pub fn scancode_to_keycode(scancode: c_ushort) -> Option { 0x4b => VirtualKeyCode::Divide, 0x4c => VirtualKeyCode::NumpadEnter, //0x4d => unkown, - 0x4e => VirtualKeyCode::Subtract, + 0x4e => VirtualKeyCode::NumpadSubtract, 0x4f => VirtualKeyCode::F18, 0x50 => VirtualKeyCode::F19, 0x51 => VirtualKeyCode::NumpadEquals, diff --git a/src/platform_impl/web/stdweb/event.rs b/src/platform_impl/web/stdweb/event.rs index d57f9bb5..e9bb1b38 100644 --- a/src/platform_impl/web/stdweb/event.rs +++ b/src/platform_impl/web/stdweb/event.rs @@ -195,7 +195,7 @@ pub fn virtual_key_code(event: &impl IKeyboardEvent) -> Option { "Slash" => VirtualKeyCode::Slash, "Sleep" => VirtualKeyCode::Sleep, "Stop" => VirtualKeyCode::Stop, - "NumpadSubtract" => VirtualKeyCode::Subtract, + "NumpadSubtract" => VirtualKeyCode::NumpadSubtract, "Sysrq" => VirtualKeyCode::Sysrq, "Tab" => VirtualKeyCode::Tab, "Underline" => VirtualKeyCode::Underline, diff --git a/src/platform_impl/web/web_sys/event.rs b/src/platform_impl/web/web_sys/event.rs index 18927d40..80291568 100644 --- a/src/platform_impl/web/web_sys/event.rs +++ b/src/platform_impl/web/web_sys/event.rs @@ -204,7 +204,7 @@ pub fn virtual_key_code(event: &KeyboardEvent) -> Option { "Slash" => VirtualKeyCode::Slash, "Sleep" => VirtualKeyCode::Sleep, "Stop" => VirtualKeyCode::Stop, - "NumpadSubtract" => VirtualKeyCode::Subtract, + "NumpadSubtract" => VirtualKeyCode::NumpadSubtract, "Sysrq" => VirtualKeyCode::Sysrq, "Tab" => VirtualKeyCode::Tab, "Underline" => VirtualKeyCode::Underline, diff --git a/src/platform_impl/windows/event.rs b/src/platform_impl/windows/event.rs index 49501f1a..40312418 100644 --- a/src/platform_impl/windows/event.rs +++ b/src/platform_impl/windows/event.rs @@ -262,7 +262,7 @@ pub fn vkey_to_winit_vkey(vkey: c_int) -> Option { winuser::VK_MULTIPLY => Some(VirtualKeyCode::Multiply), winuser::VK_ADD => Some(VirtualKeyCode::Add), //winuser::VK_SEPARATOR => Some(VirtualKeyCode::Separator), - winuser::VK_SUBTRACT => Some(VirtualKeyCode::Subtract), + winuser::VK_SUBTRACT => Some(VirtualKeyCode::NumpadSubtract), winuser::VK_DECIMAL => Some(VirtualKeyCode::Decimal), winuser::VK_DIVIDE => Some(VirtualKeyCode::Divide), winuser::VK_F1 => Some(VirtualKeyCode::F1),