From 510f0fe8f20670a8aae1e49ebd81fb2f0263640e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 22 Sep 2023 11:44:18 -0700 Subject: [PATCH] apprt/embedded: if a physical key input is a keypad key, keep it --- src/apprt/embedded.zig | 3 +++ src/input/key.zig | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index ac5a45259..fed00b088 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -595,6 +595,9 @@ pub const Surface = struct { // // We also only do key translation if this is not a dead key. const key = if (!result.composing) key: { + // If our physical key is a keypad key, we use that. + if (physical_key.keypad()) break :key physical_key; + // A completed key. If the length of the key is one then we can // attempt to translate it to a key enum and call the key // callback. First try plain ASCII. diff --git a/src/input/key.zig b/src/input/key.zig index 46263bf30..830501772 100644 --- a/src/input/key.zig +++ b/src/input/key.zig @@ -422,4 +422,30 @@ pub const Key = enum(c_int) { else => false, }; } + + /// Returns true if this is a keypad key. + pub fn keypad(self: Key) bool { + return switch (self) { + .kp_0, + .kp_1, + .kp_2, + .kp_3, + .kp_4, + .kp_5, + .kp_6, + .kp_7, + .kp_8, + .kp_9, + .kp_decimal, + .kp_divide, + .kp_multiply, + .kp_subtract, + .kp_add, + .kp_enter, + .kp_equal, + => true, + + else => false, + }; + } };