SDL: Fixed centering the D-pad on some joysticks (ce677)

From ce67788629f4dcd25b19391b4eb837e848e492b1 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 5 Dec 2022 13:36:51 -0800
Subject: [PATCH] Fixed centering the D-pad on some joysticks

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

(cherry picked from commit d1b4810542183a415e42b11b516bf8d5b0a6d58c)
---
 src/joystick/windows/SDL_rawinputjoystick.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

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