From a8345a90d2059022b4d7114cfcf16fc32c9094d5 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Fri, 24 Nov 2023 01:39:12 +0200 Subject: [PATCH] feat: support `Code::Backquote` on Linux (#44) closes #41 --- .changes/backquote.md | 5 ++ src/platform_impl/windows/mod.rs | 88 ++++++++++++++++---------------- src/platform_impl/x11/mod.rs | 73 +++++++++++++------------- 3 files changed, 86 insertions(+), 80 deletions(-) create mode 100644 .changes/backquote.md diff --git a/.changes/backquote.md b/.changes/backquote.md new file mode 100644 index 0000000..ec44753 --- /dev/null +++ b/.changes/backquote.md @@ -0,0 +1,5 @@ +--- +"global-hotkey": "patch" +--- + +Add support for `Code::Backquote` on Linux. diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 99720f9..c4211f1 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -173,53 +173,53 @@ pub fn get_instance_handle() -> windows_sys::Win32::Foundation::HMODULE { // used to build accelerators table from Key fn key_to_vk(key: &Code) -> Option { Some(match key { - Code::KeyA => unsafe { VkKeyScanW('a' as u16) as u16 }, - Code::KeyB => unsafe { VkKeyScanW('b' as u16) as u16 }, - Code::KeyC => unsafe { VkKeyScanW('c' as u16) as u16 }, - Code::KeyD => unsafe { VkKeyScanW('d' as u16) as u16 }, - Code::KeyE => unsafe { VkKeyScanW('e' as u16) as u16 }, - Code::KeyF => unsafe { VkKeyScanW('f' as u16) as u16 }, - Code::KeyG => unsafe { VkKeyScanW('g' as u16) as u16 }, - Code::KeyH => unsafe { VkKeyScanW('h' as u16) as u16 }, - Code::KeyI => unsafe { VkKeyScanW('i' as u16) as u16 }, - Code::KeyJ => unsafe { VkKeyScanW('j' as u16) as u16 }, - Code::KeyK => unsafe { VkKeyScanW('k' as u16) as u16 }, - Code::KeyL => unsafe { VkKeyScanW('l' as u16) as u16 }, - Code::KeyM => unsafe { VkKeyScanW('m' as u16) as u16 }, - Code::KeyN => unsafe { VkKeyScanW('n' as u16) as u16 }, - Code::KeyO => unsafe { VkKeyScanW('o' as u16) as u16 }, - Code::KeyP => unsafe { VkKeyScanW('p' as u16) as u16 }, - Code::KeyQ => unsafe { VkKeyScanW('q' as u16) as u16 }, - Code::KeyR => unsafe { VkKeyScanW('r' as u16) as u16 }, - Code::KeyS => unsafe { VkKeyScanW('s' as u16) as u16 }, - Code::KeyT => unsafe { VkKeyScanW('t' as u16) as u16 }, - Code::KeyU => unsafe { VkKeyScanW('u' as u16) as u16 }, - Code::KeyV => unsafe { VkKeyScanW('v' as u16) as u16 }, - Code::KeyW => unsafe { VkKeyScanW('w' as u16) as u16 }, - Code::KeyX => unsafe { VkKeyScanW('x' as u16) as u16 }, - Code::KeyY => unsafe { VkKeyScanW('y' as u16) as u16 }, - Code::KeyZ => unsafe { VkKeyScanW('z' as u16) as u16 }, - Code::Digit0 => unsafe { VkKeyScanW('0' as u16) as u16 }, - Code::Digit1 => unsafe { VkKeyScanW('1' as u16) as u16 }, - Code::Digit2 => unsafe { VkKeyScanW('2' as u16) as u16 }, - Code::Digit3 => unsafe { VkKeyScanW('3' as u16) as u16 }, - Code::Digit4 => unsafe { VkKeyScanW('4' as u16) as u16 }, - Code::Digit5 => unsafe { VkKeyScanW('5' as u16) as u16 }, - Code::Digit6 => unsafe { VkKeyScanW('6' as u16) as u16 }, - Code::Digit7 => unsafe { VkKeyScanW('7' as u16) as u16 }, - Code::Digit8 => unsafe { VkKeyScanW('8' as u16) as u16 }, - Code::Digit9 => unsafe { VkKeyScanW('9' as u16) as u16 }, + Code::KeyA => VK_A, + Code::KeyB => VK_B, + Code::KeyC => VK_C, + Code::KeyD => VK_D, + Code::KeyE => VK_E, + Code::KeyF => VK_F, + Code::KeyG => VK_G, + Code::KeyH => VK_H, + Code::KeyI => VK_I, + Code::KeyJ => VK_J, + Code::KeyK => VK_K, + Code::KeyL => VK_L, + Code::KeyM => VK_M, + Code::KeyN => VK_N, + Code::KeyO => VK_O, + Code::KeyP => VK_P, + Code::KeyQ => VK_Q, + Code::KeyR => VK_R, + Code::KeyS => VK_S, + Code::KeyT => VK_T, + Code::KeyU => VK_U, + Code::KeyV => VK_V, + Code::KeyW => VK_W, + Code::KeyX => VK_X, + Code::KeyY => VK_Y, + Code::KeyZ => VK_Z, + Code::Digit0 => VK_0, + Code::Digit1 => VK_1, + Code::Digit2 => VK_2, + Code::Digit3 => VK_3, + Code::Digit4 => VK_4, + Code::Digit5 => VK_5, + Code::Digit6 => VK_6, + Code::Digit7 => VK_7, + Code::Digit8 => VK_8, + Code::Digit9 => VK_9, + Code::Equal => VK_OEM_PLUS, Code::Comma => VK_OEM_COMMA, Code::Minus => VK_OEM_MINUS, Code::Period => VK_OEM_PERIOD, - Code::Equal => unsafe { VkKeyScanW('=' as u16) as u16 }, - Code::Semicolon => unsafe { VkKeyScanW(';' as u16) as u16 }, - Code::Slash => unsafe { VkKeyScanW('/' as u16) as u16 }, - Code::Backslash => unsafe { VkKeyScanW('\\' as u16) as u16 }, - Code::Quote => unsafe { VkKeyScanW('\'' as u16) as u16 }, - Code::Backquote => unsafe { VkKeyScanW('`' as u16) as u16 }, - Code::BracketLeft => unsafe { VkKeyScanW('[' as u16) as u16 }, - Code::BracketRight => unsafe { VkKeyScanW(']' as u16) as u16 }, + Code::Semicolon => VK_OEM_1, + Code::Slash => VK_OEM_2, + Code::Backquote => VK_OEM_3, + Code::BracketLeft => VK_OEM_4, + Code::Backslash => VK_OEM_5, + Code::BracketRight => VK_OEM_6, + Code::Quote => VK_OEM_7, Code::Backspace => VK_BACK, Code::Tab => VK_TAB, Code::Space => VK_SPACE, diff --git a/src/platform_impl/x11/mod.rs b/src/platform_impl/x11/mod.rs index 9e9d60f..62470fa 100644 --- a/src/platform_impl/x11/mod.rs +++ b/src/platform_impl/x11/mod.rs @@ -226,46 +226,47 @@ fn events_processor(thread_rx: Receiver) { fn keycode_to_x11_scancode(key: Code) -> Option { Some(match key { - Code::KeyA => 'A' as u32, - Code::KeyB => 'B' as u32, - Code::KeyC => 'C' as u32, - Code::KeyD => 'D' as u32, - Code::KeyE => 'E' as u32, - Code::KeyF => 'F' as u32, - Code::KeyG => 'G' as u32, - Code::KeyH => 'H' as u32, - Code::KeyI => 'I' as u32, - Code::KeyJ => 'J' as u32, - Code::KeyK => 'K' as u32, - Code::KeyL => 'L' as u32, - Code::KeyM => 'M' as u32, - Code::KeyN => 'N' as u32, - Code::KeyO => 'O' as u32, - Code::KeyP => 'P' as u32, - Code::KeyQ => 'Q' as u32, - Code::KeyR => 'R' as u32, - Code::KeyS => 'S' as u32, - Code::KeyT => 'T' as u32, - Code::KeyU => 'U' as u32, - Code::KeyV => 'V' as u32, - Code::KeyW => 'W' as u32, - Code::KeyX => 'X' as u32, - Code::KeyY => 'Y' as u32, - Code::KeyZ => 'Z' as u32, + Code::KeyA => keysym::XK_A, + Code::KeyB => keysym::XK_B, + Code::KeyC => keysym::XK_C, + Code::KeyD => keysym::XK_D, + Code::KeyE => keysym::XK_E, + Code::KeyF => keysym::XK_F, + Code::KeyG => keysym::XK_G, + Code::KeyH => keysym::XK_H, + Code::KeyI => keysym::XK_I, + Code::KeyJ => keysym::XK_J, + Code::KeyK => keysym::XK_K, + Code::KeyL => keysym::XK_L, + Code::KeyM => keysym::XK_M, + Code::KeyN => keysym::XK_N, + Code::KeyO => keysym::XK_O, + Code::KeyP => keysym::XK_P, + Code::KeyQ => keysym::XK_Q, + Code::KeyR => keysym::XK_R, + Code::KeyS => keysym::XK_S, + Code::KeyT => keysym::XK_T, + Code::KeyU => keysym::XK_U, + Code::KeyV => keysym::XK_V, + Code::KeyW => keysym::XK_W, + Code::KeyX => keysym::XK_X, + Code::KeyY => keysym::XK_Y, + Code::KeyZ => keysym::XK_Z, Code::Backslash => keysym::XK_backslash, Code::BracketLeft => keysym::XK_bracketleft, Code::BracketRight => keysym::XK_bracketright, + Code::Backquote => keysym::XK_quoteleft, Code::Comma => keysym::XK_comma, - Code::Digit0 => '0' as u32, - Code::Digit1 => '1' as u32, - Code::Digit2 => '2' as u32, - Code::Digit3 => '3' as u32, - Code::Digit4 => '4' as u32, - Code::Digit5 => '5' as u32, - Code::Digit6 => '6' as u32, - Code::Digit7 => '7' as u32, - Code::Digit8 => '8' as u32, - Code::Digit9 => '9' as u32, + Code::Digit0 => keysym::XK_0, + Code::Digit1 => keysym::XK_1, + Code::Digit2 => keysym::XK_2, + Code::Digit3 => keysym::XK_3, + Code::Digit4 => keysym::XK_4, + Code::Digit5 => keysym::XK_5, + Code::Digit6 => keysym::XK_6, + Code::Digit7 => keysym::XK_7, + Code::Digit8 => keysym::XK_8, + Code::Digit9 => keysym::XK_9, Code::Equal => keysym::XK_equal, Code::Minus => keysym::XK_minus, Code::Period => keysym::XK_period,