From 9ae058b20895e25f4380e8a8fa82eb933b57d2e6 Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Fri, 5 Jul 2024 22:11:59 -0700 Subject: [PATCH] Slightly adjusts button mappings for compatibility with SDL game controller database --- src/linux_joystick.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/linux_joystick.c b/src/linux_joystick.c index e704f909..bc1a2dc3 100644 --- a/src/linux_joystick.c +++ b/src/linux_joystick.c @@ -190,7 +190,10 @@ static GLFWbool openJoystickDevice(const char* path) int axisCount = 0, buttonCount = 0, hatCount = 0; - for (int code = BTN_MISC; code < KEY_CNT; code++) + // This loop should stop at KEY_CNT instead of KEY_MAX. However, we are + // terminating the loop one iteration early to maintain compatibility with + // the SDL gamepad mappings. + for (int code = BTN_JOYSTICK; code < KEY_MAX; code++) { if (!isBitSet(code, keyBits)) continue; @@ -199,7 +202,11 @@ static GLFWbool openJoystickDevice(const char* path) buttonCount++; } - for (int code = 0; code < BTN_MISC; code++) + // Originally, this range was not mapped, but some controllers now output + // these values. Appending them to the end of the list maintains both + // backwards compatibility with older versions of GLFW, and with the SDL + // gamepad mappings. + for (int code = 0; code < BTN_JOYSTICK; code++) { if (!isBitSet(code, keyBits)) continue;