Fixed centering the D-pad on some joysticks

Fixes https://github.com/libsdl-org/SDL/issues/6767

(cherry picked from commit d1b4810542183a415e42b11b516bf8d5b0a6d58c)
This commit is contained in:
Sam Lantinga 2022-12-05 13:36:51 -08:00
parent 05b03032f1
commit ce67788629
1 changed files with 4 additions and 1 deletions

View File

@ -1473,6 +1473,7 @@ RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int size)
for (i = 0; i < nhats; ++i) { for (i = 0; i < nhats; ++i) {
HIDP_DATA *item = GetData(ctx->hat_indices[i], ctx->data, data_length); HIDP_DATA *item = GetData(ctx->hat_indices[i], ctx->data, data_length);
if (item) { if (item) {
Uint8 hat = SDL_HAT_CENTERED;
const Uint8 hat_states[] = { const Uint8 hat_states[] = {
SDL_HAT_CENTERED, SDL_HAT_CENTERED,
SDL_HAT_UP, SDL_HAT_UP,
@ -1483,6 +1484,7 @@ RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int size)
SDL_HAT_DOWN | SDL_HAT_LEFT, SDL_HAT_DOWN | SDL_HAT_LEFT,
SDL_HAT_LEFT, SDL_HAT_LEFT,
SDL_HAT_UP | SDL_HAT_LEFT, SDL_HAT_UP | SDL_HAT_LEFT,
SDL_HAT_CENTERED,
}; };
ULONG state = item->RawValue; ULONG state = item->RawValue;
@ -1490,8 +1492,9 @@ RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int size)
#ifdef SDL_JOYSTICK_RAWINPUT_MATCHING #ifdef SDL_JOYSTICK_RAWINPUT_MATCHING
match_state = (match_state & ~HAT_MASK) | hat_map[state]; match_state = (match_state & ~HAT_MASK) | hat_map[state];
#endif #endif
SDL_PrivateJoystickHat(joystick, i, hat_states[state]); hat = hat_states[state];
} }
SDL_PrivateJoystickHat(joystick, i, hat);
} }
} }