SDL: autotools: added windows.gaming.input.h (and SDL_JOYSTICK_WGI) detection

From 802e17aad9ee5e555dfd95fd89ffc1ac414de9cf Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 3 Nov 2021 20:35:20 +0300
Subject: [PATCH] autotools: added windows.gaming.input.h (and
 SDL_JOYSTICK_WGI) detection

---
 configure               | 19 ++++++++++++++++++-
 configure.ac            | 10 +++++++++-
 include/SDL_config.h.in |  2 ++
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 76990784f9..c87dc3d1b2 100755
--- a/configure
+++ b/configure
@@ -24071,6 +24071,18 @@ $as_echo "#define HAVE_XINPUT_STATE_EX 1" >>confdefs.h
         fi
     fi
 
+    ac_fn_c_check_header_mongrel "$LINENO" "windows.gaming.input.h" "ac_cv_header_windows_gaming_input_h" "$ac_includes_default"
+if test "x$ac_cv_header_windows_gaming_input_h" = xyes; then :
+  have_wgi=yes
+fi
+
+
+    if test x$have_wgi = xyes; then
+
+$as_echo "#define HAVE_WINDOWS_GAMING_INPUT_H 1" >>confdefs.h
+
+    fi
+
     ac_fn_c_check_header_mongrel "$LINENO" "mmdeviceapi.h" "ac_cv_header_mmdeviceapi_h" "$ac_includes_default"
 if test "x$ac_cv_header_mmdeviceapi_h" = xyes; then :
   have_wasapi=yes
@@ -25238,11 +25250,16 @@ $as_echo "#define SDL_AUDIO_DRIVER_WASAPI 1" >>confdefs.h
 
 $as_echo "#define SDL_JOYSTICK_RAWINPUT 1" >>confdefs.h
 
-            if test x$have_dinput = xyes -o x$have_xinput = xyes; then
+            if test x$have_dinput = xyes -o x$have_xinput = xyes -o x$have_wgi = xyes; then
                 if test x$have_xinput = xyes; then
 
 $as_echo "#define SDL_JOYSTICK_XINPUT 1" >>confdefs.h
 
+                fi
+                if test x$have_wgi = xyes; then
+
+$as_echo "#define SDL_JOYSTICK_WGI 1" >>confdefs.h
+
                 fi
                 if test x$have_dinput = xyes; then
 
diff --git a/configure.ac b/configure.ac
index b61d3f1060..bec63a7773 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3199,6 +3199,11 @@ XINPUT_STATE_EX s1;
         fi
     fi
 
+    AC_CHECK_HEADER(windows.gaming.input.h, have_wgi=yes)
+    if test x$have_wgi = xyes; then
+        AC_DEFINE(HAVE_WINDOWS_GAMING_INPUT_H, 1, [ ])
+    fi
+
     AC_CHECK_HEADER(mmdeviceapi.h, have_wasapi=yes)
     if test x$have_wasapi = xyes; then
         AC_DEFINE(HAVE_MMDEVICEAPI_H, 1, [ ])
@@ -3846,10 +3851,13 @@ case "$host" in
         # Set up files for the joystick library
         if test x$enable_joystick = xyes; then
             AC_DEFINE(SDL_JOYSTICK_RAWINPUT, 1, [ ])
-            if test x$have_dinput = xyes -o x$have_xinput = xyes; then
+            if test x$have_dinput = xyes -o x$have_xinput = xyes -o x$have_wgi = xyes; then
                 if test x$have_xinput = xyes; then
                     AC_DEFINE(SDL_JOYSTICK_XINPUT, 1, [ ])
                 fi
+                if test x$have_wgi = xyes; then
+                    AC_DEFINE(SDL_JOYSTICK_WGI, 1, [ ])
+                fi
                 if test x$have_dinput = xyes; then
                     AC_DEFINE(SDL_JOYSTICK_DINPUT, 1, [ ])
                     EXTRA_LDFLAGS="$EXTRA_LDFLAGS -ldinput8 -ldxguid -ldxerr8"
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index 0bb904c13e..51731b448b 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -232,6 +232,7 @@
 #undef HAVE_DINPUT_H
 #undef HAVE_DSOUND_H
 #undef HAVE_DXGI_H
+#undef HAVE_WINDOWS_GAMING_INPUT_H
 #undef HAVE_XINPUT_H
 
 #undef HAVE_MMDEVICEAPI_H
@@ -307,6 +308,7 @@
 #undef SDL_INPUT_WSCONS
 #undef SDL_JOYSTICK_HAIKU
 #undef SDL_JOYSTICK_DINPUT
+#undef SDL_JOYSTICK_WGI
 #undef SDL_JOYSTICK_XINPUT
 #undef SDL_JOYSTICK_DUMMY
 #undef SDL_JOYSTICK_IOKIT