Skip to content

Motion: the phone's sensors turned by Android's display rotation - a foldable's landscape inner screen turned them a quarter too far - #284

Merged
mamcjr merged 1 commit into
mamcjr:mainfrom
ilovz73ai-sketch:motion-foldable-rotation
Nov 8, 2026
Merged

mamcjr merged 1 commit into
mamcjr:mainfrom
ilovz73ai-sketch:motion-foldable-rotation

Conversation

@ilovz73ai-sketch

@ilovz73ai-sketch ilovz73ai-sketch commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On a Galaxy Z Fold 8, unfolded, the phone's motion controls are turned a quarter: turning the phone left/right moves
the aim up/down. Folded (cover screen) they are right. The inner screen is 4:3 and its natural orientation is
landscape
(as on the Pixel Fold or a tablet), and two things in SDL 3.4.16 meet to_screen()'s portrait assumption:

SDL_android.c onNativeRotationChanged:  if (displayNaturalOrientation == LANDSCAPE) rotation += 90
  -> rotation 0 on the inner screen reads as SDL_ORIENTATION_LANDSCAPE
  -> to_screen(): LANDSCAPE = a portrait phone in landscape -> (-y, x): one quarter turn too many
SDLActivity.onCreate is the only place nativeSetNaturalOrientation() is called
  -> the activity survives folding (configChanges has screenSize|smallestScreenSize), so SDL keeps the natural
     orientation of the screen the app started on; and Android_SendOrientationUpdate only passes an orientation on
     when its landscape-ness matches the desktop mode's

The sensor axes follow the display's natural orientation, so what to_screen() needs is the rotation from the
natural orientation - Android's Display.getRotation().

The change (runtime/hle/motion.c only)

  • screen_turns(): Display.getRotation() of the activity's display through JNI (SDL_GetAndroidJNIEnv /
    SDL_GetAndroidActivity, inside a local frame, exceptions cleared), asked at most every 250 ms since folding sends
    no event here. Without JNI: SDL's orientation less its natural orientation.
  • to_screen() turns by that: 1 -> (-y, x), 3 -> (y, -x), 2 -> (-x, -y), 0 -> as is.
  • On portrait phones rotation 90 / 270 maps exactly as LANDSCAPE / LANDSCAPE_FLIPPED did, so nothing changes there.
  • A log line when the turn changes: [motion] the screen is turned N degrees from its natural orientation.

Testing

  • Compiles cleanly with NDK r28c (aarch64-linux-android30) against the SDL 3.4.16 headers (the tarball's sha256
    matches android/deps/build_deps.sh), with the app's flags plus -Wall -Wextra: no warnings.
  • The same mapping (sensor axes turned by Display.getRotation()) was checked on an API 37 emulator with a 2400x1800
    landscape-natural display, against injected gyroscope readings: a yaw moved the screen point sideways with it,
    while the portrait-assuming mapping moved it vertically - the reported symptom.
  • In game on a Galaxy Z Fold 8, unfolded: motion controls aim the right way with this change (details in the
    comment below). Not checked here: a regular portrait phone (rotation 90 / 270 maps exactly as before).

🤖 Generated with Claude Code

… SDL's orientation - a foldable's landscape inner screen

SDL 3.4.16 counts a quarter turn more on a display whose natural orientation is
landscape (SDL_android.c onNativeRotationChanged), so on an unfolded Galaxy Z Fold 8
(4:3 inner screen) rotation 0 read as SDL_ORIENTATION_LANDSCAPE and to_screen() turned
the axes 90 degrees too far: turning the phone tilted the aim. SDL also takes the
natural orientation only in SDLActivity.onCreate, and the activity lives through
folding (configChanges), so it stayed that of the screen the app started on.

to_screen() now asks Android's Display.getRotation() through JNI (at most every
250 ms) - the turn from the display's natural orientation, which the sensor axes
follow - and without JNI takes SDL's orientation less its natural one. On portrait
phones rotation 90 / 270 maps as LANDSCAPE / LANDSCAPE_FLIPPED did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ilovz73ai-sketch

Copy link
Copy Markdown
Contributor Author

Tested on a Galaxy Z Fold 8, unfolded (4:3 inner screen, natural orientation landscape): with this change the phone's motion controls aim the right way - turning the phone left/right moves the aim left/right again, instead of up/down as with 0.3.1-beta.

How it was built: this branch (0.3.1-beta + this commit) with the app's Gradle build, libmain.so compiled from source; SDL3, shaderc, FFmpeg and the game code builder taken unchanged from the official 0.3.1-beta APK (same gen.id and game code id as the release). Installed beside the official app under another applicationId, so only the runtime differs.

Driver: a8xx-turnip-gen8-sync-V29. Unrelated to this PR but maybe useful for #32: on this phone the game also had the red tint in shadowed areas (worst on rocky ground) with the previous driver; Driver compatibility > Draw-target reads in place = Off did not change it, switching to a8xx-turnip-gen8-sync-V29 cleared it.

Ready for review from my side.

@ilovz73ai-sketch
ilovz73ai-sketch marked this pull request as ready for review November 6, 2026 01:41
@mamcjr
mamcjr merged commit f4bdeb3 into mamcjr:main Nov 8, 2026
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.

2 participants