mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 06:39:54 -04:00
Feat[gamepad_direct]: detect usage of GLFW gamepad automatically
This commit is contained in:
parent
c5d1739877
commit
f0005fa912
Binary file not shown.
@ -1 +1 @@
|
|||||||
1735293224932
|
1735328970475
|
@ -30,6 +30,7 @@ import net.kdt.pojavlaunch.customcontrols.ControlLayout;
|
|||||||
import net.kdt.pojavlaunch.customcontrols.gamepad.DefaultDataProvider;
|
import net.kdt.pojavlaunch.customcontrols.gamepad.DefaultDataProvider;
|
||||||
import net.kdt.pojavlaunch.customcontrols.gamepad.Gamepad;
|
import net.kdt.pojavlaunch.customcontrols.gamepad.Gamepad;
|
||||||
import net.kdt.pojavlaunch.customcontrols.gamepad.direct.DirectGamepad;
|
import net.kdt.pojavlaunch.customcontrols.gamepad.direct.DirectGamepad;
|
||||||
|
import net.kdt.pojavlaunch.customcontrols.gamepad.direct.DirectGamepadEnableHandler;
|
||||||
import net.kdt.pojavlaunch.customcontrols.mouse.AbstractTouchpad;
|
import net.kdt.pojavlaunch.customcontrols.mouse.AbstractTouchpad;
|
||||||
import net.kdt.pojavlaunch.customcontrols.mouse.AndroidPointerCapture;
|
import net.kdt.pojavlaunch.customcontrols.mouse.AndroidPointerCapture;
|
||||||
import net.kdt.pojavlaunch.customcontrols.mouse.InGUIEventProcessor;
|
import net.kdt.pojavlaunch.customcontrols.mouse.InGUIEventProcessor;
|
||||||
@ -48,7 +49,7 @@ import fr.spse.gamepad_remapper.RemapperView;
|
|||||||
/**
|
/**
|
||||||
* Class dealing with showing minecraft surface and taking inputs to dispatch them to minecraft
|
* Class dealing with showing minecraft surface and taking inputs to dispatch them to minecraft
|
||||||
*/
|
*/
|
||||||
public class MinecraftGLSurface extends View implements GrabListener {
|
public class MinecraftGLSurface extends View implements GrabListener, DirectGamepadEnableHandler {
|
||||||
/* Gamepad object for gamepad inputs, instantiated on need */
|
/* Gamepad object for gamepad inputs, instantiated on need */
|
||||||
private GamepadHandler mGamepadHandler;
|
private GamepadHandler mGamepadHandler;
|
||||||
/* The RemapperView.Builder object allows you to set which buttons to remap */
|
/* The RemapperView.Builder object allows you to set which buttons to remap */
|
||||||
@ -90,6 +91,7 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
|||||||
public MinecraftGLSurface(Context context, AttributeSet attributeSet) {
|
public MinecraftGLSurface(Context context, AttributeSet attributeSet) {
|
||||||
super(context, attributeSet);
|
super(context, attributeSet);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
CallbackBridge.setDirectGamepadEnableHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
@ -205,7 +207,7 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createGamepad(View contextView, InputDevice inputDevice) {
|
private void createGamepad(View contextView, InputDevice inputDevice) {
|
||||||
if(LauncherPreferences.PREF_DIRECT_CONTROLLER) {
|
if(CallbackBridge.sGamepadDirectInput) {
|
||||||
mGamepadHandler = new DirectGamepad();
|
mGamepadHandler = new DirectGamepad();
|
||||||
}else {
|
}else {
|
||||||
mGamepadHandler = new Gamepad(contextView, inputDevice, DefaultDataProvider.INSTANCE, true);
|
mGamepadHandler = new Gamepad(contextView, inputDevice, DefaultDataProvider.INSTANCE, true);
|
||||||
@ -411,6 +413,17 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDirectGamepadEnabled() {
|
||||||
|
post(()->{
|
||||||
|
if(mGamepadHandler != null && mGamepadHandler instanceof Gamepad) {
|
||||||
|
((Gamepad)mGamepadHandler).removeSelf();
|
||||||
|
}
|
||||||
|
// Force gamepad recreation on next event
|
||||||
|
mGamepadHandler = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** A small interface called when the listener is ready for the first time */
|
/** A small interface called when the listener is ready for the first time */
|
||||||
public interface SurfaceReadyListener {
|
public interface SurfaceReadyListener {
|
||||||
void isReady();
|
void isReady();
|
||||||
|
@ -30,4 +30,9 @@ public class DefaultDataProvider implements GamepadDataProvider {
|
|||||||
public void attachGrabListener(GrabListener grabListener) {
|
public void attachGrabListener(GrabListener grabListener) {
|
||||||
CallbackBridge.addGrabListener(grabListener);
|
CallbackBridge.addGrabListener(grabListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void detachGrabListener(GrabListener grabListener) {
|
||||||
|
CallbackBridge.removeGrabListener(grabListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,8 @@ public class Gamepad implements GrabListener, GamepadHandler {
|
|||||||
|
|
||||||
private final GamepadDataProvider mMapProvider;
|
private final GamepadDataProvider mMapProvider;
|
||||||
|
|
||||||
|
private boolean mRemoved = false;
|
||||||
|
|
||||||
public Gamepad(View contextView, InputDevice inputDevice, GamepadDataProvider mapProvider, boolean showCursor){
|
public Gamepad(View contextView, InputDevice inputDevice, GamepadDataProvider mapProvider, boolean showCursor){
|
||||||
Settings.setDeadzoneScale(PREF_DEADZONE_SCALE);
|
Settings.setDeadzoneScale(PREF_DEADZONE_SCALE);
|
||||||
|
|
||||||
@ -95,7 +97,7 @@ public class Gamepad implements GrabListener, GamepadHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void doFrame(long frameTimeNanos) {
|
public void doFrame(long frameTimeNanos) {
|
||||||
tick(frameTimeNanos);
|
tick(frameTimeNanos);
|
||||||
mScreenChoreographer.postFrameCallback(this);
|
if(!mRemoved) mScreenChoreographer.postFrameCallback(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mScreenChoreographer.postFrameCallback(frameCallback);
|
mScreenChoreographer.postFrameCallback(frameCallback);
|
||||||
@ -452,4 +454,10 @@ public class Gamepad implements GrabListener, GamepadHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void removeSelf() {
|
||||||
|
mRemoved = true;
|
||||||
|
mMapProvider.detachGrabListener(this);
|
||||||
|
ViewGroup viewGroup = (ViewGroup) mPointerImageView.getParent();
|
||||||
|
if(viewGroup != null) viewGroup.removeView(mPointerImageView);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,5 @@ public interface GamepadDataProvider {
|
|||||||
GamepadMap getGameMap();
|
GamepadMap getGameMap();
|
||||||
boolean isGrabbing();
|
boolean isGrabbing();
|
||||||
void attachGrabListener(GrabListener grabListener);
|
void attachGrabListener(GrabListener grabListener);
|
||||||
|
void detachGrabListener(GrabListener grabListener);
|
||||||
}
|
}
|
||||||
|
@ -325,6 +325,11 @@ public class GamepadMapperAdapter extends RecyclerView.Adapter<GamepadMapperAdap
|
|||||||
grabListener.onGrabState(mGrabState);
|
grabListener.onGrabState(mGrabState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void detachGrabListener(GrabListener grabListener) {
|
||||||
|
mGamepadGrabListener = null;
|
||||||
|
}
|
||||||
|
|
||||||
public void setGrabState(boolean newState) {
|
public void setGrabState(boolean newState) {
|
||||||
mGrabState = newState;
|
mGrabState = newState;
|
||||||
if(mGamepadGrabListener != null) mGamepadGrabListener.onGrabState(newState);
|
if(mGamepadGrabListener != null) mGamepadGrabListener.onGrabState(newState);
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package net.kdt.pojavlaunch.customcontrols.gamepad.direct;
|
||||||
|
|
||||||
|
public interface DirectGamepadEnableHandler {
|
||||||
|
void onDirectGamepadEnabled();
|
||||||
|
}
|
@ -67,7 +67,6 @@ public class LauncherPreferences {
|
|||||||
public static String PREF_DOWNLOAD_SOURCE = "default";
|
public static String PREF_DOWNLOAD_SOURCE = "default";
|
||||||
public static boolean PREF_SKIP_NOTIFICATION_PERMISSION_CHECK = false;
|
public static boolean PREF_SKIP_NOTIFICATION_PERMISSION_CHECK = false;
|
||||||
public static boolean PREF_VSYNC_IN_ZINK = true;
|
public static boolean PREF_VSYNC_IN_ZINK = true;
|
||||||
public static boolean PREF_DIRECT_CONTROLLER = false;
|
|
||||||
|
|
||||||
|
|
||||||
public static void loadPreferences(Context ctx) {
|
public static void loadPreferences(Context ctx) {
|
||||||
@ -110,7 +109,6 @@ public class LauncherPreferences {
|
|||||||
PREF_VERIFY_MANIFEST = DEFAULT_PREF.getBoolean("verifyManifest", true);
|
PREF_VERIFY_MANIFEST = DEFAULT_PREF.getBoolean("verifyManifest", true);
|
||||||
PREF_SKIP_NOTIFICATION_PERMISSION_CHECK = DEFAULT_PREF.getBoolean(PREF_KEY_SKIP_NOTIFICATION_CHECK, false);
|
PREF_SKIP_NOTIFICATION_PERMISSION_CHECK = DEFAULT_PREF.getBoolean(PREF_KEY_SKIP_NOTIFICATION_CHECK, false);
|
||||||
PREF_VSYNC_IN_ZINK = DEFAULT_PREF.getBoolean("vsync_in_zink", true);
|
PREF_VSYNC_IN_ZINK = DEFAULT_PREF.getBoolean("vsync_in_zink", true);
|
||||||
PREF_DIRECT_CONTROLLER = DEFAULT_PREF.getBoolean("directController", false);
|
|
||||||
|
|
||||||
String argLwjglLibname = "-Dorg.lwjgl.opengl.libname=";
|
String argLwjglLibname = "-Dorg.lwjgl.opengl.libname=";
|
||||||
for (String arg : JREUtils.parseJavaArguments(PREF_CUSTOM_JAVA_ARGS)) {
|
for (String arg : JREUtils.parseJavaArguments(PREF_CUSTOM_JAVA_ARGS)) {
|
||||||
|
@ -2,8 +2,6 @@ package net.kdt.pojavlaunch.prefs.screens;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.hardware.Sensor;
|
|
||||||
import android.hardware.SensorManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
@ -89,7 +87,6 @@ public class LauncherPreferenceControlFragment extends LauncherPreferenceFragmen
|
|||||||
requirePreference("gyroInvertX").setVisible(LauncherPreferences.PREF_ENABLE_GYRO);
|
requirePreference("gyroInvertX").setVisible(LauncherPreferences.PREF_ENABLE_GYRO);
|
||||||
requirePreference("gyroInvertY").setVisible(LauncherPreferences.PREF_ENABLE_GYRO);
|
requirePreference("gyroInvertY").setVisible(LauncherPreferences.PREF_ENABLE_GYRO);
|
||||||
requirePreference("gyroSmoothing").setVisible(LauncherPreferences.PREF_ENABLE_GYRO);
|
requirePreference("gyroSmoothing").setVisible(LauncherPreferences.PREF_ENABLE_GYRO);
|
||||||
requirePreference("_frag_changeKeyBindings").setVisible(!LauncherPreferences.PREF_DIRECT_CONTROLLER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package org.lwjgl.glfw;
|
package org.lwjgl.glfw;
|
||||||
|
|
||||||
import net.kdt.pojavlaunch.*;
|
import net.kdt.pojavlaunch.*;
|
||||||
|
import net.kdt.pojavlaunch.customcontrols.gamepad.direct.DirectGamepadEnableHandler;
|
||||||
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Choreographer;
|
import android.view.Choreographer;
|
||||||
@ -8,6 +10,7 @@ import android.view.Choreographer;
|
|||||||
import androidx.annotation.Keep;
|
import androidx.annotation.Keep;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
@ -19,6 +22,7 @@ public class CallbackBridge {
|
|||||||
public static final Choreographer sChoreographer = Choreographer.getInstance();
|
public static final Choreographer sChoreographer = Choreographer.getInstance();
|
||||||
private static boolean isGrabbing = false;
|
private static boolean isGrabbing = false;
|
||||||
private static final ArrayList<GrabListener> grabListeners = new ArrayList<>();
|
private static final ArrayList<GrabListener> grabListeners = new ArrayList<>();
|
||||||
|
private static WeakReference<DirectGamepadEnableHandler> sDirectGamepadEnableHandler;
|
||||||
|
|
||||||
public static final int CLIPBOARD_COPY = 2000;
|
public static final int CLIPBOARD_COPY = 2000;
|
||||||
public static final int CLIPBOARD_PASTE = 2001;
|
public static final int CLIPBOARD_PASTE = 2001;
|
||||||
@ -32,6 +36,7 @@ public class CallbackBridge {
|
|||||||
|
|
||||||
public static final ByteBuffer sGamepadButtonBuffer;
|
public static final ByteBuffer sGamepadButtonBuffer;
|
||||||
public static final FloatBuffer sGamepadAxisBuffer;
|
public static final FloatBuffer sGamepadAxisBuffer;
|
||||||
|
public static boolean sGamepadDirectInput = false;
|
||||||
|
|
||||||
public static void putMouseEventWithCoords(int button, float x, float y) {
|
public static void putMouseEventWithCoords(int button, float x, float y) {
|
||||||
putMouseEventWithCoords(button, true, x, y);
|
putMouseEventWithCoords(button, true, x, y);
|
||||||
@ -171,6 +176,16 @@ public class CallbackBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Called from JRE side
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Keep
|
||||||
|
private static void onDirectInputEnable() {
|
||||||
|
Log.i("CallbackBridge", "onDirectInputEnable()");
|
||||||
|
DirectGamepadEnableHandler enableHandler = Tools.getWeakReference(sDirectGamepadEnableHandler);
|
||||||
|
if(enableHandler != null) enableHandler.onDirectGamepadEnabled();
|
||||||
|
sGamepadDirectInput = true;
|
||||||
|
}
|
||||||
|
|
||||||
//Called from JRE side
|
//Called from JRE side
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Keep
|
@Keep
|
||||||
@ -199,12 +214,17 @@ public class CallbackBridge {
|
|||||||
grabListeners.remove(listener);
|
grabListeners.remove(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FloatBuffer createGamepadAxisBuffer() {
|
public static FloatBuffer createGamepadAxisBuffer() {
|
||||||
ByteBuffer axisByteBuffer = nativeCreateGamepadAxisBuffer();
|
ByteBuffer axisByteBuffer = nativeCreateGamepadAxisBuffer();
|
||||||
// NOTE: hardcoded order (also in jre_lwjgl3glfw CallbackBridge)
|
// NOTE: hardcoded order (also in jre_lwjgl3glfw CallbackBridge)
|
||||||
return axisByteBuffer.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
|
return axisByteBuffer.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setDirectGamepadEnableHandler(DirectGamepadEnableHandler h) {
|
||||||
|
sDirectGamepadEnableHandler = new WeakReference<>(h);
|
||||||
|
}
|
||||||
|
|
||||||
@Keep @CriticalNative public static native void nativeSetUseInputStackQueue(boolean useInputStackQueue);
|
@Keep @CriticalNative public static native void nativeSetUseInputStackQueue(boolean useInputStackQueue);
|
||||||
|
|
||||||
@Keep @CriticalNative private static native boolean nativeSendChar(char codepoint);
|
@Keep @CriticalNative private static native boolean nativeSendChar(char codepoint);
|
||||||
|
@ -47,6 +47,7 @@ struct pojav_environ_s {
|
|||||||
double cursorX, cursorY, cLastX, cLastY;
|
double cursorX, cursorY, cLastX, cLastY;
|
||||||
jmethodID method_accessAndroidClipboard;
|
jmethodID method_accessAndroidClipboard;
|
||||||
jmethodID method_onGrabStateChanged;
|
jmethodID method_onGrabStateChanged;
|
||||||
|
jmethodID method_onDirectInputEnable;
|
||||||
jmethodID method_glftSetWindowAttrib;
|
jmethodID method_glftSetWindowAttrib;
|
||||||
jmethodID method_internalWindowSizeChanged;
|
jmethodID method_internalWindowSizeChanged;
|
||||||
jmethodID method_internalChangeMonitorSize;
|
jmethodID method_internalChangeMonitorSize;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
* - Implements glfwSetCursorPos() to handle grab camera pos correctly.
|
* - Implements glfwSetCursorPos() to handle grab camera pos correctly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
@ -30,6 +30,29 @@
|
|||||||
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
||||||
#define EVENT_TYPE_SCROLL 1007
|
#define EVENT_TYPE_SCROLL 1007
|
||||||
|
|
||||||
|
static jint attach_env(JNIEnv ** pEnv, JavaVM *jvm) {
|
||||||
|
JNIEnv *jvm_env = NULL;
|
||||||
|
jint env_result = (*jvm)->GetEnv(jvm, (void**)&jvm_env, JNI_VERSION_1_4);
|
||||||
|
if(env_result == JNI_EDETACHED) {
|
||||||
|
env_result = (*jvm)->AttachCurrentThread(jvm, &jvm_env, NULL);
|
||||||
|
}
|
||||||
|
if(env_result != JNI_OK) {
|
||||||
|
return env_result;
|
||||||
|
}
|
||||||
|
*pEnv = jvm_env;
|
||||||
|
return JNI_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TRY_ATTACH_ENV(env_name, vm, error_message, then) JNIEnv* env_name;\
|
||||||
|
do { \
|
||||||
|
jint result = attach_env(&env_name, vm); \
|
||||||
|
if(result != JNI_OK) { \
|
||||||
|
printf(error_message, result); \
|
||||||
|
then\
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
jint (*orig_ProcessImpl_forkAndExec)(JNIEnv *env, jobject process, jint mode, jbyteArray helperpath, jbyteArray prog, jbyteArray argBlock, jint argc, jbyteArray envBlock, jint envc, jbyteArray dir, jintArray std_fds, jboolean redirectErrorStream);
|
jint (*orig_ProcessImpl_forkAndExec)(JNIEnv *env, jobject process, jint mode, jbyteArray helperpath, jbyteArray prog, jbyteArray argBlock, jint argc, jbyteArray envBlock, jint envc, jbyteArray dir, jintArray std_fds, jboolean redirectErrorStream);
|
||||||
|
|
||||||
static void registerFunctions(JNIEnv *env);
|
static void registerFunctions(JNIEnv *env);
|
||||||
@ -44,6 +67,7 @@ jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
|||||||
pojav_environ->bridgeClazz = (*env)->NewGlobalRef(env,(*env) ->FindClass(env,"org/lwjgl/glfw/CallbackBridge"));
|
pojav_environ->bridgeClazz = (*env)->NewGlobalRef(env,(*env) ->FindClass(env,"org/lwjgl/glfw/CallbackBridge"));
|
||||||
pojav_environ->method_accessAndroidClipboard = (*env)->GetStaticMethodID(env, pojav_environ->bridgeClazz, "accessAndroidClipboard", "(ILjava/lang/String;)Ljava/lang/String;");
|
pojav_environ->method_accessAndroidClipboard = (*env)->GetStaticMethodID(env, pojav_environ->bridgeClazz, "accessAndroidClipboard", "(ILjava/lang/String;)Ljava/lang/String;");
|
||||||
pojav_environ->method_onGrabStateChanged = (*env)->GetStaticMethodID(env, pojav_environ->bridgeClazz, "onGrabStateChanged", "(Z)V");
|
pojav_environ->method_onGrabStateChanged = (*env)->GetStaticMethodID(env, pojav_environ->bridgeClazz, "onGrabStateChanged", "(Z)V");
|
||||||
|
pojav_environ->method_onDirectInputEnable = (*env)->GetStaticMethodID(env, pojav_environ->bridgeClazz, "onDirectInputEnable", "()V");
|
||||||
pojav_environ->isUseStackQueueCall = JNI_FALSE;
|
pojav_environ->isUseStackQueueCall = JNI_FALSE;
|
||||||
} else if (pojav_environ->dalvikJavaVMPtr != vm) {
|
} else if (pojav_environ->dalvikJavaVMPtr != vm) {
|
||||||
__android_log_print(ANDROID_LOG_INFO, "Native", "Saving JVM environ...");
|
__android_log_print(ANDROID_LOG_INFO, "Native", "Saving JVM environ...");
|
||||||
@ -71,7 +95,7 @@ jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
|||||||
registerFunctions(env);
|
registerFunctions(env);
|
||||||
}
|
}
|
||||||
pojav_environ->isGrabbing = JNI_FALSE;
|
pojav_environ->isGrabbing = JNI_FALSE;
|
||||||
|
|
||||||
return JNI_VERSION_1_4;
|
return JNI_VERSION_1_4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +385,7 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNI
|
|||||||
(*pojav_environ->dalvikJavaVMPtr)->AttachCurrentThread(pojav_environ->dalvikJavaVMPtr, &dalvikEnv, NULL);
|
(*pojav_environ->dalvikJavaVMPtr)->AttachCurrentThread(pojav_environ->dalvikJavaVMPtr, &dalvikEnv, NULL);
|
||||||
assert(dalvikEnv != NULL);
|
assert(dalvikEnv != NULL);
|
||||||
assert(pojav_environ->bridgeClazz != NULL);
|
assert(pojav_environ->bridgeClazz != NULL);
|
||||||
|
|
||||||
LOGD("Clipboard: Converting string\n");
|
LOGD("Clipboard: Converting string\n");
|
||||||
char *copySrcC;
|
char *copySrcC;
|
||||||
jstring copyDst = NULL;
|
jstring copyDst = NULL;
|
||||||
@ -374,7 +398,7 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNI
|
|||||||
jstring pasteDst = convertStringJVM(dalvikEnv, env, (jstring) (*dalvikEnv)->CallStaticObjectMethod(dalvikEnv, pojav_environ->bridgeClazz, pojav_environ->method_accessAndroidClipboard, action, copyDst));
|
jstring pasteDst = convertStringJVM(dalvikEnv, env, (jstring) (*dalvikEnv)->CallStaticObjectMethod(dalvikEnv, pojav_environ->bridgeClazz, pojav_environ->method_accessAndroidClipboard, action, copyDst));
|
||||||
|
|
||||||
if (copySrc) {
|
if (copySrc) {
|
||||||
(*dalvikEnv)->DeleteLocalRef(dalvikEnv, copyDst);
|
(*dalvikEnv)->DeleteLocalRef(dalvikEnv, copyDst);
|
||||||
(*env)->ReleaseByteArrayElements(env, copySrc, (jbyte *)copySrcC, 0);
|
(*env)->ReleaseByteArrayElements(env, copySrc, (jbyte *)copySrcC, 0);
|
||||||
}
|
}
|
||||||
(*pojav_environ->dalvikJavaVMPtr)->DetachCurrentThread(pojav_environ->dalvikJavaVMPtr);
|
(*pojav_environ->dalvikJavaVMPtr)->DetachCurrentThread(pojav_environ->dalvikJavaVMPtr);
|
||||||
@ -395,13 +419,18 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputRead
|
|||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetGrabbing(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jboolean grabbing) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetGrabbing(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jboolean grabbing) {
|
||||||
JNIEnv *dalvikEnv;
|
TRY_ATTACH_ENV(dvm_env, pojav_environ->dalvikJavaVMPtr, "nativeSetGrabbing failed: %i", return;);
|
||||||
(*pojav_environ->dalvikJavaVMPtr)->AttachCurrentThread(pojav_environ->dalvikJavaVMPtr, &dalvikEnv, NULL);
|
(*dvm_env)->CallStaticVoidMethod(dvm_env, pojav_environ->bridgeClazz, pojav_environ->method_onGrabStateChanged, grabbing);
|
||||||
(*dalvikEnv)->CallStaticVoidMethod(dalvikEnv, pojav_environ->bridgeClazz, pojav_environ->method_onGrabStateChanged, grabbing);
|
|
||||||
(*pojav_environ->dalvikJavaVMPtr)->DetachCurrentThread(pojav_environ->dalvikJavaVMPtr);
|
|
||||||
pojav_environ->isGrabbing = grabbing;
|
pojav_environ->isGrabbing = grabbing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL
|
||||||
|
Java_org_lwjgl_glfw_CallbackBridge_nativeEnableGamepadDirectInput(__attribute__((unused)) JNIEnv *env, __attribute__((unused)) jclass clazz) {
|
||||||
|
TRY_ATTACH_ENV(dvm_env, pojav_environ->dalvikJavaVMPtr, "nativeEnableGamepadDirectInput failed: %i", return JNI_FALSE;);
|
||||||
|
(*dvm_env)->CallStaticVoidMethod(dvm_env, pojav_environ->bridgeClazz, pojav_environ->method_onDirectInputEnable);
|
||||||
|
return JNI_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
jboolean critical_send_char(jchar codepoint) {
|
jboolean critical_send_char(jchar codepoint) {
|
||||||
if (pojav_environ->GLFW_invoke_Char && pojav_environ->isInputReady) {
|
if (pojav_environ->GLFW_invoke_Char && pojav_environ->isInputReady) {
|
||||||
if (pojav_environ->isUseStackQueueCall) {
|
if (pojav_environ->isUseStackQueueCall) {
|
||||||
@ -561,16 +590,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetWindowAttrib(
|
|||||||
// in environ for the Android UI thread but this is the only place that uses it
|
// in environ for the Android UI thread but this is the only place that uses it
|
||||||
// (very rarely, only in lifecycle callbacks) so i dont care
|
// (very rarely, only in lifecycle callbacks) so i dont care
|
||||||
|
|
||||||
JavaVM* jvm = pojav_environ->runtimeJavaVMPtr;
|
TRY_ATTACH_ENV(jvm_env, pojav_environ->runtimeJavaVMPtr, "nativeSetWindowAttrib failed: %i", return;);
|
||||||
JNIEnv *jvm_env = NULL;
|
|
||||||
jint env_result = (*jvm)->GetEnv(jvm, (void**)&jvm_env, JNI_VERSION_1_4);
|
|
||||||
if(env_result == JNI_EDETACHED) {
|
|
||||||
env_result = (*jvm)->AttachCurrentThread(jvm, &jvm_env, NULL);
|
|
||||||
}
|
|
||||||
if(env_result != JNI_OK) {
|
|
||||||
printf("input_bridge nativeSetWindowAttrib() JNI call failed: %i\n", env_result);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*jvm_env)->CallStaticVoidMethod(
|
(*jvm_env)->CallStaticVoidMethod(
|
||||||
jvm_env, pojav_environ->vmGlfwClass,
|
jvm_env, pojav_environ->vmGlfwClass,
|
||||||
|
@ -144,13 +144,7 @@
|
|||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/preference_category_controller_settings"
|
android:title="@string/preference_category_controller_settings"
|
||||||
>
|
>
|
||||||
<SwitchPreference
|
|
||||||
android:key="directController"
|
|
||||||
android:title="@string/preference_direct_controller_title"
|
|
||||||
android:summary="@string/preference_direct_controller_description"
|
|
||||||
/>
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="_frag_changeKeyBindings"
|
|
||||||
android:title="@string/preference_remap_controller_title"
|
android:title="@string/preference_remap_controller_title"
|
||||||
android:summary="@string/preference_remap_controller_description"
|
android:summary="@string/preference_remap_controller_description"
|
||||||
android:fragment="net.kdt.pojavlaunch.fragments.GamepadMapperFragment"/>
|
android:fragment="net.kdt.pojavlaunch.fragments.GamepadMapperFragment"/>
|
||||||
|
@ -19,6 +19,8 @@ public class CallbackBridge {
|
|||||||
public static final int ANDROID_TYPE_GRAB_STATE = 0;
|
public static final int ANDROID_TYPE_GRAB_STATE = 0;
|
||||||
|
|
||||||
public static final boolean INPUT_DEBUG_ENABLED;
|
public static final boolean INPUT_DEBUG_ENABLED;
|
||||||
|
|
||||||
|
public static boolean sGamepadDirectEnabled;
|
||||||
|
|
||||||
// TODO send grab state event to Android
|
// TODO send grab state event to Android
|
||||||
|
|
||||||
@ -41,6 +43,11 @@ public class CallbackBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void enableGamepadDirectInput() {
|
||||||
|
if(sGamepadDirectEnabled) return;
|
||||||
|
sGamepadDirectEnabled = nativeEnableGamepadDirectInput();
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendData(int type, String data) {
|
public static void sendData(int type, String data) {
|
||||||
nativeSendData(false, type, data);
|
nativeSendData(false, type, data);
|
||||||
}
|
}
|
||||||
@ -50,5 +57,6 @@ public class CallbackBridge {
|
|||||||
public static native void nativeSetGrabbing(boolean grab);
|
public static native void nativeSetGrabbing(boolean grab);
|
||||||
public static native ByteBuffer nativeCreateGamepadButtonBuffer();
|
public static native ByteBuffer nativeCreateGamepadButtonBuffer();
|
||||||
public static native ByteBuffer nativeCreateGamepadAxisBuffer();
|
public static native ByteBuffer nativeCreateGamepadAxisBuffer();
|
||||||
|
private static native boolean nativeEnableGamepadDirectInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1211,6 +1211,7 @@ public class GLFW
|
|||||||
|
|
||||||
public static boolean glfwJoystickPresent(int jid) {
|
public static boolean glfwJoystickPresent(int jid) {
|
||||||
if(jid == GLFW_JOYSTICK_1) {
|
if(jid == GLFW_JOYSTICK_1) {
|
||||||
|
CallbackBridge.enableGamepadDirectInput();
|
||||||
return true;
|
return true;
|
||||||
}else return false;
|
}else return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user