Compare commits

...

4 Commits

Author SHA1 Message Date
Mason Remaley
0749dfe812
Merge 9ae058b208 into 7ef6efeb66 2025-08-19 11:14:10 +08:00
Mason Remaley
9ae058b208 Slightly adjusts button mappings for compatibility with SDL game controller database 2024-07-05 22:11:59 -07:00
Mason Remaley
6836e650bc Remaps indices of buttons below the previous minimum
This prevents us from missing their inputs, while also maintaining
backwards compatibility with previous indices
2024-07-05 21:56:00 -07:00
Mason Remaley
5e1ec2444f Fixes an out of bounds joystick array access
Testing with an Xbox Series X controller. The extra button they
added directly under the Xbox button emits 0xA7 for me, which is
lower than BTN_MISC. As a result, when pressed, handleKeyEvent
was indexing an array with a negative index.

This commit adds a bounds check preventing the negative index, and
adds a second bounds check to a similar function preemptively.

It's possible that the better fix for this is to extend the range of
the buttons array so that this button can be mapped, but that may
need some disucssion first.
2024-07-05 20:17:02 -07:00
2 changed files with 20 additions and 4 deletions

View File

@ -50,7 +50,7 @@
static void handleKeyEvent(_GLFWjoystick* js, int code, int value)
{
_glfwInputJoystickButton(js,
js->linjs.keyMap[code - BTN_MISC],
js->linjs.keyMap[code],
value ? GLFW_PRESS : GLFW_RELEASE);
}
@ -190,12 +190,28 @@ 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;
linjs.keyMap[code - BTN_MISC] = buttonCount;
linjs.keyMap[code] = buttonCount;
buttonCount++;
}
// 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;
linjs.keyMap[code] = buttonCount;
buttonCount++;
}

View File

@ -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];