From 7ca0d15d64edd29f4ad6aae9bdd45e7d3c0c3123 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 8 Dec 2022 00:08:51 -0500
Subject: [PATCH] events: Changed SDL_GetEventState from a macro to a function.
Fixes #6773.
---
docs/README-migration.md | 2 ++
include/SDL3/SDL_events.h | 22 ++++++++++++++++++++--
src/dynapi/SDL_dynapi.sym | 1 +
src/dynapi/SDL_dynapi_overrides.h | 1 +
src/dynapi/SDL_dynapi_procs.h | 1 +
src/events/SDL_events.c | 8 ++++++--
6 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 2c95b31184aa..25ab3a25ab43 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -56,6 +56,8 @@ The `timestamp_us` member of the sensor events has been renamed `sensor_timestam
You should set the `event.common.timestamp` field before passing an event to `SDL_PushEvent()`. If the timestamp is 0 it will be filled in with `SDL_GetTicksNS()`.
+SDL_GetEventState used to be a macro, now it's a real function, but otherwise functions identically.
+
## SDL_gamecontroller.h
diff --git a/include/SDL3/SDL_events.h b/include/SDL3/SDL_events.h
index a666c2d0d23f..defcba5ad179 100644
--- a/include/SDL3/SDL_events.h
+++ b/include/SDL3/SDL_events.h
@@ -1097,7 +1097,7 @@ extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
#define SDL_ENABLE 1
/**
- * Set the state of processing events by type.
+ * Set or query the state of processing events by type.
*
* `state` may be any of the following:
*
@@ -1116,8 +1116,26 @@ extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
* \sa SDL_GetEventState
*/
extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
+
+/**
+ * Query the state of processing events by type.
+ *
+ * This is equivalent to calling `SDL_EventState(type, SDL_QUERY)`.
+ *
+ * In SDL3, this is a proper function, but in SDL2, this was a macro.
+ *
+ * \param type the type of event; see SDL_EventType for details
+ * \returns `SDL_DISABLE` or `SDL_ENABLE`, representing the processing state
+ * of the event before this function makes any changes to it.
+ *
+ * \since This function is available since SDL 3.0.0.
+ *
+ * \sa SDL_EventState
+ */
+extern DECLSPEC Uint8 SDLCALL SDL_GetEventState(Uint32 type);
+
/* @} */
-#define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
+
/**
* Allocate a set of user-defined events, and return the beginning event
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index 948c6168f9b5..f8355809430f 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -864,6 +864,7 @@ SDL3_0.0.0 {
SDL_GetPowerInfo;
SDL_GetTicksNS;
SDL_DelayNS;
+ SDL_GetEventState;
# extra symbols go here (don't modify this line)
local: *;
};
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index d8249bb187c0..1139766b7f6a 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -888,3 +888,4 @@
#define SDL_memset4 SDL_memset4_REAL
#define SDL_GetTicksNS SDL_GetTicksNS_REAL
#define SDL_DelayNS SDL_DelayNS_REAL
+#define SDL_GetEventState SDL_GetEventState_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 53dede94f57f..5b2701d63e5e 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -964,3 +964,4 @@ SDL_DYNAPI_PROC(int,SDL_GetWindowWMInfo,(SDL_Window *a, SDL_SysWMinfo *b, Uint32
SDL_DYNAPI_PROC(void*,SDL_memset4,(void *a, Uint32 b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(Uint64,SDL_GetTicksNS,(void),(),return)
SDL_DYNAPI_PROC(void,SDL_DelayNS,(Uint64 a),(a),)
+SDL_DYNAPI_PROC(Uint8,SDL_GetEventState,(Uint32 a),(a),return)
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 07adf42c9dc8..bfad6e04641c 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -1388,8 +1388,12 @@ Uint8 SDL_EventState(Uint32 type, int state)
return current_state;
}
-Uint32
-SDL_RegisterEvents(int numevents)
+Uint8 SDL_GetEventState(Uint32 type)
+{
+ return SDL_EventState(type, SDL_QUERY);
+}
+
+Uint32 SDL_RegisterEvents(int numevents)
{
Uint32 event_base;