Skip to content

Conversation

@alexytomi
Copy link
Member

@alexytomi alexytomi commented Aug 19, 2025

A clone of PojavLauncherTeam#6462, but Amethyst

Not so much anymore

This PR basically takes only the minimum out of what's needed to get controller pass-through working properly, anything else wasn't given thought.

Thanks isXander for most of the reference material used for this PR

- Add "Gamepad passthrough" option to disable Pojav controller emulation and allow games to process controllers directly.
- Add SDL3 AAR and add it as a dependency.
- Add SDL lifecycle events in main activity
- Add support for SDL in the main activity and include it as a dependency in the `Android.mk`.
- Update `libjnidispatch.so` files for all arch.
@alexytomi
Copy link
Member Author

This compiled locally wtf

@alexytomi alexytomi force-pushed the feat/sdl branch 5 times, most recently from c2e4753 to a9f3639 Compare August 22, 2025 09:03
This depends on the specific version of SDL shipped here, the changes to
SDL required to make this work has been reverted due to being a breaking
change.

See here for more info:
libsdl-org/SDL#11891

fix(workflow): Use Java 21 for the entire build

remove overkill checks

add checks for instantiation and static method calls

feat(SDL): Update strings

fix(SDL): Include libSDL3.so

This was put in the ANGLE module by the original commit which now
doesn't exist so it had to be readded.
For some reason it was no longer in full screen when starting the game,
this fixes that
Oculus controllers makes a motion event that doesn't have a device
attached to it. Weird but ok.
@alexytomi alexytomi force-pushed the feat/sdl branch 2 times, most recently from 4967b4d to 2eee393 Compare September 1, 2025 15:03
@alexytomi alexytomi changed the title SDL support by @isXander SDL support Sep 1, 2025
@alexytomi alexytomi marked this pull request as ready for review September 1, 2025 15:44
Legacy4J has code that traps us inside GLFW only, soo this is a hacky
workaround. It works but I'd prefer we don't have it at all.
@alexytomi
Copy link
Member Author

alexytomi commented Sep 17, 2025

Changes

  • "Enable SDL controller backend"

    • Enables SDL
    • Input passthrough to our keys input forwarder is blocked when SDL is active as it causes issues with duplicate inputs.
    • GLFW will still be present be cause there is no way to remove or disable it, if we do so forcefully, even more buggier behavior appears. To minimize the effect of this buggy behavior, I have disabled input passthrough to GLFW when the SDL subsystems are active.
      • Test: If disabled, we should have identical behavior as to before this PR with all inputs, controller or not.
  • "Forcibly start SDL controller handling"

    • Starts the SDL subsystems for gamepad, joystick, and events inMainActivity.onCreate().
  • Legacy4J old version detection

    • Detects whether or not Legacy4J properly loaded our SDL or used GLFW
      • If GLFW was used
        • Start the SDL subsystems for gamepad, joystick, and events.
        • Show a warning to enable the SDL backend for best experience
    • Technically this is bugged in versions 1.7.4 and below as it never removes the log listener, in that case but I am not supporting that. Update already or deal with the immense overhead of essentially having the log output open at all times (ooo scary, not really tbh).
      • We should use regex to filter out 1.7.5 and above but I don't think anyone is gonna be using those ancient versions of Legacy4J any time soon so am not gonna
  • Controllable native loading mitigation

    • If controllable is found, we try to delete the natives it extracts asap, before it can dlopen them and crash because it's dlopening a glibc lib in android
      • This is a horrible race condition, a bug report should be filed with controllable to fix this.
      • This happens because controllable sets the setExtractionPath() which only falls back if the path isn't valid, else it crashes trying to dlopen the linux glibc native

@ThatStella7922
Copy link

ThatStella7922 commented Sep 21, 2025

Testing https://github.com/AngelAuraMC/Amethyst-Android/actions/runs/17873979455

Minecraft 1.21.8 fabric loader 0.17.2

Vanilla game:
Screenshot_2025-09-21-00-42-29-59_59e3738f718bc4374df4f834029b3543
Works fine, glfw controller setup wizard appeared and glfw controller support works

Controllify 2.4.1:
Screenshot_2025-09-21-00-49-19-50_59e3738f718bc4374df4f834029b3543
Worked fine too, glfw controller support disabled itself and it was purely SDL. No more pojav cursor

I think it's good ngl, this gets the Mommy Stella Seal of Approval™️

@alexytomi
Copy link
Member Author

Worked fine too, glfw controller support disabled itself and it was purely SDL. No more pojav cursor
GLFW wasn't actually turned off, Controlify turns off their GLFW backend when SDL is found.

It can still be selected in Legacy4J but the inputs won't work because of me adding an if statement to not forward inputs into GLFW when SDL joystick subsystem is running.

No longer rely on the pref for SDL enabling, this lets SDL act the same
as GLFW, using the emulated gamepad if SDL isn't inited
This is jank but their implementation of how to default to the system
library demands it.
This is not stable yes, but we need to and since they are willing to
support it we aren't forking
I didn't do this in native because I thought the JNI overhead would've
been worse than doing it in Java
This forces SDL on when an old Legacy4J version, without the android
fixes, is identified using log output
@alexytomi
Copy link
Member Author

Bugfixes

  • The SDL callback did not run only once as intended
  • Accidentally blocked all non-controller inputs when SDL enabled

@alexytomi
Copy link
Member Author

alexytomi commented Sep 21, 2025

Also just for documentation purposes, the Gamepad remapping system wasn't used because I don't wanna do the job that SDL already does, that is filter all that stuff through to an actual input again.

eventKeycode >= KeyEvent.KEYCODE_BUTTON_A && eventKeycode <= KeyEvent.KEYCODE_BUTTON_MODE ensures no weird shit controllers will crash SDL, like an oculus one

If someone somehow has a weirdshit controller they wanna use that isn't registering because of this, they can feel free to make a bug report and I'll try to fix it.

I don't know why android decided it was a good idea to turn unconsumed
MotionEvents into KeyEvents but now it's fixed for SDL too.
@alexytomi alexytomi force-pushed the feat/sdl branch 2 times, most recently from 824521f to bf000d6 Compare September 21, 2025 16:17
Now continously polls the directory where controllable is expected to
extract natives instead of waiting on inotify. This theoretically should
consume quite a bit of the CPU but it seems to not when testing.

This should be much more consistent than waiting on inotify, testing
seems to corroborate that. Anyone who's crashing can send a bug report.
@alexytomi
Copy link
Member Author

Bugfixes

  • Android's garbage keyevents was leaking through to processKeyEvent again due to fixing up the keyboard input blocking
  • Controllable was at the mercy of whether inotify would want to work, now we just poll it..a lot, say hi to fried CPU

@alexytomi alexytomi merged commit c8e74e6 into v3_openjdk Sep 22, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants