From 547959c1efa8bc3150fe7dec54874afd119bea08 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 5 Sep 2018 07:31:55 +0530 Subject: [PATCH] Linux: Fix numpad arrow keys not working when num lock is off Fixes #857 --- docs/changelog.rst | 2 ++ glfw/xkb_glfw.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index dfcd2eb21..cc7d0cab7 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -10,6 +10,8 @@ Changelog font fallback for all subsequent characters that cannot be rendered in the main font to fail (:iss:`799`) +- Linux: Fix numpad arrow keys not working when num lock is off (:iss:`857`) + - Allow mapping shortcuts using the raw key code from the OS (:iss:`848`) - Allow mapping of individual keypresses without modifiers as shortcuts diff --git a/glfw/xkb_glfw.c b/glfw/xkb_glfw.c index 22a532102..c4baf5ff9 100644 --- a/glfw/xkb_glfw.c +++ b/glfw/xkb_glfw.c @@ -33,7 +33,7 @@ #define debug(...) if (_glfw.hints.init.debugKeyboard) printf(__VA_ARGS__); -#define map_key(key) { \ +#define map_key(key) \ switch(key) { \ S(space, SPACE); \ S(apostrophe, APOSTROPHE); \ @@ -93,10 +93,6 @@ D(A, Z, A, Z); \ R(F1, F25, F1, F25); \ R(KP_0, KP_9, KP_0, KP_9); \ - default: \ - break; \ - } \ -} static int glfw_key_for_sym(xkb_keysym_t key) { @@ -105,6 +101,13 @@ glfw_key_for_sym(xkb_keysym_t key) { #define R(s, e, gs, ...) case XKB_KEY_##s ... XKB_KEY_##e: return GLFW_KEY_##gs + key - XKB_KEY_##s #define D(s, e, gs, ...) R(s, e, gs) map_key(key) + S(KP_Up, UP); + S(KP_Down, DOWN); + S(KP_Left, LEFT); + S(KP_Right, RIGHT); + default: + break; + } return GLFW_KEY_UNKNOWN; #undef F #undef D @@ -119,6 +122,9 @@ glfw_xkb_sym_for_key(int key) { #define R(s, e, gs, ge) case GLFW_KEY_##gs ... GLFW_KEY_##ge: return XKB_KEY_##s + key - GLFW_KEY_##gs #define D(...) map_key(key) + default: + break; + } return GLFW_KEY_UNKNOWN; #undef F #undef D