diff --git a/docs/README-migration.md b/docs/README-migration.md index 8d3e77c740..d42785155c 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -82,12 +82,11 @@ 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. - The `SDL_DISPLAYEVENT_*` events have been moved to top level events, and `SDL_DISPLAYEVENT` has been removed. In general, handling this change just means checking for the individual events instead of first checking for `SDL_DISPLAYEVENT` and then checking for display events. You can compare the event >= `SDL_DISPLAYEVENT_FIRST` and <= `SDL_DISPLAYEVENT_LAST` if you need to see whether it's a display event. The `SDL_WINDOWEVENT_*` events have been moved to top level events, and `SDL_WINDOWEVENT` has been removed. In general, handling this change just means checking for the individual events instead of first checking for `SDL_WINDOWEVENT` and then checking for window events. You can compare the event >= `SDL_WINDOWEVENT_FIRST` and <= `SDL_WINDOWEVENT_LAST` if you need to see whether it's a window event. +`SDL_QUERY`, `SDL_IGNORE`, `SDL_ENABLE`, and `SDL_DISABLE` have been removed. You can use the functions SDL_SetEventEnabled() and SDL_EventEnabled() to set and query event processing state. The following symbols have been renamed: * SDL_CONTROLLERAXISMOTION => SDL_GAMEPADAXISMOTION @@ -108,6 +107,10 @@ The following structures have been renamed: * SDL_ControllerSensorEvent => SDL_GamepadSensorEvent * SDL_ControllerTouchpadEvent => SDL_GamepadTouchpadEvent +The following functions have been removed: +* SDL_EventState() - replaced with SDL_SetEventEnabled() +* SDL_GetEventState() - replaced with SDL_EventEnabled() + ## SDL_gamecontroller.h SDL_gamecontroller.h has been renamed SDL_gamepad.h, and all APIs have been renamed to match. @@ -133,7 +136,6 @@ The following functions have been renamed: * SDL_GameControllerAddMappingsFromFile => SDL_AddGamepadMappingsFromFile * SDL_GameControllerAddMappingsFromRW => SDL_AddGamepadMappingsFromRW * SDL_GameControllerClose => SDL_CloseGamepad -* SDL_GameControllerEventState => SDL_GetGamepadEventState * SDL_GameControllerFromInstanceID => SDL_GetGamepadFromInstanceID * SDL_GameControllerFromPlayerIndex => SDL_GetGamepadFromPlayerIndex * SDL_GameControllerGetAppleSFSymbolsNameForAxis => SDL_GetGamepadAppleSFSymbolsNameForAxis @@ -184,10 +186,11 @@ The following functions have been renamed: * SDL_IsGameController => SDL_IsGamepad The following functions have been removed: +* SDL_GameControllerEventState - replaced with SDL_SetGamepadEventsEnabled() and SDL_GamepadEventsEnabled() +* SDL_GameControllerMappingForDeviceIndex() - replaced with SDL_GetGamepadInstanceMapping() * SDL_GameControllerNameForIndex() - replaced with SDL_GetGamepadInstanceName() * SDL_GameControllerPathForIndex() - replaced with SDL_GetGamepadInstancePath() * SDL_GameControllerTypeForIndex() - replaced with SDL_GetGamepadInstanceType() -* SDL_GameControllerMappingForDeviceIndex() - replaced with SDL_GetGamepadInstanceMapping() The following symbols have been renamed: * SDL_CONTROLLER_AXIS_INVALID => SDL_GAMEPAD_AXIS_INVALID @@ -302,7 +305,6 @@ The following functions have been renamed: * SDL_JoystickClose => SDL_CloseJoystick * SDL_JoystickCurrentPowerLevel => SDL_GetJoystickPowerLevel * SDL_JoystickDetachVirtual => SDL_DetachVirtualJoystick -* SDL_JoystickEventState => SDL_GetJoystickEventState * SDL_JoystickFromInstanceID => SDL_GetJoystickFromInstanceID * SDL_JoystickFromPlayerIndex => SDL_GetJoystickFromPlayerIndex * SDL_JoystickGetAttached => SDL_IsJoystickConnected @@ -342,7 +344,7 @@ The following symbols have been renamed: * SDL_JOYSTICK_TYPE_GAMECONTROLLER => SDL_JOYSTICK_TYPE_GAMEPAD The following functions have been removed: -* SDL_NumJoysticks - replaced with SDL_HasJoysticks() and SDL_GetJoysticks() +* SDL_JoystickEventState - replaced with SDL_SetJoystickEventsEnabled() and SDL_JoystickEventsEnabled() * SDL_JoystickGetDeviceGUID() - replaced with SDL_GetJoystickInstanceGUID() * SDL_JoystickGetDeviceInstanceID() * SDL_JoystickGetDevicePlayerIndex() - replaced with SDL_GetJoystickInstancePlayerIndex() @@ -352,6 +354,7 @@ The following functions have been removed: * SDL_JoystickGetDeviceVendor() - replaced with SDL_GetJoystickInstanceVendor() * SDL_JoystickNameForIndex() - replaced with SDL_GetJoystickInstanceName() * SDL_JoystickPathForIndex() - replaced with SDL_GetJoystickInstancePath() +* SDL_NumJoysticks - replaced with SDL_HasJoysticks() and SDL_GetJoysticks() ## SDL_keycode.h @@ -404,6 +407,10 @@ Furthermore, the different `SDL_*RunApp()` functions (SDL_WinRtRunApp, SDL_GDKRu have been unified into just `int SDL_RunApp(int argc, char* argv[], void * reserved)` (which is also used by additional platforms that didn't have a SDL_RunApp-like function before). +## SDL_mouse.h + +SDL_ShowCursor() has been split into three functions: SDL_ShowCursor(), SDL_HideCursor(), and SDL_CursorVisible() + ## SDL_pixels.h SDL_CalculateGammaRamp has been removed, because SDL_SetWindowGammaRamp has been removed as well due to poor support in modern operating systems (see [SDL_video.h](#sdl_videoh)). diff --git a/include/SDL3/SDL_events.h b/include/SDL3/SDL_events.h index 44923e1ec6..6e068ff40c 100644 --- a/include/SDL3/SDL_events.h +++ b/include/SDL3/SDL_events.h @@ -516,7 +516,7 @@ typedef struct SDL_TouchFingerEvent /** * \brief An event used to request a file open by the system (event.drop.*) - * This event is enabled by default, you can disable it with SDL_EventState(). + * This event is enabled by default, you can disable it with SDL_SetEventEnabled(). * \note If this event is enabled, you must free the filename in the event. */ typedef struct SDL_DropEvent @@ -577,7 +577,7 @@ typedef struct SDL_SysWMmsg SDL_SysWMmsg; /** * \brief A video driver dependent system event (event.syswm.*) - * This event is disabled by default, you can enable it with SDL_EventState() + * This event is disabled by default, you can enable it with SDL_SetEventEnabled() * * \note If you want to use this event, you should include SDL_syswm.h. */ @@ -969,7 +969,7 @@ typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event); * closed, otherwise the window will remain open if possible. * * Note: Disabled events never make it to the event filter function; see - * SDL_EventState(). + * SDL_SetEventEnabled(). * * Note: If you just want to inspect events without filtering, you should use * SDL_AddEventWatch() instead. @@ -984,7 +984,7 @@ typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event); * \since This function is available since SDL 3.0.0. * * \sa SDL_AddEventWatch - * \sa SDL_EventState + * \sa SDL_SetEventEnabled * \sa SDL_GetEventFilter * \sa SDL_PeepEvents * \sa SDL_PushEvent @@ -1074,52 +1074,29 @@ extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter, extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter, void *userdata); -/* @{ */ -#define SDL_QUERY -1 -#define SDL_IGNORE 0 -#define SDL_DISABLE 0 -#define SDL_ENABLE 1 - /** - * Set or query the state of processing events by type. - * - * `state` may be any of the following: - * - * - `SDL_QUERY`: returns the current processing state of the specified event - * - `SDL_IGNORE` (aka `SDL_DISABLE`): the event will automatically be dropped - * from the event queue and will not be filtered - * - `SDL_ENABLE`: the event will be processed normally + * Set the state of processing events by type. * * \param type the type of event; see SDL_EventType for details - * \param state how to process the event - * \returns `SDL_DISABLE` or `SDL_ENABLE`, representing the processing state - * of the event before this function makes any changes to it. + * \param state whether to process the event or not * * \since This function is available since SDL 3.0.0. * - * \sa SDL_GetEventState + * \sa SDL_IsEventEnabled */ -extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state); +extern DECLSPEC void SDLCALL SDL_SetEventEnabled(Uint32 type, SDL_bool enabled); /** * 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. + * \returns SDL_TRUE if the event is being processed, SDL_FALSE otherwise. * * \since This function is available since SDL 3.0.0. * - * \sa SDL_EventState + * \sa SDL_SetEventEnabled */ -extern DECLSPEC Uint8 SDLCALL SDL_GetEventState(Uint32 type); - -/* @} */ - +extern DECLSPEC SDL_bool SDLCALL SDL_EventEnabled(Uint32 type); /** * Allocate a set of user-defined events, and return the beginning event diff --git a/include/SDL3/SDL_gamepad.h b/include/SDL3/SDL_gamepad.h index ba84ada1b7..a1dcf89366 100644 --- a/include/SDL3/SDL_gamepad.h +++ b/include/SDL3/SDL_gamepad.h @@ -184,7 +184,7 @@ typedef struct SDL_GamepadBinding extern DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mappingString); /** - * Load a set of Game Controller mappings from a seekable SDL data stream. + * Load a set of gamepad mappings from a seekable SDL data stream. * * You can call this function several times, if needed, to load different * database files. @@ -256,7 +256,7 @@ extern DECLSPEC char * SDLCALL SDL_GetGamepadMappingForIndex(int mapping_index); extern DECLSPEC char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid); /** - * Get the current mapping of a Game Controller. + * Get the current mapping of a gamepad. * * The returned string must be freed with SDL_free(). * @@ -649,24 +649,34 @@ extern DECLSPEC SDL_bool SDLCALL SDL_IsGamepadConnected(SDL_Gamepad *gamepad); extern DECLSPEC SDL_Joystick *SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad); /** - * Query or change current state of Game Controller events. + * Set the state of gamepad event processing. * * If gamepad events are disabled, you must call SDL_UpdateGamepads() * yourself and check the state of the gamepad when you want gamepad * information. * - * Any number can be passed to SDL_GetGamepadEventState(), but only -1, 0, - * and 1 will have any effect. Other numbers will just be returned. - * - * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE` - * \returns the same value passed to the function, with exception to -1 - * (SDL_QUERY), which will return the current state. + * \param state whether to process gamepad events or not * * \since This function is available since SDL 3.0.0. * - * \sa SDL_GetJoystickEventState + * \sa SDL_GamepadEventsEnabled */ -extern DECLSPEC int SDLCALL SDL_GetGamepadEventState(int state); +extern DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled); + +/** + * Query the state of gamepad event processing. + * + * If gamepad events are disabled, you must call SDL_UpdateGamepads() + * yourself and check the state of the gamepad when you want gamepad + * information. + * + * \returns SDL_TRUE if gamepad events are being processed, SDL_FALSE otherwise. + * + * \since This function is available since SDL 3.0.0. + * + * \sa SDL_SetGamepadEventsEnabled + */ +extern DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void); /** * Manually pump gamepad updates if not using the loop. diff --git a/include/SDL3/SDL_joystick.h b/include/SDL3/SDL_joystick.h index 75d3ec418d..5e2742e927 100644 --- a/include/SDL3/SDL_joystick.h +++ b/include/SDL3/SDL_joystick.h @@ -107,6 +107,9 @@ typedef enum SDL_JOYSTICK_POWER_MAX } SDL_JoystickPowerLevel; +#define SDL_JOYSTICK_AXIS_MAX 32767 +#define SDL_JOYSTICK_AXIS_MIN -32768 + /* Set max recognized G-force from accelerometer See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed */ @@ -716,6 +719,36 @@ extern DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick); */ extern DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick); +/** + * Set the state of joystick event processing. + * + * If joystick events are disabled, you must call SDL_UpdateJoysticks() + * yourself and check the state of the joystick when you want joystick + * information. + * + * \param state whether to process joystick events or not + * + * \since This function is available since SDL 3.0.0. + * + * \sa SDL_JoystickEventsEnabled + */ +extern DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(SDL_bool enabled); + +/** + * Query the state of joystick event processing. + * + * If joystick events are disabled, you must call SDL_UpdateJoysticks() + * yourself and check the state of the joystick when you want joystick + * information. + * + * \returns SDL_TRUE if joystick events are being processed, SDL_FALSE otherwise. + * + * \since This function is available since SDL 3.0.0. + * + * \sa SDL_SetJoystickEventsEnabled + */ +extern DECLSPEC SDL_bool SDLCALL SDL_JoystickEventsEnabled(void); + /** * Update the current state of the open joysticks. * @@ -723,39 +756,9 @@ extern DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick); * enabled. * * \since This function is available since SDL 3.0.0. - * - * \sa SDL_GetJoystickEventState */ extern DECLSPEC void SDLCALL SDL_UpdateJoysticks(void); -/** - * Enable/disable joystick event polling. - * - * If joystick events are disabled, you must call SDL_UpdateJoysticks() - * yourself and manually check the state of the joystick when you want - * joystick information. - * - * It is recommended that you leave joystick event handling enabled. - * - * **WARNING**: Calling this function may delete all events currently in SDL's - * event queue. - * - * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE` - * \returns 1 if enabled, 0 if disabled, or a negative error code on failure; - * call SDL_GetError() for more information. - * - * If `state` is `SDL_QUERY` then the current state is returned, - * otherwise the new processing state is returned. - * - * \since This function is available since SDL 3.0.0. - * - * \sa SDL_GetGamepadEventState - */ -extern DECLSPEC int SDLCALL SDL_GetJoystickEventState(int state); - -#define SDL_JOYSTICK_AXIS_MAX 32767 -#define SDL_JOYSTICK_AXIS_MIN -32768 - /** * Get the current state of an axis control on a joystick. * diff --git a/include/SDL3/SDL_mouse.h b/include/SDL3/SDL_mouse.h index f74e2b8b32..d986068024 100644 --- a/include/SDL3/SDL_mouse.h +++ b/include/SDL3/SDL_mouse.h @@ -318,7 +318,6 @@ extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void); * * \sa SDL_FreeCursor * \sa SDL_SetCursor - * \sa SDL_ShowCursor */ extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data, const Uint8 * mask, @@ -370,7 +369,6 @@ extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id); * * \sa SDL_CreateCursor * \sa SDL_GetCursor - * \sa SDL_ShowCursor */ extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor); @@ -419,26 +417,43 @@ extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetDefaultCursor(void); extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor); /** - * Toggle whether or not the cursor is shown. + * Show the cursor. * - * The cursor starts off displayed but can be turned off. Passing `SDL_ENABLE` - * displays the cursor and passing `SDL_DISABLE` hides it. - * - * The current state of the mouse cursor can be queried by passing - * `SDL_QUERY`; either `SDL_DISABLE` or `SDL_ENABLE` will be returned. - * - * \param toggle `SDL_ENABLE` to show the cursor, `SDL_DISABLE` to hide it, - * `SDL_QUERY` to query the current state without changing it. - * \returns `SDL_ENABLE` if the cursor is shown, or `SDL_DISABLE` if the - * cursor is hidden, or a negative error code on failure; call + * \returns 0 on success or a negative error code on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * - * \sa SDL_CreateCursor - * \sa SDL_SetCursor + * \sa SDL_CursorVisible + * \sa SDL_HideCursor */ -extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle); +extern DECLSPEC int SDLCALL SDL_ShowCursor(void); + +/** + * Hide the cursor. + * + * \returns 0 on success or a negative error code on failure; call + * SDL_GetError() for more information. + * + * \since This function is available since SDL 3.0.0. + * + * \sa SDL_CursorVisible + * \sa SDL_ShowCursor + */ +extern DECLSPEC int SDLCALL SDL_HideCursor(void); + +/** + * Return whether the cursor is currently being shown. + * + * \returns `SDL_TRUE` if the cursor is being shown, or `SDL_FALSE` if the + * cursor is hidden. + * + * \since This function is available since SDL 3.0.0. + * + * \sa SDL_HideCursor + * \sa SDL_ShowCursor + */ +extern DECLSPEC SDL_bool SDLCALL SDL_CursorVisible(void); /** * Used as a mask when testing buttons in buttonstate. diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h index 4f6e17e9b5..269e27e7f2 100644 --- a/include/SDL3/SDL_oldnames.h +++ b/include/SDL3/SDL_oldnames.h @@ -125,7 +125,6 @@ #define SDL_GameControllerButton SDL_GamepadButton #define SDL_GameControllerButtonBind SDL_GamepadBinding #define SDL_GameControllerClose SDL_CloseGamepad -#define SDL_GameControllerEventState SDL_GetGamepadEventState #define SDL_GameControllerFromInstanceID SDL_GetGamepadFromInstanceID #define SDL_GameControllerFromPlayerIndex SDL_GetGamepadFromPlayerIndex #define SDL_GameControllerGetAppleSFSymbolsNameForAxis SDL_GetGamepadAppleSFSymbolsNameForAxis @@ -184,7 +183,6 @@ #define SDL_JoystickClose SDL_CloseJoystick #define SDL_JoystickCurrentPowerLevel SDL_GetJoystickPowerLevel #define SDL_JoystickDetachVirtual SDL_DetachVirtualJoystick -#define SDL_JoystickEventState SDL_GetJoystickEventState #define SDL_JoystickFromInstanceID SDL_GetJoystickFromInstanceID #define SDL_JoystickFromPlayerIndex SDL_GetJoystickFromPlayerIndex #define SDL_JoystickGetAttached SDL_IsJoystickConnected @@ -437,7 +435,6 @@ #define SDL_GameControllerButton SDL_GameControllerButton_renamed_SDL_GamepadButton #define SDL_GameControllerButtonBind SDL_GameControllerButtonBind_renamed_SDL_GamepadBinding #define SDL_GameControllerClose SDL_GameControllerClose_renamed_SDL_CloseGamepad -#define SDL_GameControllerEventState SDL_GameControllerEventState_renamed_SDL_GetGamepadEventState #define SDL_GameControllerFromInstanceID SDL_GameControllerFromInstanceID_renamed_SDL_GetGamepadFromInstanceID #define SDL_GameControllerFromPlayerIndex SDL_GameControllerFromPlayerIndex_renamed_SDL_GetGamepadFromPlayerIndex #define SDL_GameControllerGetAppleSFSymbolsNameForAxis SDL_GameControllerGetAppleSFSymbolsNameForAxis_renamed_SDL_GetGamepadAppleSFSymbolsNameForAxis @@ -500,7 +497,6 @@ #define SDL_JoystickClose SDL_JoystickClose_renamed_SDL_CloseJoystick #define SDL_JoystickCurrentPowerLevel SDL_JoystickCurrentPowerLevel_renamed_SDL_GetJoystickPowerLevel #define SDL_JoystickDetachVirtual SDL_JoystickDetachVirtual_renamed_SDL_DetachVirtualJoystick -#define SDL_JoystickEventState SDL_JoystickEventState_renamed_SDL_GetJoystickEventState #define SDL_JoystickFromInstanceID SDL_JoystickFromInstanceID_renamed_SDL_GetJoystickFromInstanceID #define SDL_JoystickFromPlayerIndex SDL_JoystickFromPlayerIndex_renamed_SDL_GetJoystickFromPlayerIndex #define SDL_JoystickGetAttached SDL_JoystickGetAttached_renamed_SDL_IsJoystickConnected diff --git a/include/SDL3/SDL_syswm.h b/include/SDL3/SDL_syswm.h index d1b53e646a..36145dbe1b 100644 --- a/include/SDL3/SDL_syswm.h +++ b/include/SDL3/SDL_syswm.h @@ -39,7 +39,7 @@ * Your application has access to a special type of event ::SDL_SYSWMEVENT, * which contains window-manager specific information and arrives whenever * an unhandled window event occurs. This event is ignored by default, but - * you can enable it with SDL_EventState(). + * you can enable it with SDL_SetEventEnabled(). * * As of SDL 3.0, this file no longer includes the platform specific headers * and types. You should include the headers you need and define one or more diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 880975eee7..aee7d8420e 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -412,7 +412,7 @@ void SDL_AddAudioDevice(const SDL_bool iscapture, const char *name, SDL_AudioSpe const int device_index = iscapture ? add_capture_device(name, spec, handle) : add_output_device(name, spec, handle); if (device_index != -1) { /* Post the event, if desired */ - if (SDL_GetEventState(SDL_AUDIODEVICEADDED) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_AUDIODEVICEADDED)) { SDL_Event event; event.type = SDL_AUDIODEVICEADDED; event.common.timestamp = 0; @@ -443,7 +443,7 @@ void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device) current_audio.impl.UnlockDevice(device); /* Post the event, if desired */ - if (SDL_GetEventState(SDL_AUDIODEVICEREMOVED) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_AUDIODEVICEREMOVED)) { SDL_Event event; event.type = SDL_AUDIODEVICEREMOVED; event.common.timestamp = 0; @@ -495,7 +495,7 @@ void SDL_RemoveAudioDevice(const SDL_bool iscapture, void *handle) Note that opened devices will send the non-zero event in SDL_OpenedAudioDeviceDisconnected(). */ if (!device_was_opened) { - if (SDL_GetEventState(SDL_AUDIODEVICEREMOVED) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_AUDIODEVICEREMOVED)) { SDL_Event event; event.type = SDL_AUDIODEVICEREMOVED; event.common.timestamp = 0; diff --git a/src/core/haiku/SDL_BApp.h b/src/core/haiku/SDL_BApp.h index a766411a00..fa108a5c4d 100644 --- a/src/core/haiku/SDL_BApp.h +++ b/src/core/haiku/SDL_BApp.h @@ -260,7 +260,7 @@ class SDL_BApp : public BApplication be_app->HideCursor(); } else { SDL_SendMouseMotion(0, win, 0, 0, x, y); - if (SDL_ShowCursor(-1) && be_app->IsCursorHidden()) + if (SDL_CursorVisible() && be_app->IsCursorHidden()) be_app->ShowCursor(); } } @@ -311,7 +311,7 @@ class SDL_BApp : public BApplication HAIKU_SetKeyState(scancode, state); SDL_SendKeyboardKey(0, state, HAIKU_GetScancodeFromBeKey(scancode)); - if (state == SDL_PRESSED && SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { + if (state == SDL_PRESSED && SDL_EventEnabled(SDL_TEXTINPUT)) { const int8 *keyUtf8; ssize_t count; if (msg->FindData("key-utf8", B_INT8_TYPE, (const void **)&keyUtf8, &count) == B_OK) { diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym index 64c73fdedf..328b9cc477 100644 --- a/src/dynapi/SDL_dynapi.sym +++ b/src/dynapi/SDL_dynapi.sym @@ -101,7 +101,6 @@ SDL3_0.0.0 { SDL_EGL_SetEGLAttributeCallbacks; SDL_EnableScreenSaver; SDL_Error; - SDL_EventState; SDL_FillSurfaceRect; SDL_FillSurfaceRects; SDL_FilterEvents; @@ -173,7 +172,6 @@ SDL3_0.0.0 { SDL_GetError; SDL_GetErrorMsg; SDL_GetEventFilter; - SDL_GetEventState; SDL_GetGamepadAppleSFSymbolsNameForAxis; SDL_GetGamepadAppleSFSymbolsNameForButton; SDL_GetGamepadAxis; @@ -182,7 +180,6 @@ SDL3_0.0.0 { SDL_GetGamepadBindForButton; SDL_GetGamepadButton; SDL_GetGamepadButtonFromString; - SDL_GetGamepadEventState; SDL_GetGamepadFirmwareVersion; SDL_GetGamepadFromInstanceID; SDL_GetGamepadFromPlayerIndex; @@ -222,7 +219,6 @@ SDL3_0.0.0 { SDL_GetJoystickAxis; SDL_GetJoystickAxisInitialState; SDL_GetJoystickButton; - SDL_GetJoystickEventState; SDL_GetJoystickFirmwareVersion; SDL_GetJoystickFromInstanceID; SDL_GetJoystickFromPlayerIndex; @@ -657,7 +653,6 @@ SDL3_0.0.0 { SDL_SetWindowTitle; SDL_SetWindowsMessageHook; SDL_SetYUVConversionMode; - SDL_ShowCursor; SDL_ShowMessageBox; SDL_ShowSimpleMessageBox; SDL_ShowWindow; @@ -855,6 +850,15 @@ SDL3_0.0.0 { SDL_wcsncasecmp; SDL_wcsncmp; SDL_wcsstr; + SDL_SetEventEnabled; + SDL_EventEnabled; + SDL_SetGamepadEventsEnabled; + SDL_GamepadEventsEnabled; + SDL_SetJoystickEventsEnabled; + SDL_JoystickEventsEnabled; + SDL_ShowCursor; + SDL_HideCursor; + SDL_CursorVisible; # 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 936b61c098..7c77747cc5 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -127,7 +127,6 @@ #define SDL_EGL_SetEGLAttributeCallbacks SDL_EGL_SetEGLAttributeCallbacks_REAL #define SDL_EnableScreenSaver SDL_EnableScreenSaver_REAL #define SDL_Error SDL_Error_REAL -#define SDL_EventState SDL_EventState_REAL #define SDL_FillSurfaceRect SDL_FillSurfaceRect_REAL #define SDL_FillSurfaceRects SDL_FillSurfaceRects_REAL #define SDL_FilterEvents SDL_FilterEvents_REAL @@ -199,7 +198,6 @@ #define SDL_GetError SDL_GetError_REAL #define SDL_GetErrorMsg SDL_GetErrorMsg_REAL #define SDL_GetEventFilter SDL_GetEventFilter_REAL -#define SDL_GetEventState SDL_GetEventState_REAL #define SDL_GetGamepadAppleSFSymbolsNameForAxis SDL_GetGamepadAppleSFSymbolsNameForAxis_REAL #define SDL_GetGamepadAppleSFSymbolsNameForButton SDL_GetGamepadAppleSFSymbolsNameForButton_REAL #define SDL_GetGamepadAxis SDL_GetGamepadAxis_REAL @@ -208,7 +206,6 @@ #define SDL_GetGamepadBindForButton SDL_GetGamepadBindForButton_REAL #define SDL_GetGamepadButton SDL_GetGamepadButton_REAL #define SDL_GetGamepadButtonFromString SDL_GetGamepadButtonFromString_REAL -#define SDL_GetGamepadEventState SDL_GetGamepadEventState_REAL #define SDL_GetGamepadFirmwareVersion SDL_GetGamepadFirmwareVersion_REAL #define SDL_GetGamepadFromInstanceID SDL_GetGamepadFromInstanceID_REAL #define SDL_GetGamepadFromPlayerIndex SDL_GetGamepadFromPlayerIndex_REAL @@ -248,7 +245,6 @@ #define SDL_GetJoystickAxis SDL_GetJoystickAxis_REAL #define SDL_GetJoystickAxisInitialState SDL_GetJoystickAxisInitialState_REAL #define SDL_GetJoystickButton SDL_GetJoystickButton_REAL -#define SDL_GetJoystickEventState SDL_GetJoystickEventState_REAL #define SDL_GetJoystickFirmwareVersion SDL_GetJoystickFirmwareVersion_REAL #define SDL_GetJoystickFromInstanceID SDL_GetJoystickFromInstanceID_REAL #define SDL_GetJoystickFromPlayerIndex SDL_GetJoystickFromPlayerIndex_REAL @@ -683,7 +679,6 @@ #define SDL_SetWindowTitle SDL_SetWindowTitle_REAL #define SDL_SetWindowsMessageHook SDL_SetWindowsMessageHook_REAL #define SDL_SetYUVConversionMode SDL_SetYUVConversionMode_REAL -#define SDL_ShowCursor SDL_ShowCursor_REAL #define SDL_ShowMessageBox SDL_ShowMessageBox_REAL #define SDL_ShowSimpleMessageBox SDL_ShowSimpleMessageBox_REAL #define SDL_ShowWindow SDL_ShowWindow_REAL @@ -883,3 +878,12 @@ #define SDL_wcsstr SDL_wcsstr_REAL /* New API symbols are added at the end */ +#define SDL_SetEventEnabled SDL_SetEventEnabled_REAL +#define SDL_EventEnabled SDL_EventEnabled_REAL +#define SDL_SetGamepadEventsEnabled SDL_SetGamepadEventsEnabled_REAL +#define SDL_GamepadEventsEnabled SDL_GamepadEventsEnabled_REAL +#define SDL_SetJoystickEventsEnabled SDL_SetJoystickEventsEnabled_REAL +#define SDL_JoystickEventsEnabled SDL_JoystickEventsEnabled_REAL +#define SDL_ShowCursor SDL_ShowCursor_REAL +#define SDL_HideCursor SDL_HideCursor_REAL +#define SDL_CursorVisible SDL_CursorVisible_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index bebc269196..62953b55d4 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -204,7 +204,6 @@ SDL_DYNAPI_PROC(SDL_EGLSurface,SDL_EGL_GetWindowEGLSurface,(SDL_Window *a),(a),r SDL_DYNAPI_PROC(void,SDL_EGL_SetEGLAttributeCallbacks,(SDL_EGLAttribArrayCallback a, SDL_EGLIntArrayCallback b, SDL_EGLIntArrayCallback c),(a,b,c),) SDL_DYNAPI_PROC(void,SDL_EnableScreenSaver,(void),(),) SDL_DYNAPI_PROC(int,SDL_Error,(SDL_errorcode a),(a),return) -SDL_DYNAPI_PROC(Uint8,SDL_EventState,(Uint32 a, int b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_FillSurfaceRect,(SDL_Surface *a, const SDL_Rect *b, Uint32 c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_FillSurfaceRects,(SDL_Surface *a, const SDL_Rect *b, int c, Uint32 d),(a,b,c,d),return) SDL_DYNAPI_PROC(void,SDL_FilterEvents,(SDL_EventFilter a, void *b),(a,b),) @@ -273,7 +272,6 @@ SDL_DYNAPI_PROC(int,SDL_GetDisplayUsableBounds,(int a, SDL_Rect *b),(a,b),return SDL_DYNAPI_PROC(const char*,SDL_GetError,(void),(),return) SDL_DYNAPI_PROC(char*,SDL_GetErrorMsg,(char *a, int b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetEventFilter,(SDL_EventFilter *a, void **b),(a,b),return) -SDL_DYNAPI_PROC(Uint8,SDL_GetEventState,(Uint32 a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return) SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return) SDL_DYNAPI_PROC(Sint16,SDL_GetGamepadAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return) @@ -282,7 +280,6 @@ SDL_DYNAPI_PROC(SDL_GamepadBinding,SDL_GetGamepadBindForAxis,(SDL_Gamepad *a, SD SDL_DYNAPI_PROC(SDL_GamepadBinding,SDL_GetGamepadBindForButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return) SDL_DYNAPI_PROC(Uint8,SDL_GetGamepadButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return) SDL_DYNAPI_PROC(SDL_GamepadButton,SDL_GetGamepadButtonFromString,(const char *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetGamepadEventState,(int a),(a),return) SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadFirmwareVersion,(SDL_Gamepad *a),(a),return) SDL_DYNAPI_PROC(SDL_Gamepad*,SDL_GetGamepadFromInstanceID,(SDL_JoystickID a),(a),return) SDL_DYNAPI_PROC(SDL_Gamepad*,SDL_GetGamepadFromPlayerIndex,(int a),(a),return) @@ -322,7 +319,6 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_GetHintBoolean,(const char *a, SDL_bool b),(a,b),re SDL_DYNAPI_PROC(Sint16,SDL_GetJoystickAxis,(SDL_Joystick *a, int b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetJoystickAxisInitialState,(SDL_Joystick *a, int b, Sint16 *c),(a,b,c),return) SDL_DYNAPI_PROC(Uint8,SDL_GetJoystickButton,(SDL_Joystick *a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetJoystickEventState,(int a),(a),return) SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickFirmwareVersion,(SDL_Joystick *a),(a),return) SDL_DYNAPI_PROC(SDL_Joystick*,SDL_GetJoystickFromInstanceID,(SDL_JoystickID a),(a),return) SDL_DYNAPI_PROC(SDL_Joystick*,SDL_GetJoystickFromPlayerIndex,(int a),(a),return) @@ -737,7 +733,6 @@ SDL_DYNAPI_PROC(int,SDL_SetWindowShape,(SDL_Window *a, SDL_Surface *b, SDL_Windo SDL_DYNAPI_PROC(void,SDL_SetWindowSize,(SDL_Window *a, int b, int c),(a,b,c),) SDL_DYNAPI_PROC(void,SDL_SetWindowTitle,(SDL_Window *a, const char *b),(a,b),) SDL_DYNAPI_PROC(void,SDL_SetYUVConversionMode,(SDL_YUV_CONVERSION_MODE a),(a),) -SDL_DYNAPI_PROC(int,SDL_ShowCursor,(int a),(a),return) SDL_DYNAPI_PROC(int,SDL_ShowMessageBox,(const SDL_MessageBoxData *a, int *b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_ShowSimpleMessageBox,(Uint32 a, const char *b, const char *c, SDL_Window *d),(a,b,c,d),return) SDL_DYNAPI_PROC(void,SDL_ShowWindow,(SDL_Window *a),(a),) @@ -928,3 +923,12 @@ SDL_DYNAPI_PROC(int,SDL_wcsncmp,(const wchar_t *a, const wchar_t *b, size_t c),( SDL_DYNAPI_PROC(wchar_t*,SDL_wcsstr,(const wchar_t *a, const wchar_t *b),(a,b),return) /* New API symbols are added at the end */ +SDL_DYNAPI_PROC(void,SDL_SetEventEnabled,(Uint32 a, SDL_bool b),(a,b),) +SDL_DYNAPI_PROC(SDL_bool,SDL_EventEnabled,(Uint32 a),(a),return) +SDL_DYNAPI_PROC(void,SDL_SetGamepadEventsEnabled,(SDL_bool a),(a),) +SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadEventsEnabled,(void),(),return) +SDL_DYNAPI_PROC(void,SDL_SetJoystickEventsEnabled,(SDL_bool a),(a),) +SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickEventsEnabled,(void),(),return) +SDL_DYNAPI_PROC(int,SDL_ShowCursor,(void),(),return) +SDL_DYNAPI_PROC(int,SDL_HideCursor,(void),(),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_CursorVisible,(void),(),return) diff --git a/src/events/SDL_clipboardevents.c b/src/events/SDL_clipboardevents.c index e39a527094..83d04c7a9f 100644 --- a/src/events/SDL_clipboardevents.c +++ b/src/events/SDL_clipboardevents.c @@ -31,7 +31,7 @@ int SDL_SendClipboardUpdate(void) /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(SDL_CLIPBOARDUPDATE) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_CLIPBOARDUPDATE)) { SDL_Event event; event.type = SDL_CLIPBOARDUPDATE; event.common.timestamp = 0; diff --git a/src/events/SDL_displayevents.c b/src/events/SDL_displayevents.c index 8c6c9147f9..c3824dbe7c 100644 --- a/src/events/SDL_displayevents.c +++ b/src/events/SDL_displayevents.c @@ -44,7 +44,7 @@ int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(displayevent) == SDL_ENABLE) { + if (SDL_EventEnabled(displayevent)) { SDL_Event event; event.type = displayevent; event.common.timestamp = 0; diff --git a/src/events/SDL_dropevents.c b/src/events/SDL_dropevents.c index 13fa80f500..15ce9b1ba0 100644 --- a/src/events/SDL_dropevents.c +++ b/src/events/SDL_dropevents.c @@ -33,7 +33,7 @@ static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const ch int posted = 0; /* Post the event, if desired */ - if (SDL_GetEventState(evtype) == SDL_ENABLE) { + if (SDL_EventEnabled(evtype)) { const SDL_bool need_begin = window ? !window->is_dropping : !app_is_dropping; SDL_Event event; diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 76ce8b495b..c4f060a341 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -102,7 +102,7 @@ static SDL_bool SDL_update_joysticks = SDL_TRUE; static void SDL_CalculateShouldUpdateJoysticks(SDL_bool hint_value) { if (hint_value && - (!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_GetJoystickEventState(SDL_QUERY))) { + (!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventsEnabled())) { SDL_update_joysticks = SDL_TRUE; } else { SDL_update_joysticks = SDL_FALSE; @@ -139,7 +139,7 @@ static void SDLCALL SDL_AutoUpdateSensorsChanged(void *userdata, const char *nam static void SDLCALL SDL_PollSentinelChanged(void *userdata, const char *name, const char *oldValue, const char *hint) { - (void)SDL_EventState(SDL_POLLSENTINEL, SDL_GetStringBoolean(hint, SDL_TRUE) ? SDL_ENABLE : SDL_DISABLE); + SDL_SetEventEnabled(SDL_POLLSENTINEL, SDL_GetStringBoolean(hint, SDL_TRUE)); } /** @@ -585,12 +585,12 @@ int SDL_StartEventLoop(void) #endif /* !SDL_THREADS_DISABLED */ /* Process most event types */ - (void)SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE); - (void)SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE); - (void)SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE); + SDL_SetEventEnabled(SDL_TEXTINPUT, SDL_FALSE); + SDL_SetEventEnabled(SDL_TEXTEDITING, SDL_FALSE); + SDL_SetEventEnabled(SDL_SYSWMEVENT, SDL_FALSE); #if 0 /* Leave these events enabled so apps can respond to items being dragged onto them at startup */ - (void)SDL_EventState(SDL_DROPFILE, SDL_DISABLE); - (void)SDL_EventState(SDL_DROPTEXT, SDL_DISABLE); + SDL_SetEventEnabled(SDL_DROPFILE, SDL_FALSE); + SDL_SetEventEnabled(SDL_DROPTEXT, SDL_FALSE); #endif SDL_EventQ.active = SDL_TRUE; @@ -883,7 +883,7 @@ static void SDL_PumpEventsInternal(SDL_bool push_sentinel) SDL_SendPendingSignalEvents(); /* in case we had a signal handler fire, etc. */ - if (push_sentinel && SDL_GetEventState(SDL_POLLSENTINEL) == SDL_ENABLE) { + if (push_sentinel && SDL_EventEnabled(SDL_POLLSENTINEL)) { SDL_Event sentinel; sentinel.type = SDL_POLLSENTINEL; @@ -1266,22 +1266,23 @@ void SDL_FilterEvents(SDL_EventFilter filter, void *userdata) SDL_UnlockMutex(SDL_EventQ.lock); } -Uint8 SDL_EventState(Uint32 type, int state) +void SDL_SetEventEnabled(Uint32 type, SDL_bool enabled) { - const SDL_bool isde = (state == SDL_DISABLE) || (state == SDL_ENABLE); - Uint8 current_state; + SDL_bool current_state; Uint8 hi = ((type >> 8) & 0xff); Uint8 lo = (type & 0xff); if (SDL_disabled_events[hi] && (SDL_disabled_events[hi]->bits[lo / 32] & (1 << (lo & 31)))) { - current_state = SDL_DISABLE; + current_state = SDL_FALSE; } else { - current_state = SDL_ENABLE; + current_state = SDL_TRUE; } - if (isde && state != current_state) { - if (state == SDL_DISABLE) { + if (enabled != current_state) { + if (enabled) { + SDL_disabled_events[hi]->bits[lo / 32] &= ~(1 << (lo & 31)); + } else { /* Disable this event type and discard pending events */ if (!SDL_disabled_events[hi]) { SDL_disabled_events[hi] = (SDL_DisabledEventBlock *)SDL_calloc(1, sizeof(SDL_DisabledEventBlock)); @@ -1291,8 +1292,6 @@ Uint8 SDL_EventState(Uint32 type, int state) SDL_disabled_events[hi]->bits[lo / 32] |= (1 << (lo & 31)); SDL_FlushEvent(type); } - } else { // state == SDL_ENABLE - SDL_disabled_events[hi]->bits[lo / 32] &= ~(1 << (lo & 31)); } #if !SDL_JOYSTICK_DISABLED @@ -1301,20 +1300,26 @@ Uint8 SDL_EventState(Uint32 type, int state) #if !SDL_SENSOR_DISABLED SDL_CalculateShouldUpdateSensors(SDL_GetHintBoolean(SDL_HINT_AUTO_UPDATE_SENSORS, SDL_TRUE)); #endif - } - /* turn off drag'n'drop support if we've disabled the events. - This might change some UI details at the OS level. */ - if (isde && ((type == SDL_DROPFILE) || (type == SDL_DROPTEXT))) { - SDL_ToggleDragAndDropSupport(); + /* turn off drag'n'drop support if we've disabled the events. + This might change some UI details at the OS level. */ + if (type == SDL_DROPFILE || type == SDL_DROPTEXT) { + SDL_ToggleDragAndDropSupport(); + } } - - return current_state; } -Uint8 SDL_GetEventState(Uint32 type) +SDL_bool SDL_EventEnabled(Uint32 type) { - return SDL_EventState(type, SDL_QUERY); + Uint8 hi = ((type >> 8) & 0xff); + Uint8 lo = (type & 0xff); + + if (SDL_disabled_events[hi] && + (SDL_disabled_events[hi]->bits[lo / 32] & (1 << (lo & 31)))) { + return SDL_FALSE; + } else { + return SDL_TRUE; + } } Uint32 SDL_RegisterEvents(int numevents) @@ -1335,7 +1340,7 @@ int SDL_SendAppEvent(SDL_EventType eventType) int posted; posted = 0; - if (SDL_GetEventState(eventType) == SDL_ENABLE) { + if (SDL_EventEnabled(eventType)) { SDL_Event event; event.type = eventType; event.common.timestamp = 0; @@ -1349,7 +1354,7 @@ int SDL_SendSysWMEvent(SDL_SysWMmsg *message) int posted; posted = 0; - if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_SYSWMEVENT)) { SDL_Event event; SDL_memset(&event, 0, sizeof(event)); event.type = SDL_SYSWMEVENT; diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index a863eb1f4e..09486250e6 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -766,7 +766,7 @@ void SDL_SetKeyboardFocus(SDL_Window *window) 0, 0); /* Ensures IME compositions are committed */ - if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { + if (SDL_EventEnabled(SDL_TEXTINPUT)) { SDL_VideoDevice *video = SDL_GetVideoDevice(); if (video && video->StopTextInput) { video->StopTextInput(video); @@ -780,7 +780,7 @@ void SDL_SetKeyboardFocus(SDL_Window *window) SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); - if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { + if (SDL_EventEnabled(SDL_TEXTINPUT)) { SDL_VideoDevice *video = SDL_GetVideoDevice(); if (video && video->StartTextInput) { video->StartTextInput(video); @@ -901,7 +901,7 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint8 source, Uint8 sta /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(type) == SDL_ENABLE) { + if (SDL_EventEnabled(type)) { SDL_Event event; event.type = type; event.common.timestamp = timestamp; @@ -1014,7 +1014,7 @@ int SDL_SendKeyboardText(const char *text) /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_TEXTINPUT)) { SDL_Event event; size_t pos = 0, advance, length = SDL_strlen(text); @@ -1040,7 +1040,7 @@ int SDL_SendEditingText(const char *text, int start, int length) /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(SDL_TEXTEDITING) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_TEXTEDITING)) { SDL_Event event; if (SDL_GetHintBoolean(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, SDL_FALSE) && diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 3a5c28dcc6..1410b88ed2 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -601,7 +601,7 @@ static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_ /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_MOUSEMOTION)) { SDL_Event event; event.type = SDL_MOUSEMOTION; event.common.timestamp = timestamp; @@ -758,7 +758,7 @@ static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_ /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(type) == SDL_ENABLE) { + if (SDL_EventEnabled(type)) { SDL_Event event; event.type = type; event.common.timestamp = timestamp; @@ -850,7 +850,7 @@ int SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_MOUSEWHEEL)) { SDL_Event event; event.type = SDL_MOUSEWHEEL; event.common.timestamp = timestamp; @@ -878,7 +878,7 @@ void SDL_QuitMouse(void) SDL_UpdateMouseCapture(SDL_TRUE); } SDL_SetRelativeMouseMode(SDL_FALSE); - SDL_ShowCursor(1); + SDL_ShowCursor(); cursor = mouse->cursors; while (cursor) { @@ -1413,25 +1413,31 @@ void SDL_FreeCursor(SDL_Cursor *cursor) } } -int SDL_ShowCursor(int toggle) +int SDL_ShowCursor(void) { SDL_Mouse *mouse = SDL_GetMouse(); - SDL_bool shown; - if (mouse == NULL) { - return 0; + if (!mouse->cursor_shown) { + mouse->cursor_shown = SDL_TRUE; + SDL_SetCursor(NULL); } - - shown = mouse->cursor_shown; - if (toggle >= 0) { - if (toggle) { - mouse->cursor_shown = SDL_TRUE; - } else { - mouse->cursor_shown = SDL_FALSE; - } - if (mouse->cursor_shown != shown) { - SDL_SetCursor(NULL); - } - } - return shown; + return 0; +} + +int SDL_HideCursor(void) +{ + SDL_Mouse *mouse = SDL_GetMouse(); + + if (mouse->cursor_shown) { + mouse->cursor_shown = SDL_FALSE; + SDL_SetCursor(NULL); + } + return 0; +} + +SDL_bool SDL_CursorVisible(void) +{ + SDL_Mouse *mouse = SDL_GetMouse(); + + return mouse->cursor_shown; } diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index d218c80d66..1b6632cba6 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -319,7 +319,7 @@ int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_W } posted = 0; - if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_FINGERDOWN)) { SDL_Event event; event.type = SDL_FINGERDOWN; event.common.timestamp = timestamp; @@ -340,7 +340,7 @@ int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_W } posted = 0; - if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_FINGERUP)) { SDL_Event event; event.type = SDL_FINGERUP; event.common.timestamp = timestamp; @@ -437,7 +437,7 @@ int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_FINGERMOTION)) { SDL_Event event; event.type = SDL_FINGERMOTION; event.common.timestamp = timestamp; diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c index f3e417ed19..8b44793348 100644 --- a/src/events/SDL_windowevents.c +++ b/src/events/SDL_windowevents.c @@ -181,7 +181,7 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, /* Post the event, if desired */ posted = 0; - if (SDL_GetEventState(windowevent) == SDL_ENABLE) { + if (SDL_EventEnabled(windowevent)) { SDL_Event event; event.type = windowevent; event.common.timestamp = 0; diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c index 99b77ed255..0e8a27d741 100644 --- a/src/joystick/SDL_gamepad.c +++ b/src/joystick/SDL_gamepad.c @@ -3076,7 +3076,7 @@ static int SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gamep /* translate the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED - if (SDL_GetEventState(SDL_GAMEPADAXISMOTION) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_GAMEPADAXISMOTION)) { SDL_Event event; event.type = SDL_GAMEPADAXISMOTION; event.common.timestamp = timestamp; @@ -3138,7 +3138,7 @@ static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gam /* translate the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED - if (SDL_GetEventState(event.type) == SDL_ENABLE) { + if (SDL_EventEnabled(event.type)) { event.common.timestamp = timestamp; event.cbutton.which = gamepad->joystick->instance_id; event.cbutton.button = button; @@ -3149,46 +3149,46 @@ static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gam return posted; } -/* - * Turn off gamepad events - */ -int SDL_GetGamepadEventState(int state) +static const Uint32 SDL_gamepad_event_list[] = { + SDL_GAMEPADAXISMOTION, + SDL_GAMEPADBUTTONDOWN, + SDL_GAMEPADBUTTONUP, + SDL_GAMEPADADDED, + SDL_GAMEPADREMOVED, + SDL_GAMEPADDEVICEREMAPPED, + SDL_GAMEPADTOUCHPADDOWN, + SDL_GAMEPADTOUCHPADMOTION, + SDL_GAMEPADTOUCHPADUP, + SDL_GAMEPADSENSORUPDATE, +}; + +void SDL_SetGamepadEventsEnabled(SDL_bool enabled) { -#if SDL_EVENTS_DISABLED - return SDL_IGNORE; -#else - const Uint32 event_list[] = { - SDL_GAMEPADAXISMOTION, - SDL_GAMEPADBUTTONDOWN, - SDL_GAMEPADBUTTONUP, - SDL_GAMEPADADDED, - SDL_GAMEPADREMOVED, - SDL_GAMEPADDEVICEREMAPPED, - SDL_GAMEPADTOUCHPADDOWN, - SDL_GAMEPADTOUCHPADMOTION, - SDL_GAMEPADTOUCHPADUP, - SDL_GAMEPADSENSORUPDATE, - }; +#ifndef SDL_EVENTS_DISABLED unsigned int i; - switch (state) { - case SDL_QUERY: - state = SDL_IGNORE; - for (i = 0; i < SDL_arraysize(event_list); ++i) { - state = SDL_EventState(event_list[i], SDL_QUERY); - if (state == SDL_ENABLE) { - break; - } - } - break; - default: - for (i = 0; i < SDL_arraysize(event_list); ++i) { - (void)SDL_EventState(event_list[i], state); - } - break; + for (i = 0; i < SDL_arraysize(SDL_gamepad_event_list); ++i) { + SDL_SetEventEnabled(SDL_gamepad_event_list[i], enabled); + } +#endif /* !SDL_EVENTS_DISABLED */ +} + +SDL_bool SDL_GamepadEventsEnabled(void) +{ + SDL_bool enabled = SDL_FALSE; + +#ifndef SDL_EVENTS_DISABLED + unsigned int i; + + for (i = 0; i < SDL_arraysize(SDL_gamepad_event_list); ++i) { + enabled = SDL_EventEnabled(SDL_gamepad_event_list[i]); + if (enabled) { + break; + } } - return state; #endif /* SDL_EVENTS_DISABLED */ + + return enabled; } void SDL_GamepadHandleDelayedGuideButton(SDL_Joystick *joystick) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 2f355dfb91..cf3a41aa13 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -1404,7 +1404,7 @@ void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id) event.type = SDL_JOYDEVICEADDED; event.common.timestamp = 0; - if (SDL_GetEventState(event.type) == SDL_ENABLE) { + if (SDL_EventEnabled(event.type)) { event.jdevice.which = instance_id; SDL_PushEvent(&event); } @@ -1466,7 +1466,7 @@ void SDL_PrivateJoystickRemoved(SDL_JoystickID instance_id) event.type = SDL_JOYDEVICEREMOVED; event.common.timestamp = 0; - if (SDL_GetEventState(event.type) == SDL_ENABLE) { + if (SDL_EventEnabled(event.type)) { event.jdevice.which = instance_id; SDL_PushEvent(&event); } @@ -1532,7 +1532,7 @@ int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, S /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED - if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_JOYAXISMOTION)) { SDL_Event event; event.type = SDL_JOYAXISMOTION; event.common.timestamp = timestamp; @@ -1574,7 +1574,7 @@ int SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uin /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED - if (SDL_GetEventState(SDL_JOYHATMOTION) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_JOYHATMOTION)) { SDL_Event event; event.type = SDL_JOYHATMOTION; event.common.timestamp = timestamp; @@ -1632,7 +1632,7 @@ int SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 butto /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED - if (SDL_GetEventState(event.type) == SDL_ENABLE) { + if (SDL_EventEnabled(event.type)) { event.common.timestamp = timestamp; event.jbutton.which = joystick->instance_id; event.jbutton.button = button; @@ -1698,38 +1698,45 @@ void SDL_UpdateJoysticks(void) SDL_UnlockJoysticks(); } -int SDL_GetJoystickEventState(int state) +static const Uint32 SDL_joystick_event_list[] = { + SDL_JOYAXISMOTION, + SDL_JOYHATMOTION, + SDL_JOYBUTTONDOWN, + SDL_JOYBUTTONUP, + SDL_JOYDEVICEADDED, + SDL_JOYDEVICEREMOVED, + SDL_JOYBATTERYUPDATED +}; + +void SDL_SetJoystickEventsEnabled(SDL_bool enabled) { -#if SDL_EVENTS_DISABLED - return SDL_DISABLE; -#else - const Uint32 event_list[] = { - SDL_JOYAXISMOTION, SDL_JOYHATMOTION, - SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED, - SDL_JOYBATTERYUPDATED - }; +#ifndef SDL_EVENTS_DISABLED unsigned int i; - switch (state) { - case SDL_QUERY: - state = SDL_DISABLE; - for (i = 0; i < SDL_arraysize(event_list); ++i) { - state = SDL_EventState(event_list[i], SDL_QUERY); - if (state == SDL_ENABLE) { - break; - } - } - break; - default: - for (i = 0; i < SDL_arraysize(event_list); ++i) { - (void)SDL_EventState(event_list[i], state); - } - break; + for (i = 0; i < SDL_arraysize(SDL_joystick_event_list); ++i) { + SDL_SetEventEnabled(SDL_joystick_event_list[i], enabled); } - return state; #endif /* SDL_EVENTS_DISABLED */ } +SDL_bool SDL_JoystickEventsEnabled() +{ + SDL_bool enabled = SDL_FALSE; + +#ifndef SDL_EVENTS_DISABLED + unsigned int i; + + for (i = 0; i < SDL_arraysize(SDL_joystick_event_list); ++i) { + enabled = SDL_EventEnabled(SDL_joystick_event_list[i]); + if (enabled) { + break; + } + } +#endif /* !SDL_EVENTS_DISABLED */ + + return enabled; +} + void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16) { Uint16 *guid16 = (Uint16 *)guid.data; @@ -2819,7 +2826,7 @@ void SDL_SendJoystickBatteryLevel(SDL_Joystick *joystick, SDL_JoystickPowerLevel SDL_assert(joystick->ref_count); /* make sure we are calling this only for update, not for initialization */ if (ePowerLevel != joystick->epowerlevel) { #if !SDL_EVENTS_DISABLED - if (SDL_GetEventState(SDL_JOYBATTERYUPDATED) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_JOYBATTERYUPDATED)) { SDL_Event event; event.type = SDL_JOYBATTERYUPDATED; event.common.timestamp = 0; @@ -2923,7 +2930,7 @@ int SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touch /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED - if (SDL_GetEventState(event_type) == SDL_ENABLE) { + if (SDL_EventEnabled(event_type)) { SDL_Event event; event.type = event_type; event.common.timestamp = timestamp; @@ -2963,7 +2970,7 @@ int SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorT /* Post the event, if desired */ #if !SDL_EVENTS_DISABLED - if (SDL_GetEventState(SDL_GAMEPADSENSORUPDATE) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_GAMEPADSENSORUPDATE)) { SDL_Event event; event.type = SDL_GAMEPADSENSORUPDATE; event.common.timestamp = timestamp; diff --git a/src/sensor/SDL_sensor.c b/src/sensor/SDL_sensor.c index 4e52ceedf7..c2874ccf8f 100644 --- a/src/sensor/SDL_sensor.c +++ b/src/sensor/SDL_sensor.c @@ -492,7 +492,7 @@ int SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_tim /* Post the event, if desired */ posted = 0; #if !SDL_EVENTS_DISABLED - if (SDL_GetEventState(SDL_SENSORUPDATE) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_SENSORUPDATE)) { SDL_Event event; event.type = SDL_SENSORUPDATE; event.common.timestamp = timestamp; diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 5f046c72c8..c64bf67ae6 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1491,8 +1491,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen) static SDL_INLINE SDL_bool IsAcceptingDragAndDrop(void) { - if ((SDL_GetEventState(SDL_DROPFILE) == SDL_ENABLE) || - (SDL_GetEventState(SDL_DROPTEXT) == SDL_ENABLE)) { + if (SDL_EventEnabled(SDL_DROPFILE) || SDL_EventEnabled(SDL_DROPTEXT)) { return SDL_TRUE; } return SDL_FALSE; @@ -4230,8 +4229,8 @@ void SDL_StartTextInput(void) SDL_Window *window; /* First, enable text events */ - (void)SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE); - (void)SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE); + SDL_SetEventEnabled(SDL_TEXTINPUT, SDL_TRUE); + SDL_SetEventEnabled(SDL_TEXTEDITING, SDL_TRUE); /* Then show the on-screen keyboard, if any */ window = SDL_GetFocusWindow(); @@ -4265,7 +4264,7 @@ SDL_IsTextInputShown(void) SDL_bool SDL_IsTextInputActive(void) { - return SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE; + return SDL_EventEnabled(SDL_TEXTINPUT); } void SDL_StopTextInput(void) @@ -4284,8 +4283,8 @@ void SDL_StopTextInput(void) } /* Finally disable text events */ - (void)SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE); - (void)SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE); + SDL_SetEventEnabled(SDL_TEXTINPUT, SDL_FALSE); + SDL_SetEventEnabled(SDL_TEXTEDITING, SDL_FALSE); } void SDL_SetTextInputRect(const SDL_Rect *rect) @@ -4368,7 +4367,7 @@ int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) int dummybutton; int retval = -1; SDL_bool relative_mode; - int show_cursor_prev; + SDL_bool show_cursor_prev; SDL_Window *current_window; SDL_MessageBoxData mbdata; @@ -4384,7 +4383,8 @@ int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) relative_mode = SDL_GetRelativeMouseMode(); SDL_UpdateMouseCapture(SDL_FALSE); SDL_SetRelativeMouseMode(SDL_FALSE); - show_cursor_prev = SDL_ShowCursor(1); + show_cursor_prev = SDL_CursorVisible(); + SDL_ShowCursor(); SDL_ResetKeyboard(); if (buttonid == NULL) { @@ -4489,7 +4489,9 @@ int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) SDL_RaiseWindow(current_window); } - SDL_ShowCursor(show_cursor_prev); + if (!show_cursor_prev) { + SDL_HideCursor(); + } SDL_SetRelativeMouseMode(relative_mode); SDL_UpdateMouseCapture(SDL_FALSE); diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index e08dfecaa6..a5f24fde2d 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -405,7 +405,7 @@ void Cocoa_HandleKeyEvent(_THIS, NSEvent *event) SDL_Log("The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL forums/mailing list or to Christian Walther . Mac virtual key code is %d.\n", scancode); } #endif - if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { + if (SDL_EventEnabled(SDL_TEXTINPUT)) { /* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */ [data.fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]]; #if 0 diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 42f262a53d..a41f1e587c 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -680,7 +680,7 @@ static EM_BOOL Emscripten_HandleMouseButton(int eventType, const EmscriptenMouse return 0; } - return SDL_GetEventState(sdl_event_type) == SDL_ENABLE; + return SDL_EventEnabled(sdl_event_type); } static EM_BOOL Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) @@ -701,7 +701,7 @@ static EM_BOOL Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseE } SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL); - return SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE; + return SDL_EventEnabled(SDL_MOUSEMOTION); } static EM_BOOL Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent *wheelEvent, void *userData) @@ -723,7 +723,7 @@ static EM_BOOL Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent } SDL_SendMouseWheel(0, window_data->window, 0, (float)wheelEvent->deltaX, -deltaY, SDL_MOUSEWHEEL_NORMAL); - return SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE; + return SDL_EventEnabled(SDL_MOUSEWHEEL); } static EM_BOOL Emscripten_HandleFocus(int eventType, const EmscriptenFocusEvent *wheelEvent, void *userData) @@ -739,7 +739,7 @@ static EM_BOOL Emscripten_HandleFocus(int eventType, const EmscriptenFocusEvent sdl_event_type = (eventType == EMSCRIPTEN_EVENT_FOCUS) ? SDL_WINDOWEVENT_FOCUS_GAINED : SDL_WINDOWEVENT_FOCUS_LOST; SDL_SendWindowEvent(window_data->window, sdl_event_type, 0, 0); - return SDL_GetEventState(sdl_event_type) == SDL_ENABLE; + return SDL_EventEnabled(sdl_event_type); } static EM_BOOL Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData) @@ -772,7 +772,7 @@ static EM_BOOL Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent SDL_SendTouch(0, deviceId, id, window_data->window, SDL_TRUE, x, y, 1.0f); /* disable browser scrolling/pinch-to-zoom if app handles touch events */ - if (!preventDefault && SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) { + if (!preventDefault && SDL_EventEnabled(SDL_FINGERDOWN)) { preventDefault = 1; } } else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) { @@ -822,7 +822,7 @@ static EM_BOOL Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent is_nav_key = SDL_TRUE; } - if ((eventType == EMSCRIPTEN_EVENT_KEYDOWN) && (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) && !is_nav_key) { + if ((eventType == EMSCRIPTEN_EVENT_KEYDOWN) && SDL_EventEnabled(SDL_TEXTINPUT) && !is_nav_key) { prevent_default = SDL_FALSE; } @@ -835,7 +835,7 @@ static EM_BOOL Emscripten_HandleKeyPress(int eventType, const EmscriptenKeyboard if (Emscripten_ConvertUTF32toUTF8(keyEvent->charCode, text)) { SDL_SendKeyboardText(text); } - return SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE; + return SDL_EventEnabled(SDL_TEXTINPUT); } static EM_BOOL Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData) diff --git a/src/video/haiku/SDL_BApp.h b/src/video/haiku/SDL_BApp.h index 350d4b6336..998ffb0e48 100644 --- a/src/video/haiku/SDL_BApp.h +++ b/src/video/haiku/SDL_BApp.h @@ -260,7 +260,7 @@ class SDL_BApp : public BApplication be_app->HideCursor(); } else { SDL_SendMouseMotion(0, win, 0, 0, x, y); - if (SDL_ShowCursor(-1) && be_app->IsCursorHidden()) + if (SDL_CursorVisible() && be_app->IsCursorHidden()) be_app->ShowCursor(); } } @@ -311,7 +311,7 @@ class SDL_BApp : public BApplication HAIKU_SetKeyState(scancode, state); SDL_SendKeyboardKey(0, state, HAIKU_GetScancodeFromBeKey(scancode)); - if (state == SDL_PRESSED && SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) { + if (state == SDL_PRESSED && SDL_EventEnabled(SDL_TEXTINPUT)) { const int8 *keyUtf8; ssize_t count; if (msg->FindData("key-utf8", B_INT8_TYPE, (const void **)&keyUtf8, &count) == B_OK) { diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index b2eb2754fe..5c915b1904 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -165,7 +165,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick; - (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4)) { - if (SDL_ShowCursor(-1)) { + if (SDL_CursorVisible()) { return nil; } else { return [UIPointerStyle hiddenPointerStyle]; diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index 8a9cdf40f0..515533ff92 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -374,7 +374,7 @@ int Wayland_WaitEventTimeout(_THIS, Sint64 timeoutNS) WAYLAND_wl_display_flush(d->display); #ifdef SDL_USE_IME - if (d->text_input_manager == NULL && SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { + if (d->text_input_manager == NULL && SDL_EventEnabled(SDL_TEXTINPUT)) { SDL_IME_PumpEvents(); } #endif @@ -443,7 +443,7 @@ void Wayland_PumpEvents(_THIS) int err; #ifdef SDL_USE_IME - if (d->text_input_manager == NULL && SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { + if (d->text_input_manager == NULL && SDL_EventEnabled(SDL_TEXTINPUT)) { SDL_IME_PumpEvents(); } #endif diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index d9a5c80722..dccbcac58c 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -720,7 +720,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT returnCode = -1; /* Send a SDL_SYSWMEVENT if the application wants them */ - if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_SYSWMEVENT)) { SDL_SysWMmsg wmmsg; wmmsg.version = SDL_SYSWM_CURRENT_VERSION; diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 40892edae7..efba6021b0 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -334,7 +334,7 @@ static void X11_HandleGenericEvent(SDL_VideoData *videodata, XEvent *xev) * Since event data is only available until XFreeEventData is called, * the *only* way for an application to access it is to register an event filter/watcher * and do all the processing on the SDL_SYSWMEVENT inside the callback. */ - if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_SYSWMEVENT)) { SDL_SysWMmsg wmmsg; wmmsg.version = SDL_SYSWM_CURRENT_VERSION; @@ -816,7 +816,7 @@ static void X11_DispatchEvent(_THIS, XEvent *xevent) #endif /* Send a SDL_SYSWMEVENT if the application wants them */ - if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_SYSWMEVENT)) { SDL_SysWMmsg wmmsg; wmmsg.version = SDL_SYSWM_CURRENT_VERSION; @@ -1078,7 +1078,7 @@ static void X11_DispatchEvent(_THIS, XEvent *xevent) #endif #ifdef SDL_USE_IME - if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_TEXTINPUT)) { handled_by_ime = SDL_IME_ProcessKeyEvent(keysym, keycode, (xevent->type == KeyPress ? SDL_PRESSED : SDL_RELEASED)); } #endif @@ -1171,7 +1171,7 @@ static void X11_DispatchEvent(_THIS, XEvent *xevent) SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED, xevent->xconfigure.x, xevent->xconfigure.y); #ifdef SDL_USE_IME - if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_TEXTINPUT)) { /* Update IME candidate list position */ SDL_IME_UpdateTextRect(NULL); } @@ -1668,7 +1668,7 @@ int X11_WaitEventTimeout(_THIS, Sint64 timeoutNS) X11_DispatchEvent(_this, &xevent); #ifdef SDL_USE_IME - if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_TEXTINPUT)) { SDL_IME_PumpEvents(); } #endif @@ -1709,7 +1709,7 @@ void X11_PumpEvents(_THIS) } #ifdef SDL_USE_IME - if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) { + if (SDL_EventEnabled(SDL_TEXTINPUT)) { SDL_IME_PumpEvents(); } #endif diff --git a/test/testautomation_mouse.c b/test/testautomation_mouse.c index ac918d5801..f04fadb2c7 100644 --- a/test/testautomation_mouse.c +++ b/test/testautomation_mouse.c @@ -247,24 +247,22 @@ int mouse_createFreeColorCursor(void *arg) } /* Helper that changes cursor visibility */ -void _changeCursorVisibility(int state) +void _changeCursorVisibility(SDL_bool state) { - int oldState; - int newState; - int result; + SDL_bool newState; - oldState = SDL_ShowCursor(SDL_QUERY); - SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)"); + if (state) { + SDL_ShowCursor(); + } else { + SDL_HideCursor(); + } + SDLTest_AssertPass("Call to %s", state ? "SDL_ShowCursor()" : "SDL_HideCursor()"); - result = SDL_ShowCursor(state); - SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE"); - SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i", - (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result); - - newState = SDL_ShowCursor(SDL_QUERY); - SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)"); - SDLTest_AssertCheck(state == newState, "Validate new state, expected: %i, got: %i", - state, newState); + newState = SDL_CursorVisible(); + SDLTest_AssertPass("Call to SDL_CursorVisible()"); + SDLTest_AssertCheck(state == newState, "Validate new state, expected: %s, got: %s", + state ? "SDL_TRUE" : "SDL_FALSE", + newState ? "SDL_TRUE" : "SDL_FALSE"); } /** @@ -274,23 +272,19 @@ void _changeCursorVisibility(int state) */ int mouse_showCursor(void *arg) { - int currentState; + SDL_bool currentState; /* Get current state */ - currentState = SDL_ShowCursor(SDL_QUERY); - SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)"); - SDLTest_AssertCheck(currentState == SDL_DISABLE || currentState == SDL_ENABLE, - "Validate result is %i or %i, got: %i", SDL_DISABLE, SDL_ENABLE, currentState); - if (currentState == SDL_DISABLE) { - /* Show the cursor, then hide it again */ - _changeCursorVisibility(SDL_ENABLE); - _changeCursorVisibility(SDL_DISABLE); - } else if (currentState == SDL_ENABLE) { + currentState = SDL_CursorVisible(); + SDLTest_AssertPass("Call to SDL_CursorVisible()"); + if (currentState) { /* Hide the cursor, then show it again */ - _changeCursorVisibility(SDL_DISABLE); - _changeCursorVisibility(SDL_ENABLE); + _changeCursorVisibility(SDL_FALSE); + _changeCursorVisibility(SDL_TRUE); } else { - return TEST_ABORTED; + /* Show the cursor, then hide it again */ + _changeCursorVisibility(SDL_TRUE); + _changeCursorVisibility(SDL_FALSE); } return TEST_COMPLETED; diff --git a/test/testcustomcursor.c b/test/testcustomcursor.c index 286cbb6937..0de3e2655e 100644 --- a/test/testcustomcursor.c +++ b/test/testcustomcursor.c @@ -137,7 +137,7 @@ static SDL_Cursor *cursors[1 + SDL_NUM_SYSTEM_CURSORS]; static SDL_SystemCursor cursor_types[1 + SDL_NUM_SYSTEM_CURSORS]; static int num_cursors; static int current_cursor; -static int show_cursor; +static SDL_bool show_cursor; /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ static void @@ -214,7 +214,11 @@ void loop() } else { show_cursor = !show_cursor; - SDL_ShowCursor(show_cursor); + if (show_cursor) { + SDL_ShowCursor(); + } else { + SDL_HideCursor(); + } } } } @@ -300,7 +304,7 @@ int main(int argc, char *argv[]) SDL_SetCursor(cursors[0]); } - show_cursor = SDL_ShowCursor(SDL_QUERY); + show_cursor = SDL_CursorVisible(); /* Main render loop */ done = 0; diff --git a/test/testdropfile.c b/test/testdropfile.c index e2f882dec4..4df76a6da2 100644 --- a/test/testdropfile.c +++ b/test/testdropfile.c @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) SDL_RenderPresent(renderer); } - SDL_EventState(SDL_DROPFILE, SDL_ENABLE); + SDL_SetEventEnabled(SDL_DROPFILE, SDL_TRUE); /* Main render loop */ done = 0; diff --git a/test/testoverlay2.c b/test/testoverlay2.c index dd2cb14996..dff64edf88 100644 --- a/test/testoverlay2.c +++ b/test/testoverlay2.c @@ -492,7 +492,7 @@ int main(int argc, char **argv) displayrect.h = window_h; /* Ignore key up events, they don't even get filtered */ - SDL_EventState(SDL_KEYUP, SDL_IGNORE); + SDL_SetEventEnabled(SDL_KEYUP, SDL_FALSE); /* Main render loop */ frames = 0; diff --git a/test/testwm2.c b/test/testwm2.c index 1b5da0bfce..c9b0d49763 100644 --- a/test/testwm2.c +++ b/test/testwm2.c @@ -269,8 +269,8 @@ int main(int argc, char *argv[]) return 1; } - SDL_EventState(SDL_DROPFILE, SDL_ENABLE); - SDL_EventState(SDL_DROPTEXT, SDL_ENABLE); + SDL_SetEventEnabled(SDL_DROPFILE, SDL_TRUE); + SDL_SetEventEnabled(SDL_DROPTEXT, SDL_TRUE); for (i = 0; i < state->num_windows; ++i) { SDL_Renderer *renderer = state->renderers[i];