From 627cb8acd09e6cbf8362d808634a26f37382c73d Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 6 Aug 2024 07:36:42 -0700
Subject: [PATCH] SDL_EventFilter functions now return SDL_bool
---
docs/README-migration.md | 2 ++
include/SDL3/SDL_events.h | 10 +++++-----
src/events/SDL_windowevents.c | 6 +++---
src/joystick/SDL_gamepad.c | 4 ++--
src/main/SDL_main_callbacks.c | 4 ++--
src/render/SDL_render.c | 4 ++--
test/testautomation_clipboard.c | 4 ++--
test/testautomation_events.c | 4 ++--
8 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 56e843961c96e..aebcd7ecb7d04 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -379,6 +379,8 @@ SDL_AddEventWatch() now returns -1 if it fails because it ran out of memory and
SDL_RegisterEvents() now returns 0 if it couldn't allocate any user events.
+SDL_EventFilter functions now return SDL_bool.
+
The following symbols have been renamed:
* SDL_APP_DIDENTERBACKGROUND => SDL_EVENT_DID_ENTER_BACKGROUND
* SDL_APP_DIDENTERFOREGROUND => SDL_EVENT_DID_ENTER_FOREGROUND
diff --git a/include/SDL3/SDL_events.h b/include/SDL3/SDL_events.h
index 4c113f9a3efce..6e5a305e51003 100644
--- a/include/SDL3/SDL_events.h
+++ b/include/SDL3/SDL_events.h
@@ -1218,7 +1218,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event);
* \param userdata what was passed as `userdata` to SDL_SetEventFilter() or
* SDL_AddEventWatch, etc.
* \param event the event that triggered the callback.
- * \returns 1 to permit event to be added to the queue, and 0 to disallow it.
+ * \returns SDL_TRUE to permit event to be added to the queue, and SDL_FALSE to disallow it.
* When used with SDL_AddEventWatch, the return value is ignored.
*
* \threadsafety SDL may call this callback at any time from any thread; the
@@ -1230,14 +1230,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event);
* \sa SDL_SetEventFilter
* \sa SDL_AddEventWatch
*/
-typedef int (SDLCALL *SDL_EventFilter)(void *userdata, SDL_Event *event);
+typedef SDL_bool (SDLCALL *SDL_EventFilter)(void *userdata, SDL_Event *event);
/**
* Set up a filter to process all events before they change internal state and
* are posted to the internal event queue.
*
- * If the filter function returns 1 when called, then the event will be added
- * to the internal queue. If it returns 0, then the event will be dropped from
+ * If the filter function returns SDL_TRUE when called, then the event will be added
+ * to the internal queue. If it returns SDL_FALSE, then the event will be dropped from
* the queue, but the internal state will still be updated. This allows
* selective filtering of dynamically arriving events.
*
@@ -1346,7 +1346,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter, void
/**
* Run a specific filter function on the current event queue, removing any
- * events for which the filter returns 0.
+ * events for which the filter returns SDL_FALSE.
*
* See SDL_SetEventFilter() for more information. Unlike SDL_SetEventFilter(),
* this function does not change the filter permanently, it only uses the
diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c
index 80fd511c151be..262f3da27c58a 100644
--- a/src/events/SDL_windowevents.c
+++ b/src/events/SDL_windowevents.c
@@ -26,16 +26,16 @@
#include "SDL_mouse_c.h"
-static int SDLCALL RemoveSupercededWindowEvents(void *userdata, SDL_Event *event)
+static SDL_bool SDLCALL RemoveSupercededWindowEvents(void *userdata, SDL_Event *event)
{
SDL_Event *new_event = (SDL_Event *)userdata;
if (event->type == new_event->type &&
event->window.windowID == new_event->window.windowID) {
/* We're about to post a new move event, drop the old one */
- return 0;
+ return SDL_FALSE;
}
- return 1;
+ return SDL_TRUE;
}
int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c
index 0d9648ab0463f..d08d83b24a928 100644
--- a/src/joystick/SDL_gamepad.c
+++ b/src/joystick/SDL_gamepad.c
@@ -363,7 +363,7 @@ static void SDL_PrivateGamepadRemapped(SDL_JoystickID instance_id)
/*
* Event filter to fire gamepad events from joystick ones
*/
-static int SDLCALL SDL_GamepadEventWatcher(void *userdata, SDL_Event *event)
+static SDL_bool SDLCALL SDL_GamepadEventWatcher(void *userdata, SDL_Event *event)
{
SDL_Gamepad *gamepad;
@@ -422,7 +422,7 @@ static int SDLCALL SDL_GamepadEventWatcher(void *userdata, SDL_Event *event)
break;
}
- return 1;
+ return SDL_TRUE;
}
/* SDL defines sensor orientation relative to the device natural
diff --git a/src/main/SDL_main_callbacks.c b/src/main/SDL_main_callbacks.c
index f867b62ba9e60..c247632fc5583 100644
--- a/src/main/SDL_main_callbacks.c
+++ b/src/main/SDL_main_callbacks.c
@@ -69,7 +69,7 @@ static void SDL_DispatchMainCallbackEvents(void)
}
}
-static int SDLCALL SDL_MainCallbackEventWatcher(void *userdata, SDL_Event *event)
+static SDL_bool SDLCALL SDL_MainCallbackEventWatcher(void *userdata, SDL_Event *event)
{
if (ShouldDispatchImmediately(event)) {
// Make sure any currently queued events are processed then dispatch this before continuing
@@ -78,7 +78,7 @@ static int SDLCALL SDL_MainCallbackEventWatcher(void *userdata, SDL_Event *event
} else {
// We'll process this event later from the main event queue
}
- return 0;
+ return SDL_TRUE;
}
SDL_bool SDL_HasMainCallbacks(void)
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 17b24a171d21e..5886a286ec5c7 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -818,7 +818,7 @@ const char *SDL_GetRenderDriver(int index)
#endif
}
-static int SDLCALL SDL_RendererEventWatch(void *userdata, SDL_Event *event)
+static SDL_bool SDLCALL SDL_RendererEventWatch(void *userdata, SDL_Event *event)
{
SDL_Renderer *renderer = (SDL_Renderer *)userdata;
@@ -855,7 +855,7 @@ static int SDLCALL SDL_RendererEventWatch(void *userdata, SDL_Event *event)
UpdateHDRProperties(renderer);
}
- return 0;
+ return SDL_TRUE;
}
int SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer)
diff --git a/test/testautomation_clipboard.c b/test/testautomation_clipboard.c
index 1b67434f184c5..5b1c4a4f39a5f 100644
--- a/test/testautomation_clipboard.c
+++ b/test/testautomation_clipboard.c
@@ -9,12 +9,12 @@
static int clipboard_update_count;
-static int ClipboardEventWatch(void *userdata, SDL_Event *event)
+static SDL_bool ClipboardEventWatch(void *userdata, SDL_Event *event)
{
if (event->type == SDL_EVENT_CLIPBOARD_UPDATE) {
++clipboard_update_count;
}
- return 0;
+ return SDL_TRUE;
}
enum
diff --git a/test/testautomation_events.c b/test/testautomation_events.c
index b7fae05d5c73f..71c4de8e84c56 100644
--- a/test/testautomation_events.c
+++ b/test/testautomation_events.c
@@ -25,7 +25,7 @@ static int g_userdataValue2 = 2;
#define MAX_ITERATIONS 100
/* Event filter that sets some flags and optionally checks userdata */
-static int SDLCALL events_sampleNullEventFilter(void *userdata, SDL_Event *event)
+static SDL_bool SDLCALL events_sampleNullEventFilter(void *userdata, SDL_Event *event)
{
g_eventFilterCalled = 1;
@@ -36,7 +36,7 @@ static int SDLCALL events_sampleNullEventFilter(void *userdata, SDL_Event *event
}
}
- return 0;
+ return SDL_TRUE;
}
/**