Removed SDL_EVENTS_DISABLED

Events are a core part of the SDL API, and shouldn't be disabled
main
Sam Lantinga 2024-01-16 21:23:46 -08:00
parent ba02722755
commit 52d6587084
7 changed files with 2 additions and 71 deletions

View File

@ -243,7 +243,6 @@ set(SDL_SUBSYSTEMS
Audio
Video
Render
Events
Joystick
Haptic
Hidapi

View File

@ -259,7 +259,6 @@
#cmakedefine SDL_ATOMIC_DISABLED @SDL_ATOMIC_DISABLED@
#cmakedefine SDL_AUDIO_DISABLED @SDL_AUDIO_DISABLED@
#cmakedefine SDL_CPUINFO_DISABLED @SDL_CPUINFO_DISABLED@
#cmakedefine SDL_EVENTS_DISABLED @SDL_EVENTS_DISABLED@
#cmakedefine SDL_FILE_DISABLED @SDL_FILE_DISABLED@
#cmakedefine SDL_JOYSTICK_DISABLED @SDL_JOYSTICK_DISABLED@
#cmakedefine SDL_HAPTIC_DISABLED @SDL_HAPTIC_DISABLED@

View File

@ -204,7 +204,6 @@ int SDL_InitSubSystem(Uint32 flags)
/* Initialize the event subsystem */
if (flags & SDL_INIT_EVENTS) {
#ifndef SDL_EVENTS_DISABLED
if (SDL_ShouldInitSubsystem(SDL_INIT_EVENTS)) {
SDL_IncrementSubsystemRefCount(SDL_INIT_EVENTS);
if (SDL_InitEvents() < 0) {
@ -215,10 +214,6 @@ int SDL_InitSubSystem(Uint32 flags)
SDL_IncrementSubsystemRefCount(SDL_INIT_EVENTS);
}
flags_initialized |= SDL_INIT_EVENTS;
#else
SDL_SetError("SDL not built with events support");
goto quit_and_error;
#endif
}
/* Initialize the timer subsystem */
@ -452,14 +447,12 @@ void SDL_QuitSubSystem(Uint32 flags)
SDL_DecrementSubsystemRefCount(SDL_INIT_TIMER);
}
#ifndef SDL_EVENTS_DISABLED
if (flags & SDL_INIT_EVENTS) {
if (SDL_ShouldQuitSubsystem(SDL_INIT_EVENTS)) {
SDL_QuitEvents();
}
SDL_DecrementSubsystemRefCount(SDL_INIT_EVENTS);
}
#endif
}
Uint32 SDL_WasInit(Uint32 flags)

View File

@ -31,10 +31,8 @@
#include "controller_type.h"
#include "usb_ids.h"
#include "hidapi/SDL_hidapi_nintendo.h"
#ifndef SDL_EVENTS_DISABLED
#include "../events/SDL_events_c.h"
#endif
#ifdef __ANDROID__
#endif
@ -3635,7 +3633,6 @@ static int SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gamep
/* translate the event, if desired */
posted = 0;
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(SDL_EVENT_GAMEPAD_AXIS_MOTION)) {
SDL_Event event;
event.type = SDL_EVENT_GAMEPAD_AXIS_MOTION;
@ -3645,7 +3642,6 @@ static int SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gamep
event.gaxis.value = value;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return posted;
}
@ -3655,7 +3651,6 @@ static int SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gamep
static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, Uint8 state)
{
int posted;
#ifndef SDL_EVENTS_DISABLED
SDL_Event event;
SDL_AssertJoysticksLocked();
@ -3675,7 +3670,6 @@ static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gam
/* Invalid state -- bail */
return 0;
}
#endif /* !SDL_EVENTS_DISABLED */
if (button == SDL_GAMEPAD_BUTTON_GUIDE) {
Uint64 now = SDL_GetTicks();
@ -3697,7 +3691,6 @@ static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gam
/* translate the event, if desired */
posted = 0;
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(event.type)) {
event.common.timestamp = timestamp;
event.gbutton.which = gamepad->joystick->instance_id;
@ -3705,11 +3698,9 @@ static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gam
event.gbutton.state = state;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return posted;
}
#ifndef SDL_EVENTS_DISABLED
static const Uint32 SDL_gamepad_event_list[] = {
SDL_EVENT_GAMEPAD_AXIS_MOTION,
SDL_EVENT_GAMEPAD_BUTTON_DOWN,
@ -3722,24 +3713,19 @@ static const Uint32 SDL_gamepad_event_list[] = {
SDL_EVENT_GAMEPAD_TOUCHPAD_UP,
SDL_EVENT_GAMEPAD_SENSOR_UPDATE,
};
#endif
void SDL_SetGamepadEventsEnabled(SDL_bool enabled)
{
#ifndef SDL_EVENTS_DISABLED
unsigned int i;
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) {
@ -3748,8 +3734,6 @@ SDL_bool SDL_GamepadEventsEnabled(void)
break;
}
}
#endif /* SDL_EVENTS_DISABLED */
return enabled;
}

