From 46bb92e651aa9b719d9fca4d62d57a6f83b32b5e Mon Sep 17 00:00:00 2001 From: alexytomi <60690056+alexytomi@users.noreply.github.com> Date: Mon, 1 Sep 2025 22:17:38 +0800 Subject: [PATCH] SDL: Better docs on pref and why we dont use HIDDevice --- .../net/kdt/pojavlaunch/MainActivity.java | 22 +++++++++++-------- .../kdt/pojavlaunch/MinecraftGLSurface.java | 18 +++++---------- .../customcontrols/gamepad/Gamepad.java | 8 +++---- .../prefs/LauncherPreferences.java | 4 ++-- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java index d16ea77d1..660cb1c0a 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java @@ -4,7 +4,6 @@ import static net.kdt.pojavlaunch.Tools.currentDisplayMetrics; import static net.kdt.pojavlaunch.Tools.dialogForceClose; import static net.kdt.pojavlaunch.Tools.runMethodbyReflection; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_ENABLE_GYRO; -import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_GAMEPAD_PASSTHRU; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_SUSTAINED_PERFORMANCE; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_USE_ALTERNATE_SURFACE; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_VIRTUAL_MOUSE_START; @@ -75,8 +74,6 @@ import org.lwjgl.glfw.CallbackBridge; import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.Objects; public class MainActivity extends BaseActivity implements ControlButtonMenuListener, EditorExitable, ServiceConnection { @@ -111,7 +108,18 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (LauncherPreferences.PREF_GAMEPAD_PASSTHRU) { + if (LauncherPreferences.PREF_GAMEPAD_SDL_PASSTHRU) { + // SDL integration is here because android will send garbage keycodes for the purpose of + // "old app compatibility" so every input gets duplicated and attached with a correlated + // keycode like the O button on PS4 being KEYCODE_BACK = 4 or the X button being KEYCODE_SPACE + + + // TODO: Use lower level HID capture that needs a dialogue box from the user for the + // app to fully take focus of the input devices. Might cause issues with older android + // versions so we don't use that right now. Needs testing. + // Currently tried but only identification works OOTB, inputs aren't being sent. + + // TODO: Use a hook to load SDL logic depending on whether libSDL3.so is loaded. try { System.loadLibrary("SDL3"); SDL.initialize(); @@ -332,21 +340,18 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe @Override protected void onStart() { super.onStart(); - CallbackBridge.nativeSetWindowAttrib(LwjglGlfwKeycode.GLFW_VISIBLE, 1); } @Override protected void onStop() { CallbackBridge.nativeSetWindowAttrib(LwjglGlfwKeycode.GLFW_VISIBLE, 0); - super.onStop(); } @Override protected void onDestroy() { super.onDestroy(); - CallbackBridge.removeGrabListener(touchpad); CallbackBridge.removeGrabListener(minecraftGLView); ContextExecutor.clearActivity(); @@ -355,7 +360,6 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe @Override public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); - if(mGyroControl != null) mGyroControl.updateOrientation(); // Layout resize is practically guaranteed on a configuration change, and `onConfigurationChanged` // does not implicitly start a layout. So, request a layout and expect the screen dimensions to be valid after the] @@ -525,7 +529,7 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe event.getKeyCode() <= KeyEvent.KEYCODE_BUTTON_MODE // Android loves to bundle in garbage KeyEvents for compatibility with apps // that don't have controller code so we are. - && LauncherPreferences.PREF_GAMEPAD_PASSTHRU + && LauncherPreferences.PREF_GAMEPAD_SDL_PASSTHRU ){ if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN || diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java index bad99fb56..d0b1fb920 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java @@ -2,7 +2,7 @@ package net.kdt.pojavlaunch; import static net.kdt.pojavlaunch.MainActivity.touchCharInput; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_MOUSE_GRAB_FORCE; -import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_GAMEPAD_PASSTHRU; +import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_GAMEPAD_SDL_PASSTHRU; import static net.kdt.pojavlaunch.utils.MCOptionUtils.getMcScale; import static org.lwjgl.glfw.CallbackBridge.sendMouseButton; import static org.lwjgl.glfw.CallbackBridge.windowHeight; @@ -11,7 +11,6 @@ import static org.lwjgl.glfw.CallbackBridge.windowWidth; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.graphics.SurfaceTexture; import android.os.Build; import android.util.AttributeSet; @@ -182,7 +181,6 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame } - /** * The touch event for both grabbed an non-grabbed mouse state on the touch screen * Does not cover the virtual mouse touchpad @@ -222,11 +220,11 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame } private void createGamepad(View contextView, InputDevice inputDevice) { - if(CallbackBridge.sGamepadDirectInput && !PREF_GAMEPAD_PASSTHRU) { + if(CallbackBridge.sGamepadDirectInput && !PREF_GAMEPAD_SDL_PASSTHRU) { mGamepadHandler = new DirectGamepad(); - }else { + }else if(!PREF_GAMEPAD_SDL_PASSTHRU) { mGamepadHandler = new Gamepad(contextView, inputDevice, DefaultDataProvider.INSTANCE, true); - } + }else mGamepadHandler = (code, value) -> {}; // Ensure it isn't null while also not processing the events. } /** @@ -238,7 +236,7 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame super.dispatchGenericMotionEvent(event); int mouseCursorIndex = -1; - if(Gamepad.isGamepadEvent(event)){ + if(!PREF_GAMEPAD_SDL_PASSTHRU && Gamepad.isGamepadEvent(event)){ if(mGamepadHandler == null) createGamepad(this, event.getDevice()); mInputManager.handleMotionEventInput(getContext(), event, mGamepadHandler); @@ -276,10 +274,6 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame /** The event for keyboard/ gamepad button inputs */ public boolean processKeyEvent(KeyEvent event) { - if (PREF_GAMEPAD_PASSTHRU) { - return false; - } - //Log.i("KeyEvent", event.toString()); //Filtering useless events by order of probability @@ -314,7 +308,7 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame } } - if(Gamepad.isGamepadEvent(event)){ + if(!PREF_GAMEPAD_SDL_PASSTHRU && Gamepad.isGamepadEvent(event)){ if(mGamepadHandler == null) createGamepad(this, event.getDevice()); mInputManager.handleKeyEventInput(getContext(), event, mGamepadHandler); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java index 2b5cb4e94..cbe0328fb 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java @@ -42,7 +42,7 @@ import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTI import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTION_WEST; import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.isJoystickEvent; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_DEADZONE_SCALE; -import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_GAMEPAD_PASSTHRU; +import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_GAMEPAD_SDL_PASSTHRU; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_SCALE_FACTOR; import static net.kdt.pojavlaunch.utils.MCOptionUtils.getMcScale; import static org.lwjgl.glfw.CallbackBridge.sendKeyPress; @@ -91,7 +91,7 @@ public class Gamepad implements GrabListener, GamepadHandler { private boolean mRemoved = false; public Gamepad(View contextView, InputDevice inputDevice, GamepadDataProvider mapProvider, boolean showCursor){ - if (PREF_GAMEPAD_PASSTHRU) { + if (PREF_GAMEPAD_SDL_PASSTHRU) { throw new IllegalStateException("Gamepad should never have been constructed if passthru is on."); } @@ -196,14 +196,14 @@ public class Gamepad implements GrabListener, GamepadHandler { } public static boolean isGamepadEvent(MotionEvent event){ - return isJoystickEvent(event) && !PREF_GAMEPAD_PASSTHRU; + return isJoystickEvent(event) && !PREF_GAMEPAD_SDL_PASSTHRU; } public static boolean isGamepadEvent(KeyEvent event){ boolean isGamepad = ((event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((event.getDevice() != null) && ((event.getDevice().getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)); - return isGamepad && GamepadDpad.isDpadEvent(event) && !PREF_GAMEPAD_PASSTHRU; + return isGamepad && GamepadDpad.isDpadEvent(event) && !PREF_GAMEPAD_SDL_PASSTHRU; } /** diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java index bce75d54d..dc1c8c32c 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java @@ -39,7 +39,7 @@ public class LauncherPreferences { public static final String PREF_VERSION_REPOS = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"; public static boolean PREF_CHECK_LIBRARY_SHA = true; public static boolean PREF_DISABLE_GESTURES = false; - public static boolean PREF_GAMEPAD_PASSTHRU = false; + public static boolean PREF_GAMEPAD_SDL_PASSTHRU = false; public static boolean PREF_DISABLE_SWAP_HAND = false; public static float PREF_MOUSESPEED = 1f; public static int PREF_RAM_ALLOCATION; @@ -90,7 +90,7 @@ public class LauncherPreferences { PREF_FORCE_ENGLISH = DEFAULT_PREF.getBoolean("force_english", false); PREF_CHECK_LIBRARY_SHA = DEFAULT_PREF.getBoolean("checkLibraries",true); PREF_DISABLE_GESTURES = DEFAULT_PREF.getBoolean("disableGestures",false); - PREF_GAMEPAD_PASSTHRU = DEFAULT_PREF.getBoolean("gamepadPassthru",false); + PREF_GAMEPAD_SDL_PASSTHRU = DEFAULT_PREF.getBoolean("gamepadPassthru",false); PREF_DISABLE_SWAP_HAND = DEFAULT_PREF.getBoolean("disableDoubleTap", false); PREF_RAM_ALLOCATION = DEFAULT_PREF.getInt("allocation", findBestRAMAllocation(ctx)); PREF_CUSTOM_JAVA_ARGS = DEFAULT_PREF.getString("javaArgs", "");