Use C++ style comments consistently in SDL source code

Implemented using this script:

find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
    core/linux/SDL_evdev_kbd_default_keymap.h \
    events/imKStoUCS.* \
    hidapi \
    joystick/controller_type.c \
    joystick/controller_type.h \
    joystick/hidapi/steam/controller_constants.h \
    joystick/hidapi/steam/controller_structs.h \
    joystick/SDL_gamepad_db.h \
    libm \
    render/*/*Shader*.h \
    render/vitagxm/SDL_render_vita_gxm_shaders.h \
    render/metal/SDL_shaders_metal_*.h \
    stdlib/SDL_malloc.c \
    stdlib/SDL_qsort.c \
    stdlib/SDL_strtokr.c \
    test/ \
    video/directx/SDL_d3d12_xbox_cmacros.h \
    video/directx/d3d12.h \
    video/directx/d3d12sdklayers.h \
    video/khronos \
    video/x11/edid-parse.c \
    video/x11/xsettings-client.* \
    video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
This commit is contained in:
Sam Lantinga 2024-08-22 10:30:45 -07:00
parent 658fc3db0f
commit 6501e90018
743 changed files with 11882 additions and 11882 deletions

View file

@ -52,12 +52,12 @@
#define SDL_JAVA_CONTROLLER_INTERFACE(function) CONCAT1(SDL_JAVA_PREFIX, SDLControllerManager, function)
#define SDL_JAVA_INTERFACE_INPUT_CONNECTION(function) CONCAT1(SDL_JAVA_PREFIX, SDLInputConnection, function)
/* Audio encoding definitions */
// Audio encoding definitions
#define ENCODING_PCM_8BIT 3
#define ENCODING_PCM_16BIT 2
#define ENCODING_PCM_FLOAT 4
/* Java class SDLActivity */
// Java class SDLActivity
JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetVersion)(
JNIEnv *env, jclass cls);
@ -232,7 +232,7 @@ static JNINativeMethod SDLActivity_tab[] = {
{ "onNativeFileDialog", "(I[Ljava/lang/String;I)V", SDL_JAVA_INTERFACE(onNativeFileDialog) }
};
/* Java class SDLInputConnection */
// Java class SDLInputConnection
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(
JNIEnv *env, jclass cls,
jstring text, jint newCursorPosition);
@ -246,7 +246,7 @@ static JNINativeMethod SDLInputConnection_tab[] = {
{ "nativeGenerateScancodeForUnichar", "(C)V", SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeGenerateScancodeForUnichar) }
};
/* Java class SDLAudioManager */
// Java class SDLAudioManager
JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(
JNIEnv *env, jclass jcls);
@ -264,7 +264,7 @@ static JNINativeMethod SDLAudioManager_tab[] = {
{ "removeAudioDevice", "(ZI)V", SDL_JAVA_AUDIO_INTERFACE(removeAudioDevice) }
};
/* Java class SDLControllerManager */
// Java class SDLControllerManager
JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(
JNIEnv *env, jclass jcls);
@ -313,8 +313,8 @@ static JNINativeMethod SDLControllerManager_tab[] = {
{ "nativeRemoveHaptic", "(I)I", SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic) }
};
/* Uncomment this to log messages entering and exiting methods in this file */
/* #define DEBUG_JNI */
// Uncomment this to log messages entering and exiting methods in this file
// #define DEBUG_JNI
static void checkJNIReady(void);
@ -330,10 +330,10 @@ static pthread_key_t mThreadKey;
static pthread_once_t key_once = PTHREAD_ONCE_INIT;
static JavaVM *mJavaVM = NULL;
/* Main activity */
// Main activity
static jclass mActivityClass;
/* method signatures */
// method signatures
static jmethodID midClipboardGetText;
static jmethodID midClipboardHasText;
static jmethodID midClipboardSetText;
@ -366,25 +366,25 @@ static jmethodID midSupportsRelativeMouse;
static jmethodID midOpenFileDescriptor;
static jmethodID midShowFileDialog;
/* audio manager */
// audio manager
static jclass mAudioManagerClass;
/* method signatures */
// method signatures
static jmethodID midRegisterAudioDeviceCallback;
static jmethodID midUnregisterAudioDeviceCallback;
static jmethodID midAudioSetThreadPriority;
/* controller manager */
// controller manager
static jclass mControllerManagerClass;
/* method signatures */
// method signatures
static jmethodID midPollInputDevices;
static jmethodID midPollHapticDevices;
static jmethodID midHapticRun;
static jmethodID midHapticRumble;
static jmethodID midHapticStop;
/* Accelerometer data storage */
// Accelerometer data storage
static SDL_DisplayOrientation displayNaturalOrientation;
static SDL_DisplayOrientation displayCurrentOrientation;
static float fLastAccelerometer[3];
@ -392,13 +392,13 @@ static SDL_bool bHasNewData;
static SDL_bool bHasEnvironmentVariables;
/* Android AssetManager */
// Android AssetManager
static void Internal_Android_Create_AssetManager(void);
static void Internal_Android_Destroy_AssetManager(void);
static AAssetManager *asset_manager = NULL;
static jobject javaAssetManagerRef = 0;
/* Re-create activity hint */
// Re-create activity hint
static SDL_AtomicInt bAllowRecreateActivity;
static SDL_Mutex *Android_ActivityMutex = NULL;
@ -433,7 +433,7 @@ static int Android_NumLifecycleEvents;
* (except for some lost CPU cycles)
*/
/* Set local storage value */
// Set local storage value
static int Android_JNI_SetEnv(JNIEnv *env)
{
int status = pthread_setspecific(mThreadKey, env);
@ -443,16 +443,16 @@ static int Android_JNI_SetEnv(JNIEnv *env)
return status;
}
/* Get local storage value */
// Get local storage value
JNIEnv *Android_JNI_GetEnv(void)
{
/* Get JNIEnv from the Thread local storage */
// Get JNIEnv from the Thread local storage
JNIEnv *env = pthread_getspecific(mThreadKey);
if (!env) {
/* If it fails, try to attach ! (e.g the thread isn't created with SDL_CreateThread() */
// If it fails, try to attach ! (e.g the thread isn't created with SDL_CreateThread()
int status;
/* There should be a JVM */
// There should be a JVM
if (!mJavaVM) {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed, there is no JavaVM");
return NULL;
@ -466,7 +466,7 @@ JNIEnv *Android_JNI_GetEnv(void)
return NULL;
}
/* Save JNIEnv into the Thread local storage */
// Save JNIEnv into the Thread local storage
if (Android_JNI_SetEnv(env) < 0) {
return NULL;
}
@ -475,13 +475,13 @@ JNIEnv *Android_JNI_GetEnv(void)
return env;
}
/* Set up an external thread for using JNI with Android_JNI_GetEnv() */
// Set up an external thread for using JNI with Android_JNI_GetEnv()
int Android_JNI_SetupThread(void)
{
JNIEnv *env;
int status;
/* There should be a JVM */
// There should be a JVM
if (!mJavaVM) {
__android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed, there is no JavaVM");
return 0;
@ -495,7 +495,7 @@ int Android_JNI_SetupThread(void)
return 0;
}
/* Save JNIEnv into the Thread local storage */
// Save JNIEnv into the Thread local storage
if (Android_JNI_SetEnv(env) < 0) {
return 0;
}
@ -503,10 +503,10 @@ int Android_JNI_SetupThread(void)
return 1;
}
/* Destructor called for each thread where mThreadKey is not NULL */
// Destructor called for each thread where mThreadKey is not NULL
static void Android_JNI_ThreadDestroyed(void *value)
{
/* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */
// The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required
JNIEnv *env = (JNIEnv *)value;
if (env) {
(*mJavaVM)->DetachCurrentThread(mJavaVM);
@ -514,7 +514,7 @@ static void Android_JNI_ThreadDestroyed(void *value)
}
}
/* Creation of local storage mThreadKey */
// Creation of local storage mThreadKey
static void Android_JNI_CreateKey(void)
{
int status = pthread_key_create(&mThreadKey, Android_JNI_ThreadDestroyed);
@ -540,7 +540,7 @@ static void register_methods(JNIEnv *env, const char *classname, JNINativeMethod
}
}
/* Library init */
// Library init
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
{
JNIEnv *env = NULL;
@ -565,14 +565,14 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
void checkJNIReady(void)
{
if (!mActivityClass || !mAudioManagerClass || !mControllerManagerClass) {
/* We aren't fully initialized, let's just return. */
// We aren't fully initialized, let's just return.
return;
}
SDL_SetMainReady();
}
/* Get SDL version -- called before SDL_main() to verify JNI bindings */
// Get SDL version -- called before SDL_main() to verify JNI bindings
JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetVersion)(JNIEnv *env, jclass cls)
{
char version[128];
@ -582,12 +582,12 @@ JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetVersion)(JNIEnv *env, jcla
return (*env)->NewStringUTF(env, version);
}
/* Activity initialization -- called before SDL_main() to initialize JNI bindings */
// Activity initialization -- called before SDL_main() to initialize JNI bindings
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cls)
{
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeSetupJNI()");
/* Start with a clean slate */
// Start with a clean slate
SDL_ClearError();
/*
@ -596,7 +596,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
*/
Android_JNI_CreateKey_once();
/* Save JNIEnv of SDLActivity */
// Save JNIEnv of SDLActivity
Android_JNI_SetEnv(env);
if (!mJavaVM) {
@ -607,7 +607,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
* (Eg. Java sending Touch events, while native code is destroying the main SDL_Window. )
*/
if (!Android_ActivityMutex) {
Android_ActivityMutex = SDL_CreateMutex(); /* Could this be created twice if onCreate() is called a second time ? */
Android_ActivityMutex = SDL_CreateMutex(); // Could this be created twice if onCreate() is called a second time ?
}
if (!Android_ActivityMutex) {
@ -695,7 +695,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
checkJNIReady();
}
/* Audio initialization -- called before SDL_main() to initialize JNI bindings */
// Audio initialization -- called before SDL_main() to initialize JNI bindings
JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cls)
{
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "AUDIO nativeSetupJNI()");
@ -719,7 +719,7 @@ JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(JNIEnv *env, jcl
checkJNIReady();
}
/* Controller initialization -- called before SDL_main() to initialize JNI bindings */
// Controller initialization -- called before SDL_main() to initialize JNI bindings
JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cls)
{
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "CONTROLLER nativeSetupJNI()");
@ -744,7 +744,7 @@ JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(JNIEnv *env
checkJNIReady();
}
/* SDL main function prototype */
// SDL main function prototype
typedef int (*SDL_main_func)(int argc, char *argv[]);
static int run_count = 0;
@ -781,7 +781,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeInitMainThread)(
}
run_count += 1;
/* Save JNIEnv of SDLThread */
// Save JNIEnv of SDLThread
Android_JNI_SetEnv(env);
}
@ -793,7 +793,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeCleanupMainThread)(
Android_JNI_SetEnv(NULL);
}
/* Start up the SDL app */
// Start up the SDL app
JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls, jstring library, jstring function, jobject array)
{
int status = -1;
@ -826,9 +826,9 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
char **argv;
SDL_bool isstack;
/* Prepare the arguments. */
// Prepare the arguments.
len = (*env)->GetArrayLength(env, array);
argv = SDL_small_alloc(char *, 1 + len + 1, &isstack); /* !!! FIXME: check for NULL */
argv = SDL_small_alloc(char *, 1 + len + 1, &isstack); // !!! FIXME: check for NULL
argc = 0;
/* Use the name "app_process" so PHYSFS_platformCalcBaseDir() works.
https://github.com/love2d/love-android/issues/24
@ -852,10 +852,10 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
}
argv[argc] = NULL;
/* Run the application. */
// Run the application.
status = SDL_main(argc, argv);
/* Release the arguments. */
// Release the arguments.
for (i = 0; i < argc; ++i) {
SDL_free(argv[i]);
}
@ -873,8 +873,8 @@ JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv *env, jclass cls,
}
(*env)->ReleaseStringUTFChars(env, library, library_file);
/* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
/* exit(status); */
// Do not issue an exit or the whole application will terminate instead of just the SDL thread
// exit(status);
return status;
}
@ -984,7 +984,7 @@ void Android_UnlockActivityMutex(void)
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Drop file */
// Drop file
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
JNIEnv *env, jclass jcls,
jstring filename)
@ -995,7 +995,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
SDL_SendDropComplete(NULL);
}
/* Set screen resolution */
// Set screen resolution
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetScreenResolution)(
JNIEnv *env, jclass jcls,
jint surfaceWidth, jint surfaceHeight,
@ -1008,7 +1008,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetScreenResolution)(
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Resize */
// Resize
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
JNIEnv *env, jclass jcls)
{
@ -1116,7 +1116,7 @@ SDL_JAVA_AUDIO_INTERFACE(removeAudioDevice)(JNIEnv *env, jclass jcls, jboolean r
#endif
}
/* Paddown */
// Paddown
JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)(
JNIEnv *env, jclass jcls,
jint device_id, jint keycode)
@ -1125,10 +1125,10 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)(
return Android_OnPadDown(device_id, keycode);
#else
return -1;
#endif /* SDL_JOYSTICK_ANDROID */
#endif // SDL_JOYSTICK_ANDROID
}
/* Padup */
// Padup
JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)(
JNIEnv *env, jclass jcls,
jint device_id, jint keycode)
@ -1137,27 +1137,27 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)(
return Android_OnPadUp(device_id, keycode);
#else
return -1;
#endif /* SDL_JOYSTICK_ANDROID */
#endif // SDL_JOYSTICK_ANDROID
}
/* Joy */
// Joy
JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeJoy)(
JNIEnv *env, jclass jcls,
jint device_id, jint axis, jfloat value)
{
#ifdef SDL_JOYSTICK_ANDROID
Android_OnJoy(device_id, axis, value);
#endif /* SDL_JOYSTICK_ANDROID */
#endif // SDL_JOYSTICK_ANDROID
}
/* POV Hat */
// POV Hat
JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeHat)(
JNIEnv *env, jclass jcls,
jint device_id, jint hat_id, jint x, jint y)
{
#ifdef SDL_JOYSTICK_ANDROID
Android_OnHat(device_id, hat_id, x, y);
#endif /* SDL_JOYSTICK_ANDROID */
#endif // SDL_JOYSTICK_ANDROID
}
JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)(
@ -1177,7 +1177,7 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)(
(*env)->ReleaseStringUTFChars(env, device_desc, desc);
#else
retval = -1;
#endif /* SDL_JOYSTICK_ANDROID */
#endif // SDL_JOYSTICK_ANDROID
return retval;
}
@ -1189,7 +1189,7 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)(
return Android_RemoveJoystick(device_id);
#else
return -1;
#endif /* SDL_JOYSTICK_ANDROID */
#endif // SDL_JOYSTICK_ANDROID
}
JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)(
@ -1204,7 +1204,7 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)(
(*env)->ReleaseStringUTFChars(env, device_name, name);
#else
retval = -1;
#endif /* SDL_HAPTIC_ANDROID */
#endif // SDL_HAPTIC_ANDROID
return retval;
}
@ -1218,7 +1218,7 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)(
#endif
}
/* Called from surfaceCreated() */
// Called from surfaceCreated()
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(JNIEnv *env, jclass jcls)
{
SDL_LockMutex(Android_ActivityMutex);
@ -1236,7 +1236,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(JNIEnv *env, j
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Called from surfaceChanged() */
// Called from surfaceChanged()
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, jclass jcls)
{
SDL_LockMutex(Android_ActivityMutex);
@ -1246,20 +1246,20 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, j
SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_WindowData *data = Android_Window->internal;
/* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
// If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here
if (data->egl_surface == EGL_NO_SURFACE) {
data->egl_surface = SDL_EGL_CreateSurface(_this, Android_Window, (NativeWindowType)data->native_window);
SDL_SetPointerProperty(SDL_GetWindowProperties(Android_Window), SDL_PROP_WINDOW_ANDROID_SURFACE_POINTER, data->egl_surface);
}
/* GL Context handling is done in the event loop because this function is run from the Java thread */
// GL Context handling is done in the event loop because this function is run from the Java thread
}
#endif
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Called from surfaceDestroyed() */
// Called from surfaceDestroyed()
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(JNIEnv *env, jclass jcls)
{
int nb_attempt = 50;
@ -1271,7 +1271,7 @@ retry:
if (Android_Window) {
SDL_WindowData *data = Android_Window->internal;
/* Wait for Main thread being paused and context un-activated to release 'egl_surface' */
// Wait for Main thread being paused and context un-activated to release 'egl_surface'
if ((Android_Window->flags & SDL_WINDOW_OPENGL) && !data->backup_done) {
nb_attempt -= 1;
if (nb_attempt == 0) {
@ -1295,13 +1295,13 @@ retry:
data->native_window = NULL;
}
/* GL Context handling is done in the event loop because this function is run from the Java thread */
// GL Context handling is done in the event loop because this function is run from the Java thread
}
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Keydown */
// Keydown
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyDown)(
JNIEnv *env, jclass jcls,
jint keycode)
@ -1315,7 +1315,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyDown)(
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Keyup */
// Keyup
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
JNIEnv *env, jclass jcls,
jint keycode)
@ -1329,7 +1329,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Virtual keyboard return key might stop text input */
// Virtual keyboard return key might stop text input
JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(onNativeSoftReturnKey)(
JNIEnv *env, jclass jcls)
{
@ -1340,15 +1340,15 @@ JNIEXPORT jboolean JNICALL SDL_JAVA_INTERFACE(onNativeSoftReturnKey)(
return JNI_FALSE;
}
/* Keyboard Focus Lost */
// Keyboard Focus Lost
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
JNIEnv *env, jclass jcls)
{
/* Calling SDL_StopTextInput will take care of hiding the keyboard and cleaning up the DummyText widget */
// Calling SDL_StopTextInput will take care of hiding the keyboard and cleaning up the DummyText widget
SDL_StopTextInput(Android_Window);
}
/* Touch */
// Touch
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeTouch)(
JNIEnv *env, jclass jcls,
jint touch_device_id_in, jint pointer_finger_id_in,
@ -1361,7 +1361,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeTouch)(
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Mouse */
// Mouse
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
JNIEnv *env, jclass jcls,
jint button, jint action, jfloat x, jfloat y, jboolean relative)
@ -1373,7 +1373,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
SDL_UnlockMutex(Android_ActivityMutex);
}
/* Accelerometer */
// Accelerometer
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
JNIEnv *env, jclass jcls,
jfloat x, jfloat y, jfloat z)
@ -1384,14 +1384,14 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
bHasNewData = SDL_TRUE;
}
/* Clipboard */
// Clipboard
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeClipboardChanged)(
JNIEnv *env, jclass jcls)
{
SDL_SendClipboardUpdate();
}
/* Low memory */
// Low memory
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
JNIEnv *env, jclass cls)
{
@ -1406,21 +1406,21 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeLocaleChanged)(
SDL_SendAppEvent(SDL_EVENT_LOCALE_CHANGED);
}
/* Dark mode */
// Dark mode
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDarkModeChanged)(
JNIEnv *env, jclass cls, jboolean enabled)
{
Android_SetDarkMode(enabled);
}
/* Send Quit event to "SDLThread" thread */
// Send Quit event to "SDLThread" thread
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSendQuit)(
JNIEnv *env, jclass cls)
{
Android_SendLifecycleEvent(SDL_ANDROID_LIFECYCLE_DESTROY);
}
/* Activity ends */
// Activity ends
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
JNIEnv *env, jclass cls)
{
@ -1453,7 +1453,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
}
}
/* Pause */
// Pause
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
JNIEnv *env, jclass cls)
{
@ -1462,7 +1462,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
Android_SendLifecycleEvent(SDL_ANDROID_LIFECYCLE_PAUSE);
}
/* Resume */
// Resume
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeResume)(
JNIEnv *env, jclass cls)
{
@ -1692,21 +1692,21 @@ void Android_AudioThreadInit(SDL_AudioDevice *device)
Android_JNI_AudioSetThreadPriority((int) device->recording, (int)device->instance_id);
}
/* Test for an exception and call SDL_SetError with its detail if one occurs */
/* If the parameter silent is truthy then SDL_SetError() will not be called. */
// Test for an exception and call SDL_SetError with its detail if one occurs
// If the parameter silent is truthy then SDL_SetError() will not be called.
static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent)
{
JNIEnv *env = Android_JNI_GetEnv();
jthrowable exception;
/* Detect mismatch LocalReferenceHolder_Init/Cleanup */
// Detect mismatch LocalReferenceHolder_Init/Cleanup
SDL_assert(SDL_AtomicGet(&s_active) > 0);
exception = (*env)->ExceptionOccurred(env);
if (exception != NULL) {
jmethodID mid;
/* Until this happens most JNI operations have undefined behaviour */
// Until this happens most JNI operations have undefined behaviour
(*env)->ExceptionClear(env);
if (!silent) {
@ -1754,10 +1754,10 @@ static void Internal_Android_Create_AssetManager(void)
return;
}
/* context = SDLActivity.getContext(); */
// context = SDLActivity.getContext();
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
/* javaAssetManager = context.getAssets(); */
// javaAssetManager = context.getAssets();
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
"getAssets", "()Landroid/content/res/AssetManager;");
javaAssetManager = (*env)->CallObjectMethod(env, context, mid);
@ -1901,7 +1901,7 @@ int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seco
return -1;
}
/* context = SDLActivity.getContext(); */
// context = SDLActivity.getContext();
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED");
@ -1922,7 +1922,7 @@ int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seco
imid = (*env)->GetMethodID(env, cls, "getIntExtra", "(Ljava/lang/String;I)I");
/* Watch out for C89 scoping rules because of the macro */
// Watch out for C89 scoping rules because of the macro
#define GET_INT_EXTRA(var, key) \
int var; \
iname = (*env)->NewStringUTF(env, key); \
@ -1931,7 +1931,7 @@ int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seco
bmid = (*env)->GetMethodID(env, cls, "getBooleanExtra", "(Ljava/lang/String;Z)Z");
/* Watch out for C89 scoping rules because of the macro */
// Watch out for C89 scoping rules because of the macro
#define GET_BOOL_EXTRA(var, key) \
int var; \
bname = (*env)->NewStringUTF(env, key); \
@ -1939,49 +1939,49 @@ int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seco
(*env)->DeleteLocalRef(env, bname);
if (plugged) {
/* Watch out for C89 scoping rules because of the macro */
GET_INT_EXTRA(plug, "plugged") /* == BatteryManager.EXTRA_PLUGGED (API 5) */
// Watch out for C89 scoping rules because of the macro
GET_INT_EXTRA(plug, "plugged") // == BatteryManager.EXTRA_PLUGGED (API 5)
if (plug == -1) {
LocalReferenceHolder_Cleanup(&refs);
return -1;
}
/* 1 == BatteryManager.BATTERY_PLUGGED_AC */
/* 2 == BatteryManager.BATTERY_PLUGGED_USB */
// 1 == BatteryManager.BATTERY_PLUGGED_AC
// 2 == BatteryManager.BATTERY_PLUGGED_USB
*plugged = (0 < plug) ? 1 : 0;
}
if (charged) {
/* Watch out for C89 scoping rules because of the macro */
GET_INT_EXTRA(status, "status") /* == BatteryManager.EXTRA_STATUS (API 5) */
// Watch out for C89 scoping rules because of the macro
GET_INT_EXTRA(status, "status") // == BatteryManager.EXTRA_STATUS (API 5)
if (status == -1) {
LocalReferenceHolder_Cleanup(&refs);
return -1;
}
/* 5 == BatteryManager.BATTERY_STATUS_FULL */
// 5 == BatteryManager.BATTERY_STATUS_FULL
*charged = (status == 5) ? 1 : 0;
}
if (battery) {
GET_BOOL_EXTRA(present, "present") /* == BatteryManager.EXTRA_PRESENT (API 5) */
GET_BOOL_EXTRA(present, "present") // == BatteryManager.EXTRA_PRESENT (API 5)
*battery = present ? 1 : 0;
}
if (seconds) {
*seconds = -1; /* not possible */
*seconds = -1; // not possible
}
if (percent) {
int level;
int scale;
/* Watch out for C89 scoping rules because of the macro */
// Watch out for C89 scoping rules because of the macro
{
GET_INT_EXTRA(level_temp, "level") /* == BatteryManager.EXTRA_LEVEL (API 5) */
GET_INT_EXTRA(level_temp, "level") // == BatteryManager.EXTRA_LEVEL (API 5)
level = level_temp;
}
/* Watch out for C89 scoping rules because of the macro */
// Watch out for C89 scoping rules because of the macro
{
GET_INT_EXTRA(scale_temp, "scale") /* == BatteryManager.EXTRA_SCALE (API 5) */
GET_INT_EXTRA(scale_temp, "scale") // == BatteryManager.EXTRA_SCALE (API 5)
scale = scale_temp;
}
@ -1998,7 +1998,7 @@ int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seco
return 0;
}
/* Add all touch devices */
// Add all touch devices
void Android_JNI_InitTouch(void)
{
JNIEnv *env = Android_JNI_GetEnv();
@ -2035,7 +2035,7 @@ void Android_JNI_HapticStop(int device_id)
(*env)->CallStaticVoidMethod(env, mControllerManagerClass, midHapticStop, device_id);
}
/* See SDLActivity.java for constants. */
// See SDLActivity.java for constants.
#define COMMAND_SET_KEEP_SCREEN_ON 5
int SDL_SendAndroidMessage(Uint32 command, int param)
@ -2046,7 +2046,7 @@ int SDL_SendAndroidMessage(Uint32 command, int param)
return -1;
}
/* sends message to be handled on the UI event dispatch thread */
// sends message to be handled on the UI event dispatch thread
int Android_JNI_SendMessage(int command, int param)
{
JNIEnv *env = Android_JNI_GetEnv();
@ -2073,7 +2073,7 @@ void Android_JNI_ShowScreenKeyboard(int input_type, SDL_Rect *inputRect)
void Android_JNI_HideScreenKeyboard(void)
{
/* has to match Activity constant */
// has to match Activity constant
const int COMMAND_TEXTEDIT_HIDE = 3;
Android_JNI_SendMessage(COMMAND_TEXTEDIT_HIDE, 0);
}
@ -2104,7 +2104,7 @@ int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
env = Android_JNI_GetEnv();
/* convert parameters */
// convert parameters
clazz = (*env)->FindClass(env, "java/lang/String");
@ -2148,7 +2148,7 @@ int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
(*env)->DeleteLocalRef(env, clazz);
/* context = SDLActivity.getContext(); */
// context = SDLActivity.getContext();
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
clazz = (*env)->GetObjectClass(env, context);
@ -2167,7 +2167,7 @@ int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
(*env)->DeleteLocalRef(env, context);
(*env)->DeleteLocalRef(env, clazz);
/* delete parameters */
// delete parameters
(*env)->DeleteLocalRef(env, title);
(*env)->DeleteLocalRef(env, message);
@ -2193,14 +2193,14 @@ void *SDL_GetAndroidJNIEnv(void)
void *SDL_GetAndroidActivity(void)
{
/* See SDL_system.h for caveats on using this function. */
// See SDL_system.h for caveats on using this function.
JNIEnv *env = Android_JNI_GetEnv();
if (!env) {
return NULL;
}
/* return SDLActivity.getContext(); */
// return SDLActivity.getContext();
return (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
}
@ -2264,7 +2264,7 @@ const char *SDL_GetAndroidInternalStoragePath(void)
return NULL;
}
/* context = SDLActivity.getContext(); */
// context = SDLActivity.getContext();
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
if (!context) {
SDL_SetError("Couldn't get Android context!");
@ -2272,7 +2272,7 @@ const char *SDL_GetAndroidInternalStoragePath(void)
return NULL;
}
/* fileObj = context.getFilesDir(); */
// fileObj = context.getFilesDir();
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
"getFilesDir", "()Ljava/io/File;");
fileObject = (*env)->CallObjectMethod(env, context, mid);
@ -2282,7 +2282,7 @@ const char *SDL_GetAndroidInternalStoragePath(void)
return NULL;
}
/* path = fileObject.getCanonicalPath(); */
// path = fileObject.getCanonicalPath();
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, fileObject),
"getCanonicalPath", "()Ljava/lang/String;");
pathString = (jstring)(*env)->CallObjectMethod(env, fileObject, mid);
@ -2322,7 +2322,7 @@ Uint32 SDL_GetAndroidExternalStorageState(void)
state_string = (*env)->GetStringUTFChars(env, stateString, NULL);
/* Print an info message so people debugging know the storage state */
// Print an info message so people debugging know the storage state
__android_log_print(ANDROID_LOG_INFO, "SDL", "external storage state: %s", state_string);
if (SDL_strcmp(state_string, "mounted") == 0) {
@ -2358,10 +2358,10 @@ const char *SDL_GetAndroidExternalStoragePath(void)
return NULL;
}
/* context = SDLActivity.getContext(); */
// context = SDLActivity.getContext();
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
/* fileObj = context.getExternalFilesDir(); */
// fileObj = context.getExternalFilesDir();
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
"getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;");
fileObject = (*env)->CallObjectMethod(env, context, mid, NULL);
@ -2371,7 +2371,7 @@ const char *SDL_GetAndroidExternalStoragePath(void)
return NULL;
}
/* path = fileObject.getAbsolutePath(); */
// path = fileObject.getAbsolutePath();
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, fileObject),
"getAbsolutePath", "()Ljava/lang/String;");
pathString = (jstring)(*env)->CallObjectMethod(env, fileObject, mid);
@ -2404,10 +2404,10 @@ const char *SDL_GetAndroidCachePath(void)
return NULL;
}
/* context = SDLActivity.getContext(); */
// context = SDLActivity.getContext();
context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
/* fileObj = context.getExternalFilesDir(); */
// fileObj = context.getExternalFilesDir();
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
"getCacheDir", "(Ljava/lang/String;)Ljava/io/File;");
fileObject = (*env)->CallObjectMethod(env, context, mid, NULL);
@ -2417,7 +2417,7 @@ const char *SDL_GetAndroidCachePath(void)
return NULL;
}
/* path = fileObject.getAbsolutePath(); */
// path = fileObject.getAbsolutePath();
mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, fileObject),
"getAbsolutePath", "()Ljava/lang/String;");
pathString = (jstring)(*env)->CallObjectMethod(env, fileObject, mid);
@ -2568,7 +2568,7 @@ int SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermi
return 0;
}
/* Show toast notification */
// Show toast notification
int Android_JNI_ShowToast(const char *message, int duration, int gravity, int xOffset, int yOffset)
{
int result = 0;
@ -2585,7 +2585,7 @@ int Android_JNI_GetLocale(char *buf, size_t buflen)
SDL_assert(buflen > 6);
/* Need to re-create the asset manager if locale has changed (SDL_EVENT_LOCALE_CHANGED) */
// Need to re-create the asset manager if locale has changed (SDL_EVENT_LOCALE_CHANGED)
Internal_Android_Destroy_AssetManager();
if (!asset_manager) {
@ -2610,7 +2610,7 @@ int Android_JNI_GetLocale(char *buf, size_t buflen)
AConfiguration_getLanguage(cfg, language);
AConfiguration_getCountry(cfg, country);
/* copy language (not null terminated) */
// copy language (not null terminated)
if (language[0]) {
buf[id++] = language[0];
if (language[1]) {
@ -2620,7 +2620,7 @@ int Android_JNI_GetLocale(char *buf, size_t buflen)
buf[id++] = '_';
/* copy country (not null terminated) */
// copy country (not null terminated)
if (country[0]) {
buf[id++] = country[0];
if (country[1]) {
@ -2648,7 +2648,7 @@ int Android_JNI_OpenURL(const char *url)
int Android_JNI_OpenFileDescriptor(const char *uri, const char *mode)
{
/* Get fopen-style modes */
// Get fopen-style modes
int moderead = 0, modewrite = 0, modeappend = 0, modeupdate = 0;
for (const char *cmode = mode; *cmode; cmode++) {
@ -2670,8 +2670,8 @@ int Android_JNI_OpenFileDescriptor(const char *uri, const char *mode)
}
}
/* Translate fopen-style modes to ContentResolver modes. */
/* Android only allows "r", "w", "wt", "wa", "rw" or "rwt". */
// Translate fopen-style modes to ContentResolver modes.
// Android only allows "r", "w", "wt", "wa", "rw" or "rwt".
const char *contentResolverMode = "r";
if (moderead) {
@ -2719,7 +2719,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeFileDialog)(
return;
}
/* Convert fileList to string */
// Convert fileList to string
size_t count = (*env)->GetArrayLength(env, fileList);
char **charFileList = SDL_calloc(sizeof(char*), count + 1);
@ -2729,8 +2729,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeFileDialog)(
return;
}
/* Convert to UTF-8 */
/* TODO: Fix modified UTF-8 to classic UTF-8 */
// Convert to UTF-8
// TODO: Fix modified UTF-8 to classic UTF-8
for (int i = 0; i < count; i++) {
jstring string = (*env)->GetObjectArrayElement(env, fileList, i);
if (!string) {
@ -2750,7 +2750,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeFileDialog)(
mAndroidFileDialogData.callback(mAndroidFileDialogData.userdata, NULL, -1);
mAndroidFileDialogData.callback = NULL;
/* Cleanup memory */
// Cleanup memory
for (int j = 0; j < i; j++) {
SDL_free(charFileList[j]);
}
@ -2763,12 +2763,12 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeFileDialog)(
(*env)->DeleteLocalRef(env, string);
}
/* Call user-provided callback */
// Call user-provided callback
SDL_ClearError();
mAndroidFileDialogData.callback(mAndroidFileDialogData.userdata, (const char *const *) charFileList, filter);
mAndroidFileDialogData.callback = NULL;
/* Cleanup memory */
// Cleanup memory
for (int i = 0; i < count; i++) {
SDL_free(charFileList[i]);
}
@ -2792,13 +2792,13 @@ SDL_bool Android_JNI_OpenFileDialog(
JNIEnv *env = Android_JNI_GetEnv();
/* Setup filters */
// Setup filters
jobjectArray filtersArray = NULL;
if (filters) {
jclass stringClass = (*env)->FindClass(env, "java/lang/String");
filtersArray = (*env)->NewObjectArray(env, nfilters, stringClass, NULL);
/* Convert to string */
// Convert to string
for (int i = 0; i < nfilters; i++) {
jstring str = (*env)->NewStringUTF(env, filters[i].pattern);
(*env)->SetObjectArrayElement(env, filtersArray, i, str);
@ -2806,13 +2806,13 @@ SDL_bool Android_JNI_OpenFileDialog(
}
}
/* Setup data */
// Setup data
static SDL_AtomicInt next_request_code;
mAndroidFileDialogData.request_code = SDL_AtomicAdd(&next_request_code, 1);
mAndroidFileDialogData.userdata = userdata;
mAndroidFileDialogData.callback = callback;
/* Invoke JNI */
// Invoke JNI
jboolean success = (*env)->CallStaticBooleanMethod(env, mActivityClass,
midShowFileDialog, filtersArray, (jboolean) multiple, (jboolean) forwrite, mAndroidFileDialogData.request_code);
(*env)->DeleteLocalRef(env, filtersArray);
@ -2827,4 +2827,4 @@ SDL_bool Android_JNI_OpenFileDialog(
return SDL_TRUE;
}
#endif /* SDL_PLATFORM_ANDROID */
#endif // SDL_PLATFORM_ANDROID