Commit 797d2c5957e36fe917443c66589f8f14220256ed

Sam Lantinga 2019-06-30T22:48:13

Fixed bug 4436 - [OpenBSD] fix D-pad daniel.c.sinclair Hi, this patch breaks dpad/hat input on my PS4 controller. The attached patch restores functionality. Calling SDL_PrivateJoystickHat() at the end of BSD_JoystickUpdate was setting the hat state to zero on every kind of input, instead of just the HUG_DPAD events.

diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c
index fb63263..4a2e887 100644
--- a/src/joystick/bsd/SDL_sysjoystick.c
+++ b/src/joystick/bsd/SDL_sysjoystick.c
@@ -623,14 +623,22 @@ BSD_JoystickUpdate(SDL_Joystick * joy)
                                                    hitem.logical_minimum);
                         }
 #ifdef __OpenBSD__
-                        else if (usage == HUG_DPAD_UP)
+                        else if (usage == HUG_DPAD_UP) {
                             dpad[0] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
-                        else if (usage == HUG_DPAD_DOWN)
+                            SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
+                        }
+                        else if (usage == HUG_DPAD_DOWN) {
                             dpad[1] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
-                        else if (usage == HUG_DPAD_RIGHT)
+                            SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
+                        }
+                        else if (usage == HUG_DPAD_RIGHT) {
                             dpad[2] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
-                        else if (usage == HUG_DPAD_LEFT)
+                            SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
+                        }
+                        else if (usage == HUG_DPAD_LEFT) {
                             dpad[3] = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
+                            SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
+                        }
 #endif
                         break;
                     }
@@ -647,9 +655,6 @@ BSD_JoystickUpdate(SDL_Joystick * joy)
                 break;
             }
         }
-#ifdef __OpenBSD__
-        SDL_PrivateJoystickHat(joy, 0, dpad_to_sdl(dpad));
-#endif
         hid_end_parse(hdata);
     }
 }