From 3eb59cb7a97fe726fd177e48d3ca6ed699ba3f91 Mon Sep 17 00:00:00 2001 From: Nintorch <92302738+Nintorch@users.noreply.github.com> Date: Thu, 28 May 2026 00:03:32 +0500 Subject: [PATCH] [skip ci] Code cleanup --- src/joystick/hidapi/SDL_hidapi_rumble.c | 14 +++++++------- src/joystick/hidapi/SDL_hidapijoystick.c | 12 ++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapi_rumble.c b/src/joystick/hidapi/SDL_hidapi_rumble.c index 68ec667f41..4afbb70394 100644 --- a/src/joystick/hidapi/SDL_hidapi_rumble.c +++ b/src/joystick/hidapi/SDL_hidapi_rumble.c @@ -49,7 +49,7 @@ typedef struct SDL_HIDAPI_RumbleContext SDL_HIDAPI_RumbleRequest *requests_tail; } SDL_HIDAPI_RumbleContext; -#ifndef SDL_PLATFORM_EMSCRIPTEN +#ifndef SDL_THREADS_DISABLED #ifndef SDL_THREAD_SAFETY_ANALYSIS static #endif @@ -57,7 +57,7 @@ SDL_Mutex *SDL_HIDAPI_rumble_lock; #endif static SDL_HIDAPI_RumbleContext rumble_context SDL_GUARDED_BY(SDL_HIDAPI_rumble_lock); -#ifndef SDL_PLATFORM_EMSCRIPTEN // Threads are not used for the web +#ifndef SDL_THREADS_DISABLED static int SDLCALL SDL_HIDAPI_RumbleThread(void *data) { SDL_HIDAPI_RumbleContext *ctx = (SDL_HIDAPI_RumbleContext *)data; @@ -168,7 +168,7 @@ static bool SDL_HIDAPI_StartRumbleThread(SDL_HIDAPI_RumbleContext *ctx) bool SDL_HIDAPI_LockRumble(void) { -#ifndef SDL_PLATFORM_EMSCRIPTEN +#ifndef SDL_THREADS_DISABLED SDL_HIDAPI_RumbleContext *ctx = &rumble_context; if (SDL_CompareAndSwapAtomicInt(&ctx->initialized, false, true)) { @@ -184,7 +184,7 @@ bool SDL_HIDAPI_LockRumble(void) bool SDL_HIDAPI_GetPendingRumbleLocked(SDL_HIDAPI_Device *device, Uint8 **data, int **size, int *maximum_size) { -#ifndef SDL_PLATFORM_EMSCRIPTEN +#ifndef SDL_THREADS_DISABLED SDL_HIDAPI_RumbleContext *ctx = &rumble_context; SDL_HIDAPI_RumbleRequest *request, *found; @@ -220,7 +220,7 @@ int SDL_HIDAPI_SendRumbleWithCallbackAndUnlock(SDL_HIDAPI_Device *device, const return -1; } -#ifndef SDL_PLATFORM_EMSCRIPTEN +#ifndef SDL_THREADS_DISABLED request = (SDL_HIDAPI_RumbleRequest *)SDL_calloc(1, sizeof(*request)); if (!request) { SDL_HIDAPI_UnlockRumble(); @@ -254,7 +254,7 @@ int SDL_HIDAPI_SendRumbleWithCallbackAndUnlock(SDL_HIDAPI_Device *device, const void SDL_HIDAPI_UnlockRumble(void) { -#ifndef SDL_PLATFORM_EMSCRIPTEN +#ifndef SDL_THREADS_DISABLED SDL_UnlockMutex(SDL_HIDAPI_rumble_lock); #endif } @@ -287,7 +287,7 @@ int SDL_HIDAPI_SendRumble(SDL_HIDAPI_Device *device, const Uint8 *data, int size void SDL_HIDAPI_QuitRumble(void) { -#ifndef SDL_PLATFORM_EMSCRIPTEN +#ifndef SDL_THREADS_DISABLED SDL_HIDAPI_RumbleContext *ctx = &rumble_context; if (SDL_GetAtomicInt(&ctx->running)) { diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index a45c64c63f..e54f72337f 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -642,7 +642,6 @@ void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 vendor_id, Uint16 device->guid = SDL_CreateJoystickGUID(device->guid.data[0], vendor_id, product_id, device->version, device->manufacturer_string, device->product_string, 'h', 0); } -#ifndef SDL_PLATFORM_EMSCRIPTEN static void HIDAPI_UpdateJoystickSerial(SDL_HIDAPI_Device *device) { int i; @@ -657,7 +656,6 @@ static void HIDAPI_UpdateJoystickSerial(SDL_HIDAPI_Device *device) } } } -#endif static bool HIDAPI_SerialIsEmpty(SDL_HIDAPI_Device *device) { @@ -679,16 +677,15 @@ void HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial) { #ifdef SDL_PLATFORM_EMSCRIPTEN // Don't include the serial number for the web to decrease the fingerprinting surface -#else + serial = NULL; +#endif if (serial && *serial && (!device->serial || SDL_strcmp(serial, device->serial) != 0)) { SDL_free(device->serial); device->serial = SDL_strdup(serial); HIDAPI_UpdateJoystickSerial(device); } -#endif } -#ifndef SDL_PLATFORM_EMSCRIPTEN static int wcstrcmp(const wchar_t *str1, const char *str2) { int result; @@ -703,19 +700,18 @@ static int wcstrcmp(const wchar_t *str1, const char *str2) } return result; } -#endif static void HIDAPI_SetDeviceSerialW(SDL_HIDAPI_Device *device, const wchar_t *serial) { #ifdef SDL_PLATFORM_EMSCRIPTEN // Don't include the serial number for the web to decrease the fingerprinting surface -#else + serial = NULL; +#endif if (serial && *serial && (!device->serial || wcstrcmp(serial, device->serial) != 0)) { SDL_free(device->serial); device->serial = HIDAPI_ConvertString(serial); HIDAPI_UpdateJoystickSerial(device); } -#endif } bool HIDAPI_HasConnectedUSBDevice(const char *serial)