Run a virtual iPhone on an Apple Silicon Mac.
Swift
Duo: let the fold own the shared panel and host hidden windows
Jacky7155421a17be
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.mdindex e89fdee4..a1b6b8f9 100644--- a/Research/Guest/iphone_duo_bringup.md+++ b/Research/Guest/iphone_duo_bringup.md@@ -4602,3 +4602,54 @@ portrait, as on any iPhone.Open: in landscape on the cover, the `AxisAlignableSplitV68Cover` status bardraws its time and battery over Safari's address field.++## 2026-10-29: the fold owns the panel; hidden windows hosted++Reported after manual testing on duospike-inner: the fold control sometimes+left the screen on the inner display or black instead of the cover, the inner+Dock did not respond, and the screen still flickered.++**Fold control.** The shared panel used to follow SpringBoard's power+requests alone (lit while either panel wanted it, the cover winning). Those+requests do not follow the fold:++- With the inner display asleep (the 60 s auto-lock), closing made SpringBoard+ light the inner display for about three seconds and then turn it off; the+ cover was never asked on. The panel showed the folded-away inner display,+ then went black.+- In a long-running SpringBoard, a close resolved FullyClosed (SpringBoard's+ log said so at the next open) without any power request: the panel kept+ showing the inner display.++The panel now belongs to whichever display holds the primary content,+`-[SBDisplayContentModeCoordinator primaryWindowScene]`, and is lit while+that display wants to be; the other panel's requests are applied but not+shown. Ownership is re-read on every power request and after each+`performDisplayContentModeTransitionWithCoordinator:`, so a fold without a+power request still hands the panel over. With that, SpringBoard's own+requests land on the right panel: closing awake, closing after the auto-lock,+closing after the sleep button, and opening asleep each light the arriving+panel (the cover's lock screen or home screen, the inner lock screen). An+extra wake on a fold, tried first, was not needed.+(`_displayContentModeChangedWithContext:continuationLockProvider:` appears in+the symbols only through its blocks; the runtime has no such method.)++**Flicker.** A 120 Hz capture with a per-tile transient detector (a 24×24+grid, a tile that jumps and comes back within two frames) found one frame left:+going home from an app, the first frame of the shrinking app sat on black.+The compositor hosted only visible windows; the home screen's windows came+back with new `CALayerHost`s, and a host draws nothing for its first frame.+Hidden windows are now hosted too (they draw nothing); the frame shows the+dimmed home screen blur instead (backdrop 0.22 instead of 0.12, brightening+over the next frames).++**Touch.** Automation taps and guest-injected touches with and without edge+flags land at the expected points on all four edges and corners, in every+orientation (`locationInView:` equals the screenshot point divided by 3),+and the Dock launches its apps after folds, rotations, sleep/wake and app+switching. The user's dead Dock was in a SpringBoard that had been running+for hours and was not reproduced; once, right after a SpringBoard restart and+a fold, the Dock ignored taps until the next restart while the home screen's+own icons kept working. Not yet explained; the next occurrence should be+caught with `logs.syslog` for SpringBoard during a Dock tap ("Sending UIEvent+... to window" and "Allowing tap for icon view").diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.mindex 9a2ea029..bfd5e593 100644--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayPanel.m@@ -12,15 +12,25 @@ static void vpShowInnerDisplay(BOOL shown);// on, 0 off): open, the cover (primary, display 1) goes off and the inner// display on; closed, the reverse. On this guest the primary is the only// scanout, and open it has to show the inner display, which SpringBoard-// composites onto it (vpShowInnerDisplay). So the primary is kept on while-// either panel wants it; a screen-off turns both off. Closing does not turn-// the inner display off, so the inner display is lit only while the cover is-// not: the cover wins the shared panel. The compositor and backboardd's touch-// routing follow the inner display's applied state.+// composites onto it (vpShowInnerDisplay). Which panel the scanout shows+// follows the fold, not the power requests: the panel holding the primary+// content (SBDisplayContentModeCoordinator's primaryWindowScene) owns it, and+// the scanout is on while that panel wants to be. SpringBoard powers the+// panel facing away as it likes (closing does not turn the inner display off,+// and closing a sleeping device lights the inner display for a moment); on a+// real Duo that panel is folded away, so here it is not shown. The compositor+// and backboardd's touch routing follow the inner display's applied state.static IMP vpOriginalTransitionDisplayState;static id vpPrimaryStateControl, vpInnerStateControl;static long long vpPrimaryWantedState = 1, vpPrimaryAppliedState = 1, vpInnerWantedState, vpInnerAppliedState = -1;+// The cover until the inner display is resolved and holds the primary content.+static BOOL vpInnerOwnsPanel(void) {+ id innerScene = vpSpringBoardWindowScene(YES);+ id coordinator = vpReadObject(vpReadObject(objc_getClass("UIApplication"), "sharedApplication"), "displayContentModeCoordinator");+ return innerScene && vpReadObject(coordinator, "primaryWindowScene") == innerScene;+}+static unsigned int vpStateControlDisplayId(id control) {Ivar ivar = class_getInstanceVariable(object_getClass(control), "_display_id");if (!ivar || strcmp(ivar_getTypeEncoding(ivar), "I") != 0) return 0;@@ -35,9 +45,10 @@ static void vpApplyPanelState(id control, long long state, long long *applied, i}static void vpApplyPanelStates(id primaryCompletion, id innerCompletion) {- vpApplyPanelState(vpPrimaryStateControl, vpPrimaryWantedState || vpInnerWantedState ? 1 : 0,+ BOOL innerOwns = vpInnerOwnsPanel();+ vpApplyPanelState(vpPrimaryStateControl, (innerOwns ? vpInnerWantedState : vpPrimaryWantedState) ? 1 : 0,&vpPrimaryAppliedState, primaryCompletion);- long long inner = vpInnerWantedState && !vpPrimaryWantedState ? 1 : 0;+ long long inner = innerOwns && vpInnerWantedState ? 1 : 0;BOOL changed = inner != vpInnerAppliedState;vpApplyPanelState(vpInnerStateControl, inner, &vpInnerAppliedState, innerCompletion);if (changed && vpInnerStateControl) dispatch_async(dispatch_get_main_queue(), ^{ vpShowInnerDisplay(inner != 0); });@@ -84,6 +95,32 @@ static void vpSharedScanoutTransition(id self, SEL selector, long long state, idvpApplyPanelStates(nil, completion);}+// A fold moves the primary content to the other panel, which takes the+// scanout over even when no power request comes with it.+static IMP vpOriginalPerformContentModeTransition;+static int vpInnerOwnedPanel = -1;++static void vpFollowContentModeTransition(id self, SEL selector, id transitionCoordinator) {+ ((void (*)(id, SEL, id))vpOriginalPerformContentModeTransition)(self, selector, transitionCoordinator);+ dispatch_async(dispatch_get_main_queue(), ^{+ BOOL innerOwns = vpInnerOwnsPanel();+ if (innerOwns == vpInnerOwnedPanel) return;+ vpInnerOwnedPanel = innerOwns;+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: panel owned by the %@", innerOwns ? @"inner display" : @"cover"]);+ vpApplyPanelStates(nil, nil);+ });+}++static void vpInstallContentModeOwnership(void) {+ Method perform = class_getInstanceMethod(objc_getClass("SBDisplayContentModeCoordinator"),+ sel_registerName("performDisplayContentModeTransitionWithCoordinator:"));+ if (!perform || strcmp(method_getTypeEncoding(perform), "v24@0:8@16") != 0) {+ vpFoldDisplayLog(@"inner display: content mode transition ABI unavailable");+ return;+ }+ vpOriginalPerformContentModeTransition = method_setImplementation(perform, (IMP)vpFollowContentModeTransition);+}+void vpInstallSharedPanel(void) {Method transition = class_getInstanceMethod(objc_getClass("CADisplayStateControl"),sel_registerName("transitionToDisplayState:withCompletion:"));@@ -94,6 +131,7 @@ void vpInstallSharedPanel(void) {return;}vpOriginalTransitionDisplayState = method_setImplementation(transition, (IMP)vpSharedScanoutTransition);+ vpInstallContentModeOwnership();vpFoldDisplayLog(@"inner display: shared scanout installed");}@@ -178,7 +216,10 @@ static void vpFitInnerHosts(CGRect inner) {// Runs just before Core Animation commits each main run loop turn, so a// window SpringBoard shows or hides and its host change in one transaction:-// syncing later leaves a frame without the window's content.+// syncing later leaves a frame without the window's content. Hidden windows+// are hosted too (they draw nothing): a host created as its window appears+// draws nothing for its first frame, so the home screen going back under a+// closing app left that frame black.static void vpSyncInnerHosts(void) {Class transaction = objc_getClass("CATransaction");((void (*)(id, SEL))objc_msgSend)(transaction, sel_registerName("begin"));@@ -190,8 +231,7 @@ static void vpSyncInnerHosts(void) {NSMutableArray *windows = [NSMutableArray array];for (id scene in [vpReadObject(app, "connectedScenes") allObjects] ?: @[])if ([scene isKindOfClass:objc_getClass("UIWindowScene")] && vpSceneIsOnInnerDisplay(scene))- for (id window in vpReadObject(scene, "windows") ?: @[])- if (![[window valueForKey:@"hidden"] boolValue]) [windows addObject:window];+ [windows addObjectsFromArray:vpReadObject(scene, "windows") ?: @[]];[windows sortUsingComparator:^NSComparisonResult(id a, id b) {return [[a valueForKey:@"windowLevel"] compare:[b valueForKey:@"windowLevel"]];}];