sdl2-compat: DISABLE/ENABLE/QUERY functions were split into getters and setters.

From d0b1b92faaf504d02f3118345ea366b2ef426042 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 29 Dec 2022 15:04:49 -0500
Subject: [PATCH] DISABLE/ENABLE/QUERY functions were split into getters and
 setters.

---
 src/sdl2_compat.c | 71 +++++++++++++++++++++++++++++++++++++++++++----
 src/sdl3_syms.h   | 14 ++++++----
 2 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 5fc1006..741d235 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -614,6 +614,11 @@ typedef struct SDL2_RWops
 /* removed in SDL3 (which only uses SDL_WINDOW_HIDDEN now). */
 #define SDL2_WINDOW_SHOWN 0x000000004
 
+/* removed in SDL3 (APIs like this were split into getter/setter functions). */
+#define SDL2_QUERY   -1
+#define SDL2_DISABLE  0
+#define SDL2_ENABLE   1
+
 /* this enum changed in SDL3. */
 typedef enum
 {
@@ -1293,7 +1298,7 @@ EventFilter3to2(void *userdata, SDL_Event *event3)
         case SDL_DISPLAYEVENT_ORIENTATION:
         case SDL_DISPLAYEVENT_CONNECTED:
         case SDL_DISPLAYEVENT_DISCONNECTED:
-            if (SDL3_GetEventState(SDL2_DISPLAYEVENT) == SDL_ENABLE) {
+            if (SDL3_EventEnabled(SDL2_DISPLAYEVENT)) {
                 event2.display.type = SDL2_DISPLAYEVENT;
                 event2.display.timestamp = (Uint32) SDL_NS_TO_MS(event3->display.timestamp);
                 event2.display.display = event3->display.display;
@@ -1325,7 +1330,7 @@ EventFilter3to2(void *userdata, SDL_Event *event3)
         case SDL_WINDOWEVENT_HIT_TEST:
         case SDL_WINDOWEVENT_ICCPROF_CHANGED:
         case SDL_WINDOWEVENT_DISPLAY_CHANGED:
-            if (SDL3_GetEventState(SDL2_WINDOWEVENT) == SDL_ENABLE) {
+            if (SDL3_EventEnabled(SDL2_WINDOWEVENT)) {
                 event2.window.type = SDL2_WINDOWEVENT;
                 event2.window.timestamp = (Uint32) SDL_NS_TO_MS(event3->window.timestamp);
                 event2.window.windowID = event3->window.windowID;
@@ -2513,7 +2518,7 @@ static float GestureDollarRecognize(const GestureDollarPath *path, int *bestTemp
 
 static void GestureSendMulti(GestureTouch *touch, float dTheta, float dDist)
 {
-    if (SDL3_GetEventState(SDL_MULTIGESTURE) == SDL_ENABLE) {
+    if (SDL3_EventEnabled(SDL_MULTIGESTURE)) {
         SDL2_Event event;
         event.type = SDL_MULTIGESTURE;
         event.common.timestamp = 0;
@@ -2529,7 +2534,7 @@ static void GestureSendMulti(GestureTouch *touch, float dTheta, float dDist)
 
 static void GestureSendDollar(GestureTouch *touch, SDL_GestureID gestureId, float error)
 {
-    if (SDL3_GetEventState(SDL_DOLLARGESTURE) == SDL_ENABLE) {
+    if (SDL3_EventEnabled(SDL_DOLLARGESTURE)) {
         SDL2_Event event;
         event.type = SDL_DOLLARGESTURE;
         event.common.timestamp = 0;
@@ -2546,7 +2551,7 @@ static void GestureSendDollar(GestureTouch *touch, SDL_GestureID gestureId, floa
 
 static void GestureSendDollarRecord(GestureTouch *touch, SDL_GestureID gestureId)
 {
-    if (SDL3_GetEventState(SDL_DOLLARRECORD) == SDL_ENABLE) {
+    if (SDL3_EventEnabled(SDL_DOLLARRECORD)) {
         SDL2_Event event;
         event.type = SDL_DOLLARRECORD;
         event.common.timestamp = 0;
@@ -2908,6 +2913,62 @@ SDL_GL_SwapWindow(SDL_Window *window)
     (void) SDL3_GL_SwapWindow(window);
 }
 
+/* SDL3 split this into getter/setter functions. */
+DECLSPEC Uint8 SDLCALL
+SDL_EventState(Uint32 type, int state)
+{
+    const int retval = SDL3_EventEnabled(type) ? SDL2_ENABLE : SDL2_DISABLE;
+    if (state == SDL2_ENABLE) {
+        SDL3_SetEventEnabled(type, SDL_TRUE);
+    } else if (state == SDL2_DISABLE) {
+        SDL3_SetEventEnabled(type, SDL_FALSE);
+    }
+    return retval;
+}
+
+/* SDL3 split this into getter/setter functions. */
+DECLSPEC int SDLCALL
+SDL_ShowCursor(int state)
+{
+    int retval = SDL3_CursorVisible() ? SDL2_ENABLE : SDL2_DISABLE;
+    if ((state == SDL2_ENABLE) && (SDL3_ShowCursor() < 0)) {
+        retval = -1;
+    } else if ((state == SDL2_DISABLE) && (SDL3_HideCursor() < 0)) {
+        retval = -1;
+    }
+    return retval;
+}
+
+/* SDL3 split this into getter/setter functions. */
+DECLSPEC int SDLCALL
+SDL_GameControllerEventState(int state)
+{
+    int retval = state;
+    if (state == SDL2_ENABLE) {
+        SDL3_SetGamepadEventsEnabled(SDL_TRUE);
+    } else if (state == SDL2_DISABLE) {
+        SDL3_SetGamepadEventsEnabled(SDL_FALSE);
+    } else {
+        retval = SDL3_GamepadEventsEnabled() ? SDL2_ENABLE : SDL2_DISABLE;
+    }
+    return retval;
+}
+
+/* SDL3 split this into getter/setter functions. */
+DECLSPEC int SDLCALL
+SDL_JoystickEventState(int state)
+{
+    int retval = state;
+    if (state == SDL2_ENABLE) {
+        SDL3_SetJoystickEventsEnabled(SDL_TRUE);
+    } else if (state == SDL2_DISABLE) {
+        SDL3_SetJoystickEventsEnabled(SDL_FALSE);
+    } else {
+        retval = SDL3_JoystickEventsEnabled() ? SDL2_ENABLE : SDL2_DISABLE;
+    }
+    return retval;
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 4059fed..737e1f0 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -151,7 +151,6 @@ SDL3_SYM(SDL_bool,GetEventFilter,(SDL_EventFilter *a, void **b),(a,b),return)
 SDL3_SYM(void,AddEventWatch,(SDL_EventFilter a, void *b),(a,b),)
 SDL3_SYM(void,DelEventWatch,(SDL_EventFilter a, void *b),(a,b),)
 SDL3_SYM(void,FilterEvents,(SDL_EventFilter a, void *b),(a,b),)
-SDL3_SYM_PASSTHROUGH(Uint8,EventState,(Uint32 a, int b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(Uint32,RegisterEvents,(int a),(a),return)
 SDL3_SYM_PASSTHROUGH(char*,GetBasePath,(void),(),return)
 SDL3_SYM_PASSTHROUGH(char*,GetPrefPath,(const char *a, const char *b),(a,b),return)
@@ -164,7 +163,6 @@ SDL3_SYM_RENAMED(SDL_GameController*,GameControllerOpen,OpenGamepad,(int a),(a),
 SDL3_SYM_RENAMED(const char*,GameControllerName,GetGamepadName,(SDL_GameController *a),(a),return)
 SDL3_SYM_RENAMED(SDL_bool,GameControllerGetAttached,GamepadConnected,(SDL_GameController *a),(a),return)
 SDL3_SYM_RENAMED(SDL_Joystick*,GameControllerGetJoystick,GetGamepadJoystick,(SDL_GameController *a),(a),return)
-SDL3_SYM_RENAMED(int,GameControllerEventState,GetGamepadEventState,(int a),(a),return)
 SDL3_SYM_RENAMED(void,GameControllerUpdate,UpdateGamepads,(void),(),)
 SDL3_SYM_RENAMED(SDL_GameControllerAxis,GameControllerGetAxisFromString,GetGamepadAxisFromString,(const char *a),(a),return)
 SDL3_SYM_RENAMED(const char*,GameControllerGetStringForAxis,GetGamepadStringForAxis,(SDL_GameControllerAxis a),(a),return)
@@ -225,7 +223,6 @@ SDL3_SYM_RENAMED(int,JoystickNumAxes,GetNumJoystickAxes,(SDL_Joystick *a),(a),re
 SDL3_SYM_RENAMED(int,JoystickNumHats,GetNumJoystickHats,(SDL_Joystick *a),(a),return)
 SDL3_SYM_RENAMED(int,JoystickNumButtons,GetNumJoystickButtons,(SDL_Joystick *a),(a),return)
 SDL3_SYM_RENAMED(void,JoystickUpdate,UpdateJoysticks,(void),(),)
-SDL3_SYM_RENAMED(int,JoystickEventState,GetJoystickEventState,(int a),(a),return)
 SDL3_SYM_RENAMED(Sint16,JoystickGetAxis,GetJoystickAxis,(SDL_Joystick *a, int b),(a,b),return)
 SDL3_SYM_RENAMED(Uint8,JoystickGetHat,GetJoystickHat,(SDL_Joystick *a, int b),(a,b),return)
 SDL3_SYM_RENAMED(Uint8,JoystickGetButton,GetJoystickButton,(SDL_Joystick *a, int b),(a,b),return)
@@ -272,7 +269,6 @@ SDL3_SYM_PASSTHROUGH(void,SetCursor,(SDL_Cursor *a),(a),)
 SDL3_SYM_PASSTHROUGH(SDL_Cursor*,GetCursor,(void),(),return)
 SDL3_SYM_PASSTHROUGH(SDL_Cursor*,GetDefaultCursor,(void),(),return)
 SDL3_SYM_PASSTHROUGH(void,FreeCursor,(SDL_Cursor *a),(a),)
-SDL3_SYM_PASSTHROUGH(int,ShowCursor,(int a),(a),return)
 SDL3_SYM_PASSTHROUGH(SDL_mutex*,CreateMutex,(void),(),return)
 SDL3_SYM_PASSTHROUGH(int,LockMutex,(SDL_mutex *a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,TryLockMutex,(SDL_mutex *a),(a),return)
@@ -938,7 +934,15 @@ SDL3_SYM_PASSTHROUGH(char*,GetPrimarySelectionText,(void),(),return)
 SDL3_SYM_PASSTHROUGH(SDL_bool,HasPrimarySelectionText,(void),(),return)
 SDL3_SYM_PASSTHROUGH(void,ResetHints,(void),(),)
 SDL3_SYM_PASSTHROUGH(char*,strcasestr,(const char *a, const char *b),(a,b),return)
-SDL3_SYM_PASSTHROUGH(Uint8,GetEventState,(Uint32 a),(a),return)
+SDL3_SYM(void,SetEventEnabled,(Uint32 a, SDL_bool b),(a,b),)
+SDL3_SYM(SDL_bool,EventEnabled,(Uint32 a),(a),return)
+SDL3_SYM(void,SetGamepadEventsEnabled,(SDL_bool a),(a),)
+SDL3_SYM(SDL_bool,GamepadEventsEnabled,(void),(),return)
+SDL3_SYM(void,SetJoystickEventsEnabled,(SDL_bool a),(a),)
+SDL3_SYM(SDL_bool,JoystickEventsEnabled,(void),(),return)
+SDL3_SYM(int,ShowCursor,(void),(),return)
+SDL3_SYM(int,HideCursor,(void),(),return)
+SDL3_SYM(SDL_bool,CursorVisible,(void),(),return)
 
 #undef SDL3_SYM
 #undef SDL3_SYM_PASSTHROUGH