From 0f3882dbe609ba76843c9b788a2ca02e8a50d437 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 2 Feb 2026 18:32:02 +0100 Subject: [PATCH] Android: update with suggestions --- src/core/android/SDL_android.c | 4 ++-- src/events/SDL_events.c | 16 ++++++++++++---- src/joystick/android/SDL_sysjoystick.c | 6 +++--- src/joystick/android/SDL_sysjoystick_c.h | 2 +- src/video/android/SDL_androidevents.h | 1 - src/video/android/SDL_androidwindow.h | 3 --- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index a6a9d56292..019e4e89e1 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -1358,7 +1358,7 @@ JNIEXPORT jboolean JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)( jint device_id, jint keycode) { #ifdef SDL_JOYSTICK_ANDROID -int button = android_keycode_to_SDL(keycode); +int button = Android_keycode_to_SDL(keycode); if (button >= 0) { RPC_Prepare(onNativePadDown); RPC_Add(device_id); @@ -1385,7 +1385,7 @@ JNIEXPORT jboolean JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)( jint device_id, jint keycode) { #ifdef SDL_JOYSTICK_ANDROID - int button = android_keycode_to_SDL(keycode); + int button = Android_keycode_to_SDL(keycode); if (button >= 0) { RPC_Prepare(onNativePadUp); RPC_Add(device_id); diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 8bebf75ec6..a1ed8e4129 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -1514,8 +1514,12 @@ static void SDL_PumpEventsInternal(bool push_sentinel) #ifdef SDL_PLATFORM_ANDROID // Android event processing is independent of the video subsystem SDL_VideoDevice *_this = SDL_GetVideoDevice(); - SDL_Window *window = _this->windows; - Android_PumpEvents(window, 0); + if (_this) { + SDL_Window *window = _this->windows; + if (window) { + Android_PumpEvents(window, 0); + } + } #else // Get events from the video subsystem SDL_VideoDevice *_this = SDL_GetVideoDevice(); @@ -1750,8 +1754,12 @@ bool SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS) } SDL_VideoDevice *_this = SDL_GetVideoDevice(); - SDL_Window *window = _this->windows; - Android_PumpEvents(window, delay); + if (_this) { + SDL_Window *window = _this->windows; + if (window) { + Android_PumpEvents(window, delay); + } + } } #else SDL_VideoDevice *_this = SDL_GetVideoDevice(); diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index 04119a4dfb..cd0026ed40 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -64,7 +64,7 @@ static int numjoysticks = 0; * This code manipulation is done to get a sequential list of codes. * FIXME: This is only suited for the case where we use a fixed number of buttons determined by ANDROID_MAX_NBUTTONS */ -int android_keycode_to_SDL(int keycode) +int Android_keycode_to_SDL(int keycode) { // FIXME: If this function gets too unwieldy in the future, replace with a lookup table int button = 0; @@ -198,7 +198,7 @@ bool Android_OnPadDown(int device_id, int keycode) { Uint64 timestamp = SDL_GetTicksNS(); SDL_joylist_item *item; - int button = android_keycode_to_SDL(keycode); + int button = Android_keycode_to_SDL(keycode); if (button >= 0) { SDL_LockJoysticks(); item = JoystickByDeviceId(device_id); @@ -218,7 +218,7 @@ bool Android_OnPadUp(int device_id, int keycode) { Uint64 timestamp = SDL_GetTicksNS(); SDL_joylist_item *item; - int button = android_keycode_to_SDL(keycode); + int button = Android_keycode_to_SDL(keycode); if (button >= 0) { SDL_LockJoysticks(); item = JoystickByDeviceId(device_id); diff --git a/src/joystick/android/SDL_sysjoystick_c.h b/src/joystick/android/SDL_sysjoystick_c.h index 32aa9a6ffd..c72de243d5 100644 --- a/src/joystick/android/SDL_sysjoystick_c.h +++ b/src/joystick/android/SDL_sysjoystick_c.h @@ -28,7 +28,7 @@ #include "../SDL_sysjoystick.h" -extern int android_keycode_to_SDL(int keycode); +extern int Android_keycode_to_SDL(int keycode); extern bool Android_OnPadDown(int device_id, int keycode); extern bool Android_OnPadUp(int device_id, int keycode); extern bool Android_OnJoy(int device_id, int axisnum, float value); diff --git a/src/video/android/SDL_androidevents.h b/src/video/android/SDL_androidevents.h index b70a69fa01..1a9062bd62 100644 --- a/src/video/android/SDL_androidevents.h +++ b/src/video/android/SDL_androidevents.h @@ -24,5 +24,4 @@ extern void Android_InitEvents(void); extern void Android_PumpEvents(SDL_Window *window, Sint64 timeoutNS); extern bool Android_WaitActiveAndLockActivity(SDL_Window *window); extern void Android_QuitEvents(void); - extern void Android_PumpLifecycleEvents(SDL_Window *window); diff --git a/src/video/android/SDL_androidwindow.h b/src/video/android/SDL_androidwindow.h index b788f3b763..90f65dd0c3 100644 --- a/src/video/android/SDL_androidwindow.h +++ b/src/video/android/SDL_androidwindow.h @@ -47,11 +47,8 @@ struct SDL_WindowData }; - bool Android_nativeSurfaceCreated(SDL_Window *window); bool Android_nativeSurfaceChanged(SDL_Window *window); void Android_nativeSurfaceDestroyed(SDL_Window *window); - - #endif // SDL_androidwindow_h_