View File

@ -28,9 +28,7 @@
#include "SDL_joystick_c.h"
#include "SDL_steam_virtual_gamepad.h"
#ifndef SDL_EVENTS_DISABLED
#include "../events/SDL_events_c.h"
#endif
#include "../video/SDL_sysvideo.h"
#include "../sensor/SDL_sensor_c.h"
#include "hidapi/SDL_hidapijoystick_c.h"
@ -600,11 +598,9 @@ int SDL_InitJoysticks(void)
SDL_joystick_lock = SDL_CreateMutex();
}
#ifndef SDL_EVENTS_DISABLED
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
return -1;
}
#endif /* !SDL_EVENTS_DISABLED */
SDL_LockJoysticks();
@ -1855,9 +1851,7 @@ void SDL_QuitJoysticks(void)
SDL_joystick_player_count = 0;
}
#ifndef SDL_EVENTS_DISABLED
SDL_QuitSubSystem(SDL_INIT_EVENTS);
#endif
SDL_QuitSteamVirtualGamepadInfo();
@ -1971,7 +1965,6 @@ void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id)
SDL_SetJoystickIDForPlayerIndex(player_index, instance_id);
}
#ifndef SDL_EVENTS_DISABLED
{
SDL_Event event;
@ -1983,7 +1976,6 @@ void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id)
SDL_PushEvent(&event);
}
}
#endif /* !SDL_EVENTS_DISABLED */
SDL_joystick_being_added = SDL_FALSE;
@ -2032,9 +2024,7 @@ void SDL_PrivateJoystickRemoved(SDL_JoystickID instance_id)
{
SDL_Joystick *joystick = NULL;
int player_index;
#ifndef SDL_EVENTS_DISABLED
SDL_Event event;
#endif
SDL_AssertJoysticksLocked();
@ -2054,7 +2044,6 @@ void SDL_PrivateJoystickRemoved(SDL_JoystickID instance_id)
SDL_PrivateGamepadRemoved(instance_id);
}
#ifndef SDL_EVENTS_DISABLED
event.type = SDL_EVENT_JOYSTICK_REMOVED;
event.common.timestamp = 0;
@ -2062,7 +2051,6 @@ void SDL_PrivateJoystickRemoved(SDL_JoystickID instance_id)
event.jdevice.which = instance_id;
SDL_PushEvent(&event);
}
#endif /* !SDL_EVENTS_DISABLED */
player_index = SDL_GetPlayerIndexForJoystickID(instance_id);
if (player_index >= 0) {
@ -2125,7 +2113,6 @@ int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, S
/* Post the event, if desired */
posted = 0;
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(SDL_EVENT_JOYSTICK_AXIS_MOTION)) {
SDL_Event event;
event.type = SDL_EVENT_JOYSTICK_AXIS_MOTION;
@ -2135,7 +2122,6 @@ int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, S
event.jaxis.value = value;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return posted;
}
@ -2169,7 +2155,6 @@ int SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uin
/* Post the event, if desired */
posted = 0;
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(SDL_EVENT_JOYSTICK_HAT_MOTION)) {
SDL_Event event;
event.type = SDL_EVENT_JOYSTICK_HAT_MOTION;
@ -2179,14 +2164,12 @@ int SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uin
event.jhat.value = value;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return posted;
}
int SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, Uint8 state)
{
int posted;
#ifndef SDL_EVENTS_DISABLED
SDL_Event event;
SDL_AssertJoysticksLocked();
@ -2202,7 +2185,6 @@ int SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 butto
/* Invalid state -- bail */
return 0;
}
#endif /* !SDL_EVENTS_DISABLED */
SDL_AssertJoysticksLocked();
@ -2229,7 +2211,6 @@ int SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 butto
/* Post the event, if desired */
posted = 0;
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(event.type)) {
event.common.timestamp = timestamp;
event.jbutton.which = joystick->instance_id;
@ -2237,7 +2218,6 @@ int SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 butto
event.jbutton.state = state;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return posted;
}
@ -2352,7 +2332,6 @@ void SDL_UpdateJoysticks(void)
SDL_UnlockJoysticks();
}
#ifndef SDL_EVENTS_DISABLED
static const Uint32 SDL_joystick_event_list[] = {
SDL_EVENT_JOYSTICK_AXIS_MOTION,
SDL_EVENT_JOYSTICK_HAT_MOTION,
@ -2362,24 +2341,19 @@ static const Uint32 SDL_joystick_event_list[] = {
SDL_EVENT_JOYSTICK_REMOVED,
SDL_EVENT_JOYSTICK_BATTERY_UPDATED
};
#endif
void SDL_SetJoystickEventsEnabled(SDL_bool enabled)
{
#ifndef SDL_EVENTS_DISABLED
unsigned int i;
for (i = 0; i < SDL_arraysize(SDL_joystick_event_list); ++i) {
SDL_SetEventEnabled(SDL_joystick_event_list[i], enabled);
}
#endif /* SDL_EVENTS_DISABLED */
}
SDL_bool SDL_JoystickEventsEnabled(void)
{
SDL_bool enabled = SDL_FALSE;
#ifndef SDL_EVENTS_DISABLED
unsigned int i;
for (i = 0; i < SDL_arraysize(SDL_joystick_event_list); ++i) {
@ -2388,8 +2362,6 @@ SDL_bool SDL_JoystickEventsEnabled(void)
break;
}
}
#endif /* !SDL_EVENTS_DISABLED */
return enabled;
}
@ -3369,7 +3341,6 @@ 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) {
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(SDL_EVENT_JOYSTICK_BATTERY_UPDATED)) {
SDL_Event event;
event.type = SDL_EVENT_JOYSTICK_BATTERY_UPDATED;
@ -3378,7 +3349,6 @@ void SDL_SendJoystickBatteryLevel(SDL_Joystick *joystick, SDL_JoystickPowerLevel
event.jbattery.level = ePowerLevel;
SDL_PushEvent(&event);
}
#endif /* !SDL_EVENTS_DISABLED */
joystick->epowerlevel = ePowerLevel;
}
}
@ -3475,7 +3445,6 @@ int SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touch
/* Post the event, if desired */
posted = 0;
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(event_type)) {
SDL_Event event;
event.type = event_type;
@ -3488,7 +3457,6 @@ int SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touch
event.gtouchpad.pressure = pressure;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return posted;
}
@ -3516,7 +3484,6 @@ int SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorT
joystick->update_complete = timestamp;
/* Post the event, if desired */
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(SDL_EVENT_GAMEPAD_SENSOR_UPDATE)) {
SDL_Event event;
event.type = SDL_EVENT_GAMEPAD_SENSOR_UPDATE;
@ -3532,7 +3499,6 @@ int SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorT
event.gsensor.sensor_timestamp = sensor_timestamp;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
}
break;
}

