Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Duo: keep portrait through animated fold sweeps

Jackyb0863cd85bb2
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.md
index f5b7433b..2da98405 100644
--- a/Research/Guest/iphone_duo_bringup.md
+++ b/Research/Guest/iphone_duo_bringup.md
@@ -3855,3 +3855,19 @@ rotation matrix 90/0/270/0 exact; open home screen visually clean (portrait
grid, horizontal dock, no clipping). Known remaining behavior: closing while
unlocked sleeps the screen by design — the next wake presents the cover lock
screen (clock) and `screen.unlock` (or a swipe) returns to the home layout.
+
+Follow-up (same morning, animated sweeps): the fold panel's animated sweeps
+(duration > 0) exposed two residual transients. The hinge sweep's
+fully-closed band crossing re-derives the cover direction once more near its
+end, after vphoned's first correction; and opening carried the cover's
+portrait pose (device 1) into the rotated inner mounting, flashing
+landscape-left until the loop re-resolved. Fixes: the resolve loop's first
+pass now pokes pose-refresh/arbitration/actuation immediately after the
+bounds confirm (the export wait moved to the retry pass only), the posture
+path holds one final actuation batch until `vp_hinge_get()["sweeping"]`
+clears, the open direction seeds the measured inner portrait (device 3 /
+270°) before the viewport apply, and the dylib's viewport adoption completes
+the cover actuation inline (`vpScheduleViewportAdoption`), so the correct
+direction lands in the same adoption turn instead of a second later. Button
+path (duration 0) verified 3/3 roundtrips clean; animated paths sample clean
+with an occasional single-sample (~0.2 s) self-healing blip on close.
diff --git a/VPhoneDaemon/Daemon/GuestAPI+Device.swift b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
index 36bf5e8f..f0ba8d26 100644
--- a/VPhoneDaemon/Daemon/GuestAPI+Device.swift
+++ b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
@@ -393,6 +393,23 @@ extension GuestAPI {
if angle! < 5 {
_ = vp_accelerometer_set_orientation("0")
_ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
+ } else {
+ // Opening carries the same problem in reverse: the swap
+ // derives the inner interface from the cover's portrait pose
+ // (device 1), which the rotated inner mounting renders as
+ // landscape-left. The live export cannot carry the inner
+ // table while the cover viewport holds the scene, so seed
+ // the measured inner portrait (device 3 / 270°, the
+ // [3,4,2,1] table in the research notes); the post-swap
+ // loop re-resolves from the live table either way.
+ let current = vp_device_pose_get()
+ _ = vp_device_pose_set(
+ 3,
+ (current["hinge"] as? NSNumber)?.int32Value ?? Int32(hinge),
+ (current["tabletop"] as? NSNumber)?.int32Value ?? Int32(tabletop)
+ )
+ _ = vp_accelerometer_set_orientation("270")
+ _ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
}
GuestFoldPose.requestViewport(for: angle!)
let expected = angle! < 5 ? [0.0, 0.0, 466.0, 678.0] : [0.0, 0.0, 669.0, 951.0]
@@ -423,15 +440,20 @@ extension GuestAPI {
let desiredInterface = "0"
if orientation == Self.poseOrientations["portrait"] {
var settled = false
- for _ in 0..<2 where !settled {
- let staleUptime = (vp_display_orientation_mapping()["generatedUptime"] as? NSNumber)?.doubleValue ?? 0
- _ = try? postDarwinNotification("com.vphone.display.orientation.mapping.request", state: nil)
- let exportDeadline = ProcessInfo.processInfo.systemUptime + 0.8
- while ProcessInfo.processInfo.systemUptime < exportDeadline {
- let live = vp_display_orientation_mapping()
- if ((live["generatedUptime"] as? NSNumber)?.doubleValue ?? 0) > staleUptime,
- (live["configurationBounds"] as? [NSNumber])?.map(\.doubleValue) == expected { break }
- Thread.sleep(forTimeInterval: 0.05)
+ for pass in 0..<2 where !settled {
+ if pass > 0 {
+ // The first pass pokes immediately with the best
+ // table it has; only a failed confirmation waits
+ // for a post-apply export to settle the table.
+ let staleUptime = (vp_display_orientation_mapping()["generatedUptime"] as? NSNumber)?.doubleValue ?? 0
+ _ = try? postDarwinNotification("com.vphone.display.orientation.mapping.request", state: nil)
+ let exportDeadline = ProcessInfo.processInfo.systemUptime + 0.8
+ while ProcessInfo.processInfo.systemUptime < exportDeadline {
+ let live = vp_display_orientation_mapping()
+ if ((live["generatedUptime"] as? NSNumber)?.doubleValue ?? 0) > staleUptime,
+ (live["configurationBounds"] as? [NSNumber])?.map(\.doubleValue) == expected { break }
+ Thread.sleep(forTimeInterval: 0.05)
+ }
}
if let values = vp_display_orientation_mapping()["deviceOrientations"] as? [Int],
let portrait = GuestDisplayRotation.resolve(desiredInterface, deviceOrientations: values) {
@@ -449,7 +471,7 @@ extension GuestAPI {
_ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
_ = try? postDarwinNotification("com.vphone.display.orientation.arbitration.refresh", state: nil)
_ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)
- let confirmDeadline = ProcessInfo.processInfo.systemUptime + 1.5
+ let confirmDeadline = ProcessInfo.processInfo.systemUptime + 1.2
while ProcessInfo.processInfo.systemUptime < confirmDeadline {
if interfaceRotationDegrees() == portrait.interfaceDegrees {
settled = true
@@ -459,6 +481,24 @@ extension GuestAPI {
}
}
}
+ // A hinge sweep re-derives the cover direction once more when
+ // it crosses the fully-closed band near its end; hold the
+ // portrait actuation until the sweep has finished.
+ if sweep {
+ let sweepDeadline = ProcessInfo.processInfo.systemUptime + 2.5
+ while ProcessInfo.processInfo.systemUptime < sweepDeadline {
+ let hingeNow = vp_hinge_get()
+ if (hingeNow["sweeping"] as? Bool) != true { break }
+ Thread.sleep(forTimeInterval: 0.05)
+ }
+ _ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
+ _ = try? postDarwinNotification("com.vphone.display.orientation.arbitration.refresh", state: nil)
+ _ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)
+ if interfaceRotationDegrees() != 0 {
+ Thread.sleep(forTimeInterval: 0.3)
+ _ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)
+ }
+ }
_ = try? postDarwinNotification("com.vphone.display.orientation.pose.refresh", state: nil)
_ = try? postDarwinNotification("com.vphone.display.orientation.arbitration.refresh", state: nil)
_ = try? postDarwinNotification("com.vphone.display.orientation.actuation.refresh", state: nil)
diff --git a/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m b/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
index 92ee9498..2a7a3cea 100644
--- a/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
+++ b/VPhoneGuestComponents/FoldDisplay/libvphonefolddisplay.m
@@ -140,6 +140,7 @@ static NSArray *vpSnapshotRect(id object, const char *name);
static void vpProcessViewportWorkspaceRequest(BOOL submit);
static void vpApplyRootGeometry(void);
static void vpScheduleViewportAdoption(void);
+static void vpRefreshNativeOrientationActuation(void);
static void vpApplyQuickActionGlyphScale(void);
// These helpers are kept at the boundary so the extracted status/wallpaper
@@ -276,7 +277,16 @@ static void vpScheduleViewportAdoption(void) {
if (adoptionGeneration == atomic_load_explicit(&vpAdoptionCompletedGeneration, memory_order_relaxed)) return;
atomic_store_explicit(&vpAdoptionCompletedGeneration, adoptionGeneration, memory_order_relaxed);
vpApplyRootGeometry();
- if (vpPersistentViewport) vpProcessViewportWorkspaceRequest(YES);
+ if (vpPersistentViewport) {
+ vpProcessViewportWorkspaceRequest(YES);
+ // The cover arbiter derives its direction once, at the mode swap,
+ // from the pre-swap pose, and holds it; vphoned's confirm loop
+ // corrects it only after the bounds settle, leaving a landscape
+ // frame visible for about a second. Complete the actuation with
+ // the cover's native portrait in the same adoption turn.
+ if (atomic_load_explicit(&vpCoverViewportEnabled, memory_order_acquire))
+ vpRefreshNativeOrientationActuation();
+ }
}
static void vpApplyRootGeometry(void) {
if (!vpAutomaticMainStatus) return;