Repository navigation
feat: touch the display in use on iPhone Duo - #12
Conversation
On an iPhone Duo every touch went to the cover display's touchscreen, so nothing happened on the inner display while the phone was unfolded. The phone lists one touchscreen per display, named after the display's uniqueId (`CoreDevice touchscreen(123-456-789)`), and a touch lands only on the display whose touchscreen gets it. When an input connection lists more than one touchscreen, iph now asks the phone before every gesture which display is in use (CoreDevice `getdisplayinfo` on `com.apple.coredevice.deviceinfo`, about 15 ms on an open connection) and sends the gesture to that display's touchscreen. Every touch report, the priming release included, leaves through one function in `device::input` that picks the touchscreen. iph maps points by the rule measured on an iPhone Duo (iOS 27.2.1). The system's own surfaces, such as the home screen and Control Center, are applications with no name, and their frames are in the panel's points, so iph does not turn them. App frames and direction gestures are in the points of the turned screen, and iph turns them onto the panel. The display info also gives a reading its size, because the home screen's application frame says the cover display's size even when the inner one is in use. Each element is clipped to its own space, and the covered check compares frames on the panel. iph does not guess. When it cannot tell which display is in use, or that display's size for the gesture's space differs from the reading's (the phone was folded, unfolded or turned since), the gesture fails with `display_unknown` or `display_changed` and nothing is sent. A phone with one touchscreen is never asked and gets the same reports at the same coordinates on the main touchscreen as before. iph learns how many touchscreens a phone has from its first input session and keeps the count in `<udid>.touchscreens`. Until then readings are as before, and a tap on such a phone opens the input session before it reads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The known limits in README.md and README.ko.md say how touches find the display in use on an iPhone Duo, which two errors send nothing (`display_unknown`, `display_changed`), that the home screen's frames keep the panel's orientation, and that rot180 is not measured. The touch section of docs/how-it-works.md names the touchscreens and the `getdisplayinfo` request. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On an unfolded iPhone Duo `iph screenshot` saved a black picture of the cover display, which is off, and `iph record start` failed: display 1 sent no video, and displays 0 and 2 failed with `display_mismatch`. The inner display sends its frames the way its panel lies (1408x2016) while the screen reads in landscape (951x669 points). On a phone with two displays, both now ask the phone which display is in use, with the same `getdisplayinfo` request touches use. A screenshot names that display's `uniqueId` to the capture service, which draws the picture the way the screen is turned: unfolded in landscape it is 2853x2007 and upright, so iph does not turn it. A recording asks for that display's video by its `displayId` (1 the cover, 2 the inner display) and checks the frames against the display's panel instead of the screen as read. When the frames come in the panel's orientation, the file's track matrix carries the display's turn, so players show the recording the way the screen looked. The muxer always writes the identity matrix; the turned moov has the same length and is written in its place. Frames are not re-encoded. `--display` still names a display. When iph cannot tell which display is in use, the screenshot and the recording fail with `display_unknown` instead of capturing another one. A phone with one display is never asked: it gets the same screenshot request, the same displays tried in the same order against the screen as read, and the same file. The turn is the one at the start of a recording; turning the phone while it records is not followed. Only rot90 was measured for screenshots and recordings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
HyunSeob
left a comment
There was a problem hiding this comment.
Tested on real devices (build of 8f952e3), and it works well:
- iPhone 15 Pro Max (single touchscreen, USB, iOS 27.0.1): tap, key sequence, long press, scroll, edge-swipe back, home, home-page swipes, and pinch in Maps all behaved as before. The
.touchscreensfile recorded1. - iPhone Duo (Wi-Fi): folded, and unfolded in both landscape orientations and portrait. Opening an app from the home screen, Settings split view (sidebar and detail taps), detail scrolling, home, and home-page swipes all passed. The rot270 double-page swipe from the PR notes did not show up.
Three comments inline. (1) is the one I'd like addressed before merging; (2) and (3) are questions.
| .ok_or_else(|| Unaimed::Unknown(format!("no touchscreen belongs to display {}", display.unique_id)))?; | ||
| if let Some(on) = on { | ||
| let now = display.size(on.space); | ||
| if (now.0 - on.size.0).abs() > 0.5 || (now.1 - on.size.1).abs() > 0.5 { |
There was a problem hiding this comment.
The "changed since the reading" check compares only sizes, so some turns get through.
aim_at rejects a gesture only when the canvas size differs. Two cases keep the same size:
- rot90 ↔ rot270: the screen is 951×669 in both. Read in one landscape, flip to the other before the gesture, and the tap lands at the point-reflected spot (1−u, 1−v).
- Panel space: it is always 669×951, whatever the turn. The test at L949 asserts that a panel canvas passes after a turn. But the home screen does re-lay out its icons when the inner display turns, so a home-screen tap read at rot0 would go out at rot90 on stale frames.
The reading already keeps its display in Screen.display. Carrying unique_id and rotation in Canvas and comparing them here (not just the size) would close both gaps and keep the "never guess" promise.
There was a problem hiding this comment.
Fixed. Canvas now carries the display it was read on, and aim_at refuses with display_changed unless the display's uniqueId, its rotation and the size all match. So rot90 to rot270 is caught, and the panel-space test now asserts the opposite. A reading that did not know its display is refused too, so nothing is guessed on a phone with two touchscreens.
| for _ in 0..3 { | ||
| let (seq, dump) = Box::pin(self.dump(fresh, full)).await?; | ||
| let screen = Screen::build(&dump, opts); | ||
| let display = self.active_display().await?; |
There was a problem hiding this comment.
Question: should a failed getdisplayinfo fail the whole reading?
On a Duo every reading now asks for the display, and an error here turns read into display_unknown. I ran 30 reads in a row on a Duo over Wi-Fi with no failure, so I don't see a practical problem today.
The case I'd wonder about is the fold or unfold itself. parse requires exactly one active display, and if the phone briefly reports 0 or 2 during the transition, a reading taken in that moment fails. The reading itself could still be built without the display info, the way it was before, and every gesture asks again anyway. So degrading to a display-less reading with a warning might be enough here. The hint also points to iph doctor, whose touch_input check the PR says fails on the Duo.
Not blocking. Mainly asking whether failing hard is intended.
There was a problem hiding this comment.
Agreed, failing hard was not needed. A failed display question no longer fails read. The reading is built without display info and carries a display_unknown warning, and its points can never be used to aim, because gestures ask again and a display-less reading is refused with display_changed. Screenshot and record still fail with display_unknown, since capturing the wrong display silently would be worse. The hint no longer points to iph doctor; it suggests waiting a moment after folding or unfolding.
| return Ok(None); | ||
| } | ||
| let tunnel = self.ensure_tunnel().await?; | ||
| let read = match DisplayInfo::open(&tunnel.adapter, &tunnel.rsd).await { |
There was a problem hiding this comment.
Minor: this opens a new com.apple.coredevice.deviceinfo connection (with its XPC handshake) on every call.
InputSession keeps its DisplayInfo link and reuses it, but here every reading (and now every screenshot) connects afresh, including inside the 3-attempt loop in screen(). The 15 ms in the PR description is for an open connection, so the cost of a new one isn't measured. Keeping the link on Session, dropped after an error as InputSession does, would make the two paths match.
There was a problem hiding this comment.
Done. Session keeps the deviceinfo link and drops it after an error, as InputSession does, and when the tunnel is reset. Measured on a Duo: over Wi-Fi a fresh connect plus call took 33 ms (median of 8) against 14 ms on the kept link (median of 12). Over USB the difference is about 1 ms.
`aim_at` compared only the size of the space a gesture's points were read in with the size now. rot90 and rot270 give the same screen size (951x669 on the inner display), so a tap read in one landscape and sent after the phone flipped to the other landed at (1-u, 1-v). The panel's own space has the same size at every turn, and a panel-space reading passed after a turn, but the home screen lays its icons out again when the inner display turns. `Canvas` now carries the display in use when it was read, and `aim_at` refuses with `display_changed` unless that display's `uniqueId`, its turn and the size are all as they are now. A reading that did not know its display is refused the same way on a phone with several touchscreens instead of being guessed. The message now names the display and the turn on both sides, since the sizes alone can be equal. Taps, swipes and pinches that go out while the screen cannot be read (Control Center during a recording) use the display of the last complete reading, so they still reach a Duo's display when nothing changed. `Canvas` is no longer `Copy`, so gestures and the aiming helpers pass it by reference. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Every reading, screenshot and recording start opened a new `com.apple.coredevice.deviceinfo` connection with its XPC handshake to ask `getdisplayinfo`, and `screen()` asked again on each of its three attempts. `Session` now keeps the connection, as `InputSession` keeps its own for gestures. It is dropped after an error, since a request cut off leaves its answer on the connection for the next question to read, and with the tunnel it runs on (`reset`). Measured on an iPhone Duo (iOS 27.2.1), 8 fresh connections and 12 calls on a kept one, medians: over Wi-Fi a fresh connect plus call took 33.0 ms (19.2 connect, 13.8 call) against 14.4 ms on the kept connection; over USB 7.5 ms (2.0 connect, 5.2 call) against 6.4 ms. A kept connection still answered after 120 s idle on both. IPH_TRACE=1 now logs each answer and whether the connection was kept. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A failed `getdisplayinfo` failed the whole reading with `display_unknown`. While the phone folds or unfolds it may briefly report no active display or two, which `parse` rejects, so `iph read` failed for a moment although the accessibility tree was fine. A reading now goes on without the display and carries the reason: the result of `iph read` has a `display_unknown` warning, and the screen's size is the application frames' as it was before display support. Points from such a reading are never sent. Every gesture asks for the display again, and `aim_at` refuses a reading that did not know its display with `display_changed`, so nothing is guessed on a phone with two touchscreens. Screenshots and recordings still fail with `display_unknown`: capturing the wrong display without saying so is worse than failing. The last complete reading that knew its display stays the one the unread paths (Control Center during a recording) go out on. The `display_unknown` hint no longer points to `iph doctor`, whose `touch_input` check fails on a Duo; it says the phone may be folding or unfolding and to try again in a moment. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
HyunSeob
left a comment
There was a problem hiding this comment.
Approving. Re-tested on real devices at 858243e:
- iPhone 13 Pro (one display): taps, page swipes, Settings navigation, scrolling, long press, a Maps pinch zoom, a screenshot (1170x2532) and a recording (no rotation in the track, as before). All fine.
- iPhone Duo unfolded, rot90: taps, swipes and drags on the home screen and in Settings; screenshot upright at 2853x2007; recording 1408x2016 with -90 in the track matrix, plays upright.
- iPhone Duo unfolded, rot270 (after flipping the phone): taps right after the flip, home screen and Settings navigation; screenshot upright at 2853x2007; recording with +90 in the track matrix, plays upright. That covers the turn the description says was not measured.
All three review points are addressed as discussed.
|
Merged, thank you @Kofktu! 🙏 Touch, screenshots and recording now work on the display actually in use on iPhone Duo, which is a big step for iph on the foldable. I really appreciated how carefully this was done: the mapping measured on the phone itself, the "never guess, refuse instead" rule, and quick, thorough follow-ups on every review point with real numbers behind them. Thanks for the great contribution! |
Why
On iPhone Duo (two displays: a cover display and an inner one that unfolds), iph can read the screen while the phone is unfolded, but no touch does anything. Every touch report goes to touchscreen 257, which belongs to the cover display, and the cover display is off while the phone is unfolded. Screenshots came out black and
recordrefused to start for the same reason.What changed
uniqueId(CoreDevice touchscreen(987-654-321)for the cover,CoreDevice touchscreen(123-456-789)for the inner display). A touch lands only on the display whose touchscreen receives it.getdisplayinfooncom.apple.coredevice.deviceinfo, over the existing tunnel, so no Xcode is involved. On an open Wi-Fi connection this took a median of 15 ms.device::inputthat picks the touchscreen and maps the point.display_unknown. A reading remembers the display, rotation and size it was read on, and if any of them differs when the gesture is sent (the phone was folded, unfolded or rotated in between), it fails withdisplay_changed. Nothing is sent in either case. Areadthat cannot learn the display still returns the elements, with adisplay_unknownwarning, and its points cannot be used to aim.screenshotandrecordcapture the display in use on these phones.recordkeeps those frames and writes the display's rotation into the MP4 track matrix, so players show it upright without re-encoding. The fit check compares the video with the panel size from the display info instead of the rotated screen.record --display Nstill records the display you name.Testing
cargo test --locked: all pass, including the measured mapping table and the single-touchscreen parity tests.screen_changed/app_changedand a follow-up read):screenshoton the home screen and in Settings gave upright 2853x2007 PNGs.recordon both, with a page swipe and a tap during recording, wrote 1408x2016 files with a -90 rotation that QuickLook and ffmpeg play upright.screenshotgave the cover display (1398x2034) andrecordwrote the cover (1408x2048) with no rotation, as before.Not in this PR
doctor'stouch_inputcheck. It fails on the Duo even when touch works.Notes for review
readreports the rotated screen size, while home-screen element frames stay in panel points. Tapping elements is unaffected, but scripts that compute raw points from the reported size on the home screen should know this.screenshotandrecordbehave as on a single-display phone (the cover display). The READMEs say so.recordresult reports the frame size as sent (1408x2016) and has no field for the rotation, to keep its output unchanged.<udid>.touchscreensacross daemon restarts.