From 6836e650bc086f2d0a8533f9b00750695cb6a026 Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Fri, 5 Jul 2024 21:56:00 -0700 Subject: [PATCH] Remaps indices of buttons below the previous minimum This prevents us from missing their inputs, while also maintaining backwards compatibility with previous indices --- src/linux_joystick.c | 15 +++++++++++---- src/linux_joystick.h | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/linux_joystick.c b/src/linux_joystick.c index acf4e7aa..e704f909 100644 --- a/src/linux_joystick.c +++ b/src/linux_joystick.c @@ -49,9 +49,8 @@ // static void handleKeyEvent(_GLFWjoystick* js, int code, int value) { - if (code < BTN_MISC || code >= KEY_CNT - BTN_MISC) return; _glfwInputJoystickButton(js, - js->linjs.keyMap[code - BTN_MISC], + js->linjs.keyMap[code], value ? GLFW_PRESS : GLFW_RELEASE); } @@ -59,7 +58,6 @@ static void handleKeyEvent(_GLFWjoystick* js, int code, int value) // static void handleAbsEvent(_GLFWjoystick* js, int code, int value) { - if (code >= ABS_CNT) return; const int index = js->linjs.absMap[code]; if (code >= ABS_HAT0X && code <= ABS_HAT3Y) @@ -197,7 +195,16 @@ static GLFWbool openJoystickDevice(const char* path) if (!isBitSet(code, keyBits)) continue; - linjs.keyMap[code - BTN_MISC] = buttonCount; + linjs.keyMap[code] = buttonCount; + buttonCount++; + } + + for (int code = 0; code < BTN_MISC; code++) + { + if (!isBitSet(code, keyBits)) + continue; + + linjs.keyMap[code] = buttonCount; buttonCount++; } diff --git a/src/linux_joystick.h b/src/linux_joystick.h index 1ea3deb3..36ef21b2 100644 --- a/src/linux_joystick.h +++ b/src/linux_joystick.h @@ -37,7 +37,7 @@ typedef struct _GLFWjoystickLinux { int fd; char path[PATH_MAX]; - int keyMap[KEY_CNT - BTN_MISC]; + int keyMap[KEY_CNT]; int absMap[ABS_CNT]; struct input_absinfo absInfo[ABS_CNT]; int hats[4][2];