View File

@ -25,12 +25,10 @@
#include "../SDL_joystick_c.h"
#include "../hidapi/SDL_hidapijoystick_c.h"
#include "../usb_ids.h"
#include "../../events/SDL_events_c.h"
#include "SDL_mfijoystick_c.h"
#ifndef SDL_EVENTS_DISABLED
#include "../../events/SDL_events_c.h"
#endif
#if TARGET_OS_IOS
#define SDL_JOYSTICK_iOS_ACCELEROMETER

View File

@ -24,9 +24,7 @@
#include "SDL_syssensor.h"
#ifndef SDL_EVENTS_DISABLED
#include "../events/SDL_events_c.h"
#endif
#include "../joystick/SDL_gamepad_c.h"
static SDL_SensorDriver *SDL_sensor_drivers[] = {
@ -132,11 +130,9 @@ int SDL_InitSensors(void)
SDL_sensor_lock = SDL_CreateMutex();
}
#ifndef SDL_EVENTS_DISABLED
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
return -1;
}
#endif /* !SDL_EVENTS_DISABLED */
SDL_LockSensors();
@ -553,9 +549,7 @@ void SDL_QuitSensors(void)
SDL_sensor_drivers[i]->Quit();
}
#ifndef SDL_EVENTS_DISABLED
SDL_QuitSubSystem(SDL_INIT_EVENTS);
#endif
SDL_sensors_initialized = SDL_FALSE;
@ -578,7 +572,6 @@ int SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_tim
/* Post the event, if desired */
posted = 0;
#ifndef SDL_EVENTS_DISABLED
if (SDL_EventEnabled(SDL_EVENT_SENSOR_UPDATE)) {
SDL_Event event;
event.type = SDL_EVENT_SENSOR_UPDATE;
@ -590,7 +583,6 @@ int SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_tim
event.sensor.sensor_timestamp = sensor_timestamp;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
SDL_GamepadSensorWatcher(timestamp, sensor->instance_id, sensor_timestamp, data, num_values);