Skip to content

Commit ef39ea7

Browse files
committed
rework: SDL detection
Now uses SDL_Init call to detect if SDL is being used.
1 parent 55f2512 commit ef39ea7

8 files changed

Lines changed: 66 additions & 3 deletions

File tree

app_pojavlauncher/src/main/java/org/libsdl/app/SDLControllerManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ public int compare(InputDevice.MotionRange arg0, InputDevice.MotionRange arg1) {
227227
*/
228228
synchronized void pollInputDevices() {
229229
if (!firstPollDone) {
230-
MinecraftGLSurface.sdlEnabled = true;
231230
if (sDirectGamepadEnableHandler != null){
232231
sDirectGamepadEnableHandler.onDirectGamepadEnabled();
233232
}

app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import androidx.annotation.Nullable;
1515

1616
import org.libsdl.app.SDLActivity;
17+
import org.libsdl.app.SDLSurface;
1718

1819
import java.lang.ref.WeakReference;
1920
import java.nio.ByteBuffer;
@@ -60,7 +61,7 @@ public static void sendCursorPos(float x, float y) {
6061
mouseY = y;
6162
nativeSendCursorPos(mouseX, mouseY);
6263
// HOVER_MOVE and MOVE are equivalent in SDL
63-
SDLActivity.onNativeMouse(0, MotionEvent.ACTION_MOVE, x, y, true);
64+
SDLActivity.onNativeMouse(0, MotionEvent.ACTION_MOVE, x, y, false);
6465
}
6566

6667
/**
@@ -122,7 +123,7 @@ public static void sendMouseButton(int button, boolean status) {
122123
public static void sendMouseKeycode(int button, int modifiers, boolean isDown) {
123124
// if (isGrabbing()) DEBUG_STRING.append("MouseGrabStrace: " + android.util.Log.getStackTraceString(new Throwable()) + "\n");
124125
nativeSendMouseButton(button, isDown ? 1 : 0, modifiers);
125-
SDLActivity.onNativeMouse(button, isDown ? MotionEvent.ACTION_DOWN : MotionEvent.ACTION_UP, mouseX, mouseY, true);
126+
SDLActivity.onNativeMouse(button, isDown ? MotionEvent.ACTION_DOWN : MotionEvent.ACTION_UP, mouseX, mouseY, false);
126127
}
127128

128129
public static void sendMouseKeycode(int keycode) {
@@ -167,6 +168,31 @@ public static boolean isGrabbing() {
167168
}
168169
}
169170

171+
// Notification types
172+
private static final int SDL = 0;
173+
174+
// Notification actions
175+
private static final int INIT = 0;
176+
/**
177+
* Used for any sort of notification that needs to be given from the JRE side
178+
* @return if notification successful
179+
*/
180+
// Called from JRE side via jni
181+
@SuppressWarnings("unused")
182+
@Keep
183+
public static boolean notifyLauncher(int type, int... action) {
184+
switch (type) {
185+
case SDL:
186+
if (action[0] == INIT) {
187+
MinecraftGLSurface.sdlEnabled = true;
188+
// Notifies SDL of native surface res which is needed for proper input handling
189+
SDLActivity.getSDLSurface().surfaceChanged();
190+
Logger.appendToLog("Amethyst-Android: SDL support enabled!");
191+
return true;
192+
}
193+
}
194+
return false;
195+
}
170196

171197
public static int getCurrentMods() {
172198
int currMods = 0;

app_pojavlauncher/src/main/jni/environ/environ.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct pojav_environ_s {
5252
jmethodID method_internalWindowSizeChanged;
5353
jmethodID method_internalChangeMonitorSize;
5454
jmethodID method_getAndroidDPI;
55+
jmethodID method_notifyLauncher;
5556
jclass bridgeClazz;
5657
jclass vmGlfwClass;
5758
jboolean isGrabbing;

app_pojavlauncher/src/main/jni/input_bridge_v3.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
5959
pojav_environ->method_onGrabStateChanged = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "onGrabStateChanged", "(Z)V");
6060
pojav_environ->method_onDirectInputEnable = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "onDirectInputEnable", "()V");
6161
pojav_environ->method_getAndroidDPI = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "getAndroidDPI", "()F");
62+
pojav_environ->method_notifyLauncher = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "notifyLauncher", "(I[I)Z");
6263
pojav_environ->isUseStackQueueCall = JNI_FALSE;
6364
} else if (pojav_environ->dalvikJavaVMPtr != vm) {
6465
LOGI("Saving JVM environ...");
@@ -332,6 +333,13 @@ JNIEXPORT jfloat JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeGetAndroidDPI(
332333
return result;
333334
}
334335

336+
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeNotifyLauncher(JNIEnv* env, __attribute__((unused)) jclass clazz, jint type, jintArray action) {
337+
TRY_ATTACH_ENV(dvm_env, pojav_environ->dalvikJavaVMPtr, "nativeNotifyLauncher failed!\n",);
338+
jboolean result = (*dvm_env)->CallStaticBooleanMethod(dvm_env, pojav_environ->bridgeClazz,
339+
pojav_environ->method_notifyLauncher, type, convertIntArrayJVM(env, dvm_env, action));
340+
return result;
341+
}
342+
335343
jboolean critical_send_char(jchar codepoint) {
336344
if (pojav_environ->GLFW_invoke_Char && pojav_environ->isInputReady) {
337345
if (pojav_environ->isUseStackQueueCall) {

app_pojavlauncher/src/main/jni/utils.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ jstring convertStringJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jstring srcStr) {
5959
return dstStr;
6060
}
6161

62+
jintArray convertIntArrayJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jintArray srcIntArray) {
63+
if (srcIntArray == NULL) {
64+
return NULL;
65+
}
66+
67+
jsize len = (*srcEnv)->GetArrayLength(srcEnv, srcIntArray);
68+
jint* srcPtr = (*srcEnv)->GetIntArrayElements(srcEnv, srcIntArray, NULL);
69+
70+
jintArray dstIntArray = (*dstEnv)->NewIntArray(dstEnv, len);
71+
(*dstEnv)->SetIntArrayRegion(dstEnv, dstIntArray, 0, len, srcPtr);
72+
73+
(*srcEnv)->ReleaseIntArrayElements(srcEnv, srcIntArray, srcPtr, JNI_ABORT);
74+
75+
return dstIntArray;
76+
}
77+
6278
JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupBridgeSurfaceAWT(JNIEnv *env, jclass clazz, jlong surface) {
6379
shared_awt_surface = surface;
6480
}

app_pojavlauncher/src/main/jni/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray);
1010
jobjectArray convert_from_char_array(JNIEnv *env, char **charArray, int num_rows);
1111
void free_char_array(JNIEnv *env, jobjectArray jstringArray, const char **charArray);
1212
jstring convertStringJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jstring srcStr);
13+
jintArray convertIntArrayJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jintArray srcIntArray);
1314

