Skip to content

iOS: support the iPhone Duo - #54

Merged
kanapitsas merged 8 commits into
kanapitsas:mainfrom
CobreDev:feat/iphone-duo-sdk27
Nov 26, 2026
Merged

kanapitsas merged 8 commits into
kanapitsas:mainfrom
CobreDev:feat/iphone-duo-sdk27

Conversation

@CobreDev

Copy link
Copy Markdown
Contributor

The app was linked against a fake SDK 18 because SDL2 doesn't support UIScene. On the iPhone Duo that meant compatibility mode: a 667×375 point screen with black bars. This links against the real SDK, adopts UIScene without patching SDL, and then makes the game behave properly on the Duo's two displays:

  • Full-screen on the inner and outer displays, and across folding and unfolding while the game runs.
  • Touch controls clear of the rounded corners.
  • Portrait on the inner display: the game on top, the touch controls below.
  • Gyro aiming and back taps in portrait and landscape.
  • Back taps corrected for the Duo only (model iPhone19,4). Other iPhones are unchanged.

Tested: on a physical iPhone Duo, and in the Duo simulator (iOS 27.2) on both displays. Also an iPhone 16 Pro simulator (iOS 18.4), where the game starts full-screen in landscape as before. make check passes.

Notes: building needs Xcode with SDK 27.1 or newer. It warns on older SDKs, and the Duo then falls back to compatibility mode. I haven't tried a physical iPhone older than the Duo. Details are in docs/ios.md.

@CobreDev
CobreDev marked this pull request as ready for review November 25, 2026 17:12

@kanapitsas kanapitsas left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, getting UIScene to work without patching SDL is great.

I tested it on my iPhone 15 Pro Max (SDK 27.2, Metal, mtld3d 101f37d3). Launching while holding the phone upright, both landscape sides, menus, touch controls, back taps while sitting, and coming back from the background all work. make check passes.

Before merging

  1. Back taps while lying on my side: I always got the same portal, whichever side I tapped. The game stays in landscape, but gravity points almost along the phone's y axis, toward the side of the screen. The new code takes that as the bottom of the screen, so it reads the tap side on the wrong axis. On main, the side comes from the interface orientation first.

    I replayed the same recording with both detectors (tools/backtap_replay.c). For the part where I was lying down, main gives 10 left and 10 right, this branch gives 18 left and 2 right. Could we keep main's mapping on regular iPhones, or only trust gravity when it agrees with the interface orientation? Happy to send the recording.

Question

  1. Did the final back-tap mirror for iPhone19,4 work on both displays, folded and unfolded?

Smaller things

  • The 20 pt top margin also applies on regular Face ID iPhones and iPads (outside the split layout). On the 15 Pro Max the control area goes from 409 to 389 pt. It looked fine on my phone, so just a heads-up.
  • Scene reconnect: sceneDidDisconnect clears the scene and the next willConnect makes a new black bootstrap window key. rt_ios_scene_adopt only runs when the window is created, so nothing moves the SDL window to the new scene. I couldn't reproduce it, this is from reading the code.
  • Light taps in portrait: the gyro path in back_tap.c still checks device x at onset and acceptance, so a light tap that mostly rotates around y can be missed.
  • tools/build_ios_probe.sh builds scene_ios.m, which now calls rt_ios_touch_controls_rehost, but doesn't link touch_controls.m.
  • Is beginGeneratingDeviceOrientationNotifications still needed now that the orientation comes from the scene?

Not tested on my side: iPad and gyro aiming.

The app was linked against a fake SDK 18 because SDL2 2.30.9 does not support
UIScene. On the iPhone Duo that put it in compatibility mode: a 667x375 point
screen with black bars. Link against the real SDK, declare a scene manifest and
attach SDL's window to the connected scene, without patching SDL. Building now
warns below SDK 27.1.
Keep the pause button, FPS counter and look button clear of rounded corners
(the Duo reports no safe-area inset on the sides and top). Tell SDL and the game
the size and orientation of the scene's screen: scene-based apps no longer keep
statusBarOrientation up to date, and on the inner display UIScreen.mainScreen
still reports the outer display. This also fixes footer buttons that could not
be tapped and a game drawn into a corner after leaving the app and coming back.
Folding disconnects a screen and SDL's SDL_DisplayWatch crashed in
UIKit_DelDisplay, so remove its observers after SDL_Init (the app uses one
display). SDL also snaps its fullscreen window back to the display size it had
at launch when the app returns to the foreground: compare the window and view
sizes on every event poll and force a layout pass when they differ.
…ntrols below)

In portrait on the inner display the game takes the top half and the touch
controls a second window in the bottom half, keeping the landscape layout. Other
phones stay landscape only (P2_PORTRAIT_SPLIT=0 turns the split off). Also keep
SDL's on-screen keyboard off (P2_SCREEN_KEYBOARD=1 brings it back), always resize
the game window to the scene, move the portrait sticks in, and scale taps into
the engine's coordinates, which keep their launch size.
Read the screen's horizontal axis from gravity instead of assuming how the
Duo's sensor axes lie against the screen, so aiming and back taps work in
portrait and in both landscape orientations. Falls back to the interface
orientation when the phone is nearly flat. The touch overlay now moves as soon as
the layout changes.
…nner display

UIDevice.orientation reports the body of the phone, which on the inner display
said portrait in the wide landscape position and rotated the game when a level
loaded. Do not read it and never ask for portrait: keep the orientation iOS chose
when the scene connected, shrinking the window to the game's half before the
engine creates its surface. Log what the motion sensors see to help diagnose the
Gyro and Back tap settings.
The Duo's sensors gave left and right swapped. A new mirror parameter, set by
the app when the model identifier is iPhone19,4 (logged at startup), swaps the
sides in every orientation and combines with the player's Swap left and right
setting, which is off by default as before. Other iPhones are unchanged.

Docs: describe the Duo correction and what was tried on a Duo.
Back taps and gyro aiming read the screen's axes from gravity, which the
iPhone Duo needs but which breaks a regular iPhone lying on its side
(gravity then points along the screen's side while the game stays in
landscape). That reading, the portrait fallback and the 20 pt top margin
now apply on the Duo only; other devices keep what main does.

- back_tap, gyro_aim: new screen_by_gravity parameter, set from the model
  identifier in backtap_ios.m and gyro_ios.m. Off: interface orientation
  decides, as before the Duo.
- back_tap: the light-tap (gyroscope) path and its onset use the rotation
  about the screen's vertical axis, not device x, so a light tap in
  portrait that mostly rotates around y is no longer missed.
- scene: a reconnected scene (after sceneDidDisconnect) takes over the
  existing SDL window and the controls window instead of getting a new
  black bootstrap window; drop beginGeneratingDeviceOrientationNotifications,
  nothing reads UIDevice.orientation.
- touch controls: the 28/20 pt minimum insets apply on the Duo only.
- probe: stub rt_ios_touch_controls_rehost, which scene_ios.m now calls.
- tests for each, docs updated.
@CobreDev
CobreDev force-pushed the feat/iphone-duo-sdk27 branch from 69f464f to e8d0779 Compare November 26, 2026 15:24

@kanapitsas kanapitsas left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that fixes it. I read the other fixes and they look good. I couldn't trigger a scene reconnect, so that one isn't tested.

@kanapitsas
kanapitsas merged commit 44192e1 into kanapitsas:main Nov 26, 2026
3 checks passed
@CobreDev

Copy link
Copy Markdown
Contributor Author

I came up with a few more changes in the meantime, I'll open a new PR with a few other minor improvements shortly

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