Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Put a refused rotation back so the iPad pointer stays upright

Jacky08ffc14fb2bb
diff --git a/Research/Guest/springboard_orientation_stuck.md b/Research/Guest/springboard_orientation_stuck.md
index f0cc256d..e71cdc73 100644
--- a/Research/Guest/springboard_orientation_stuck.md
+++ b/Research/Guest/springboard_orientation_stuck.md
@@ -219,7 +219,10 @@ AX orientation request whenever the HID provider is alive and enumerated.
Mobile preferences retain the pose across a SpringBoard or backboardd restart;
invalid or absent preferences default to stationary portrait. The read form
adds `accelerometer` with the configuration and provider status. Its original
-SpringBoard interface-orientation readback still decides request success.
+SpringBoard interface-orientation readback still decides request success, and a
+refused request puts the previous pose back and asks again for the previous
+interface orientation; otherwise the persisted pose and iPadOS's pointer stay
+turned the way the interface is not.
Nested `orientation_sink` reports native readiness, the last BKS orientation
and delivery count separately from HID enumeration/dispatch. The outer
`device_orientation` remains UIDevice's value in vphoned, which does not
diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.md
index c778f2ac..23c1ee3c 100644
--- a/Research/vphoned_http_api.md
+++ b/Research/vphoned_http_api.md
@@ -403,7 +403,11 @@ dispatch, which by itself did not drive orientation on the research board.
When the provider is running, setting rotation first publishes a stationary
gravity pose matching the requested orientation. The existing SpringBoard
request and interface-orientation readback still decide success; a running HID
-provider is not an acknowledgement that SpringBoard rotated. The selected
+provider is not an acknowledgement that SpringBoard rotated. A refused request
+puts the previous pose back and asks again for the interface orientation from
+before it. A refused request still turns iPadOS's pointer: with the screen off,
+an upside-down request left the interface portrait and the pointer upside down,
+so the mouse moved backwards until a request for the current orientation. The selected
`system-backboardd-cfw-accelerometer` patch installs this provider; older or
disabled guests retain their existing rotation path.
diff --git a/VPhoneDaemon/Daemon/GuestAPI+Device.swift b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
index a6bb08ef..9abb90c2 100644
--- a/VPhoneDaemon/Daemon/GuestAPI+Device.swift
+++ b/VPhoneDaemon/Daemon/GuestAPI+Device.swift
@@ -77,12 +77,31 @@ extension GuestAPI {
// Preserve the physical pose across SpringBoard relaunches.
// CoreMotion's app pose provider cannot feed this HID sink.
let accelerometer = vp_accelerometer_get()
- if accelerometer["provider_running"] as? Bool == true {
+ let previousPose = (accelerometer["degrees"] as? NSNumber).map { String($0.intValue) }
+ let publishesPose = accelerometer["provider_running"] as? Bool == true
+ let previousInterface = interfaceRotationDegrees()
+ if publishesPose {
guard vp_accelerometer_set_orientation(orientation) else {
throw GuestAPIError.operationFailed("Could not publish the accelerometer orientation")
}
}
- return try setRotation(orientation)
+ do {
+ return try setRotation(orientation)
+ } catch {
+ // A refused rotation leaves the guest as it was. The pose
+ // is persisted, and a refused request still turns iPadOS's
+ // pointer: with the screen off, an upside-down request
+ // left the interface portrait and the pointer upside down,
+ // so the mouse ran backwards. Asking again for the
+ // interface's own orientation turns the pointer back.
+ if publishesPose, let previousPose {
+ _ = vp_accelerometer_set_orientation(previousPose)
+ }
+ if let previousInterface {
+ _ = try? setRotation(String(previousInterface))
+ }
+ throw error
+ }
}
var rotation = rotationInfo()
rotation["accelerometer"] = vp_accelerometer_get()