SDL_EventFilter functions now return SDL_bool

This commit is contained in:
Sam Lantinga 2024-08-06 07:36:42 -07:00
parent 57f9c6f7bb
commit 627cb8acd0
8 changed files with 20 additions and 18 deletions

View File

@ -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_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: The following symbols have been renamed:
* SDL_APP_DIDENTERBACKGROUND => SDL_EVENT_DID_ENTER_BACKGROUND * SDL_APP_DIDENTERBACKGROUND => SDL_EVENT_DID_ENTER_BACKGROUND
* SDL_APP_DIDENTERFOREGROUND => SDL_EVENT_DID_ENTER_FOREGROUND * SDL_APP_DIDENTERFOREGROUND => SDL_EVENT_DID_ENTER_FOREGROUND

View File

@ -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 * \param userdata what was passed as `userdata` to SDL_SetEventFilter() or
* SDL_AddEventWatch, etc. * SDL_AddEventWatch, etc.
* \param event the event that triggered the callback. * \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. * When used with SDL_AddEventWatch, the return value is ignored.
* *
* \threadsafety SDL may call this callback at any time from any thread; the * \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_SetEventFilter
* \sa SDL_AddEventWatch * \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 * Set up a filter to process all events before they change internal state and
* are posted to the internal event queue. * are posted to the internal event queue.
* *
* If the filter function returns 1 when called, then the event will be added * If the filter function returns SDL_TRUE when called, then the event will be added
* to the internal queue. If it returns 0, then the event will be dropped from * 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 * the queue, but the internal state will still be updated. This allows
* selective filtering of dynamically arriving events. * 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 * 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(), * See SDL_SetEventFilter() for more information. Unlike SDL_SetEventFilter(),
* this function does not change the filter permanently, it only uses the * this function does not change the filter permanently, it only uses the

View File

@ -26,16 +26,16 @@
#include "SDL_mouse_c.h" #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; SDL_Event *new_event = (SDL_Event *)userdata;
if (event->type == new_event->type && if (event->type == new_event->type &&
event->window.windowID == new_event->window.windowID) { event->window.windowID == new_event->window.windowID) {
/* We're about to post a new move event, drop the old one */ /* 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, int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,

View File

@ -363,7 +363,7 @@ static void SDL_PrivateGamepadRemapped(SDL_JoystickID instance_id)
/* /*
* Event filter to fire gamepad events from joystick ones * 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; SDL_Gamepad *gamepad;
@ -422,7 +422,7 @@ static int SDLCALL SDL_GamepadEventWatcher(void *userdata, SDL_Event *event)
break; break;
} }
return 1; return SDL_TRUE;
} }
/* SDL defines sensor orientation relative to the device natural /* SDL defines sensor orientation relative to the device natural

View File

@ -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)) { if (ShouldDispatchImmediately(event)) {
// Make sure any currently queued events are processed then dispatch this before continuing // 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 { } else {
// We'll process this event later from the main event queue // We'll process this event later from the main event queue
} }
return 0; return SDL_TRUE;
} }
SDL_bool SDL_HasMainCallbacks(void) SDL_bool SDL_HasMainCallbacks(void)

View File

@ -818,7 +818,7 @@ const char *SDL_GetRenderDriver(int index)
#endif #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; SDL_Renderer *renderer = (SDL_Renderer *)userdata;
@ -855,7 +855,7 @@ static int SDLCALL SDL_RendererEventWatch(void *userdata, SDL_Event *event)
UpdateHDRProperties(renderer); 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) int SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer)

View File

@ -9,12 +9,12 @@
static int clipboard_update_count; 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) { if (event->type == SDL_EVENT_CLIPBOARD_UPDATE) {
++clipboard_update_count; ++clipboard_update_count;
} }
return 0; return SDL_TRUE;
} }
enum enum

View File

@ -25,7 +25,7 @@ static int g_userdataValue2 = 2;
#define MAX_ITERATIONS 100 #define MAX_ITERATIONS 100
/* Event filter that sets some flags and optionally checks userdata */ /* 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; g_eventFilterCalled = 1;
@ -36,7 +36,7 @@ static int SDLCALL events_sampleNullEventFilter(void *userdata, SDL_Event *event
} }
} }
return 0; return SDL_TRUE;
} }
/** /**