1415
JNIEnv* get_attached_env(JavaVM* jvm);
1516
JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNIEnv* env, jclass clazz, jint action, jbyteArray copySrc);

jre_lwjgl3glfw/lwjgl-3.3.3/src/main/java/org/lwjgl/glfw/CallbackBridge.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class CallbackBridge {
1919

2020
public static final boolean INPUT_DEBUG_ENABLED;
2121

22+
// Notification types
23+
public static final int SDL = 0;
24+
// Notification actions
25+
public static final int INIT = 0;
26+
2227
public static boolean sGamepadDirectEnabled;
2328

2429
// TODO send grab state event to Android
@@ -58,5 +63,6 @@ public static void sendData(int type, String data) {
5863
public static native ByteBuffer nativeCreateGamepadAxisBuffer();
5964
private static native boolean nativeEnableGamepadDirectInput();
6065
public static native float nativeGetAndroidDPI();
66+
public static native boolean nativeNotifyLauncher(int type, int... action);
6167
}
6268

jre_lwjgl3glfw/lwjgl-3.4.1/src/main/java/org/lwjgl/glfw/CallbackBridge.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class CallbackBridge {
1919

2020
public static final boolean INPUT_DEBUG_ENABLED;
2121

22+
// Notification types
23+
public static final int SDL = 0;
24+
// Notification actions
25+
public static final int INIT = 0;
26+
2227
public static boolean sGamepadDirectEnabled;
2328

2429
// TODO send grab state event to Android
@@ -58,5 +63,6 @@ public static void sendData(int type, String data) {
5863
public static native ByteBuffer nativeCreateGamepadAxisBuffer();
5964
private static native boolean nativeEnableGamepadDirectInput();
6065
public static native float nativeGetAndroidDPI();
66+
public static native boolean nativeNotifyLauncher(int type, int... action);
6167
}
6268

0 commit comments

Comments
 (0)