Run a virtual iPhone on an Apple Silicon Mac.
Swift
Implement HomePod top cap tap and long press HID events
Guilherme Rambof2b1d06de8e7
diff --git a/Research/Firmware/homepod_mini_support.md b/Research/Firmware/homepod_mini_support.mdindex 01751e9b..4f76e665 100644--- a/Research/Firmware/homepod_mini_support.md+++ b/Research/Firmware/homepod_mini_support.md@@ -269,8 +269,39 @@ while retaining keyboard and accessibility activation. Quick taps last at least700 ms after the guest acknowledges key-down. Timing from the mouse event cancollapse a tap's down/up into adjacent RPCs when input delivery is delayed.This preserves a usable consumer-key hold for instantaneous mouse/AX taps.-The center touch surface has no-input mapping yet and is excluded from accessibility/tab navigation.+The center touch surface sends consumer Play/Pause (`0x0C/0xCD`) and is+included in accessibility and tab navigation. Its releases have no artificial+minimum duration, preserving rapid taps for SoundBoard's native multi-tap+recognizer. A 500 ms host hold emits a second down event with+`KeyboardLongPress`, followed by an up event carrying the same flag. Releasing+the control, losing focus or disconnecting cancels the pending hold timer.+The hold transitions require the updated vphoned's `input.hid long_press`+support; volume and ordinary center taps use the existing raw HID interface.++### Center HID mapping (2026-10-23)++`SBHPIOHID.handleHIDEvent:` in the extracted 27.0 (24J361) and 27.2 (24K120)+SoundBoardFramework images accepts keyboard event type 3, consumer page 12.+It maps usage `0xCD` to button 3 (Center), `0xE9` to Plus, `0xEA` to Minus,+and reads down and long-press fields `0x30002` and `0x30005`.+REA evidence: `ev_c06211a723a7d6257055f853e4d1ed982d84f08cce3e8980dd3af5205b02d6f2`+(27.0), `ev_84c723a63651c2f7aba20a4ba81435d36d8bcfd514d86cd03c9a6219cc8eee45`+(27.2). Image hashes are recorded in the SoundBoard controls/Sound Glow docs.+`SBButtonInterface.SBIOHIDEventOccurred:` forwards ordinary releases to+`SBTapGestureRecognizer`, long-press down to `holdBeganAtTime:`, and long-press+up to `holdEndedAtTime:`. The host does not synthesize play/skip/Siri commands+through the debug interface; SoundBoard owns gesture recognition and routing.+The 500 ms threshold is a host interaction choice, not a recovered firmware+timing constant. Apple's [IOHID keyboard event implementation](https://github.com/apple-oss-distributions/IOHIDFamily/blob/main/IOHIDFamily/IOHIDEvent.cpp)+also distinguishes down from longPress.++The AppKit input harness exercises the actual top-cap view's mouse/AX hit+areas, three rapid tap pairs, long-press start/end, timer cancellation and+unchanged volume timing. The native HID harness captures the actual encoder's+IOKit calls and checks long-press on both transitions, sender identity,+synchronous dispatch and unavailable-symbol handling. Both harnesses and the+full VPhone bundle/admission build passed. This is local event validation;+live playback, multi-tap actions and Siri activation have not been retested.### Top-cap validation (2026-10-22)diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.mdindex 23c1ee3c..47d8da21 100644--- a/Research/vphoned_http_api.md+++ b/Research/vphoned_http_api.md@@ -372,7 +372,7 @@ request carries `"force": true`.| --- | --- || Device | `device.snapshot`, `device.info` (snapshot plus network, screen, rotation, brightness, volume, low power, Developer Mode, agent, `device_name` `{name, own_name}`: the pinned name and the guest's own ComputerName), `device.screen`, `device.network`, `device.ioreg {plane}`, `device.environment`, `device.basebin {archive?}` || Display, audio | `display.brightness {value?}`, `display.rotation {orientation?}`, `display.orientation` (`{degrees, source}`: SpringBoard's interface orientation without a screen capture, for polling; `degrees` is null while SpringBoard has no answer; capability `display_orientation`), `display.rotation_lock {locked}`, `display.auto_lock` (`{auto_lock_seconds, never, lock_screen_minimum_seconds}`), `display.auto_lock.set {seconds}` (writes the mobile UserSettings input through cfprefsd, posts profiled's effective-settings notification, and returns an immediate readback; the caller must verify the effective value), `screen.unlock {passcode?, timeout?}` (`{locked, screen_off, was_locked, was_screen_off}`: the display on and the Lock Screen passed, see below; capability `screen_unlock`), `audio.volume {value?, category?}`, `audio.state` |-| Input | `input.touch`, `input.hid`, `input.button {name}`, `input.key {name}`, `input.type {text, delay_ms?}`, `input.paste {text}`, `input.tap`, `input.double_tap`, `input.long_press`, `input.swipe`, `input.drag {points}`, `input.touch_sequence {events}` — gesture coordinates are screen points; `input.pointer {x, y, seq?, buttons?}`, `input.scroll {phase, dx?, dy?, x?, y?}` (capabilities `pointer_scroll` and `pointer_buttons`, see below) |+| Input | `input.touch`, `input.hid {page, usage, down?, long_press?}`, `input.button {name}`, `input.key {name}`, `input.type {text, delay_ms?}`, `input.paste {text}`, `input.tap`, `input.double_tap`, `input.long_press`, `input.swipe`, `input.drag {points}`, `input.touch_sequence {events}` — gesture coordinates are screen points; `input.pointer {x, y, seq?, buttons?}`, `input.scroll {phase, dx?, dy?, x?, y?}` (capabilities `pointer_scroll` and `pointer_buttons`, see below) || UI | `ui.tree` (alias `accessibility.tree`), `ui.element_at`, `ui.tap_element`, `ui.wait`, `ui.wait_gone`, `ui.ocr {languages?, min_confidence?}`, `ui.describe`, `screen.screenshot` || Processes | `processes.list {filter?}`, `processes.kill {pid, signal?}` **force**, `memory.jetsam`, `memory.pressure` (only the three kernel memory sysctls, for polling) || launchd | `services.list`, `status`, `print`, `dump`, `disabled`, `start`, `enable`, `load`, `profile` (see below), `kickstart {label, kill?}` (`launchctl kickstart`, capability `service_kickstart`, see below); `services.stop`, `disable`, `remove`, `signal`, `unload`, `profile.apply {profile, groups?, allow?}` **force**, and `kickstart` with `kill` **force**; `launchd.getenv`, `setenv`, `unsetenv`. On tvOS, which never enables user sessions, they read the system domain alone; before icli 0.8.6 the foreground-user lookup trapped there and killed vphoned |@@ -394,6 +394,15 @@ request carries `"force": true`.| Profile UDID | `udid.get`, `udid.set {udid}`, `udid.clear` — each returns `{udid, path}`, the UDID the guest gives its profile checks and the host (null: the guest's own) and the settings file it came from; `set` and `clear` also return `restarted_pids`, `usb_serial` and `usb_reenumerated` (see below) || Setup Assistant | `setup.status` (`{pending, running, pid, setup_done, setup_version, current_version, data_migration_done}`), `setup.skip` **force** (sets `SetupDone`, `SetupFinishedAllSteps` and `SetupVersion` in `com.apple.purplebuddy`, restarts SpringBoard, returns the status plus `respring`; while the first boot's data migration is still running it does not restart SpringBoard, which reads the keys when migration ends, and `respring` is `{restarted: false, reason: "data_migration_pending"}`; a restart FrontBoard ignored is refused with `reason: busy`, `retryable: true`, the keys already written); `setup.settle {timeout_s?, poll_s?, stable_polls?}` (read-only wait for first-boot work, see below); `/v1/health` carries `setup_pending` — see `Research/Guest/setup_assistant_skip.md` |+`input.hid` sends a keyboard/consumer usage with 16-bit `page` and `usage`.+Omitting `down` sends a 100 ms press; a Boolean `down` sends one transition.+Optional Boolean `long_press: true` requires an explicit Boolean `down` and+sets `KeyboardLongPress` on that transition. Send it on both the hold-down+and hold-up events; it does not wait for or detect a hold. The HomePod top cap+uses consumer page 12, usage 205 for Center, with ordinary down/up for taps+and long-press transitions for holds. Older vphoned builds lack this flag;+update the guest environment before testing center holds.+`display.rotation` also reads `accelerometer`: its persisted `degrees`,`provider_running`, and the backboardd HID provider's status (enumeration,service ID, pid, report interval, dispatch/failure counts and last error).diff --git a/VPhoneDaemon/Daemon/GuestAPI.swift b/VPhoneDaemon/Daemon/GuestAPI.swiftindex d663c289..bf7d85ee 100644--- a/VPhoneDaemon/Daemon/GuestAPI.swift+++ b/VPhoneDaemon/Daemon/GuestAPI.swift@@ -371,6 +371,20 @@ enum GuestAPI {case "input.hid":let page = try integer(params, "page")let usage = try integer(params, "usage")+ if let value = params["long_press"] {+ guard let flag = value as? NSNumber, CFGetTypeID(flag) == CFBooleanGetTypeID() else {+ throw GuestAPIError.invalidRequest("long_press must be a boolean")+ }+ if flag.boolValue {+ guard (0...65535).contains(page), (0...65535).contains(usage),+ let down = params["down"] as? NSNumber, CFGetTypeID(down) == CFBooleanGetTypeID()+ else { throw GuestAPIError.invalidRequest("long_press requires a boolean down and 16-bit page and usage") }+ guard vp_hid_keyboard_hold(UInt16(page), UInt16(usage), down.boolValue) else {+ throw GuestAPIError.operationFailed("HID long-press injection is unavailable")+ }+ return ["page": page, "usage": usage, "action": down.boolValue ? "down" : "up", "long_press": true]+ }+ }if let down = params["down"] as? Bool {return try hidEvent(page: page, usage: usage, down: down)}diff --git a/VPhoneDaemon/Native/Include/VphonedNative.h b/VPhoneDaemon/Native/Include/VphonedNative.hindex 3ff65b10..c3bdd62f 100644--- a/VPhoneDaemon/Native/Include/VphonedNative.h+++ b/VPhoneDaemon/Native/Include/VphonedNative.h@@ -30,6 +30,8 @@ char *vp_homepod_debug_copy_json(const char *operation, const char *arguments_js/// safe to call more than once; returns false (injection then stays a no-op)/// on bases that do not expose the private symbols.bool vp_hid_load(void);+/// A keyboard/consumer hold transition, including KeyboardLongPress on release.+bool vp_hid_keyboard_hold(uint16_t page, uint16_t usage, bool down);/// Inject one two-finger digitizer event, the shape a trackpad pinch needs./// Phase is 0 = down, 1 = move, 3 = up; coordinates are normalized 0..1 withdiff --git a/VPhoneDaemon/Native/vphoned_touch.m b/VPhoneDaemon/Native/vphoned_touch.mindex ffc20ff7..d8dbbe1b 100644--- a/VPhoneDaemon/Native/vphoned_touch.m+++ b/VPhoneDaemon/Native/vphoned_touch.m@@ -35,6 +35,7 @@ static IOHIDEventRef (*pFinger)(CFAllocatorRef, uint64_t, uint32_t, uint32_t,IOHIDFloat, IOHIDFloat, boolean_t, boolean_t, uint32_t);static void (*pAppend)(IOHIDEventRef, IOHIDEventRef, uint32_t);static void (*pSetInt)(IOHIDEventRef, uint32_t, int);+static IOHIDEventRef (*pKeyboard)(CFAllocatorRef, uint64_t, uint32_t, uint32_t, boolean_t, uint32_t);static IOHIDEventSystemClientRef gTouchClient;static dispatch_queue_t gTouchQueue;@@ -74,6 +75,7 @@ bool vp_hid_load(void) {pFinger = dlsym(ioKit, "IOHIDEventCreateDigitizerFingerEvent");pAppend = dlsym(ioKit, "IOHIDEventAppendEvent");pSetInt = dlsym(ioKit, "IOHIDEventSetIntegerValue");+ pKeyboard = dlsym(ioKit, "IOHIDEventCreateKeyboardEvent");if (!pCreate || !pSetSender || !pDispatch || !pDigitizer || !pFinger || !pAppend || !pSetInt) {NSLog(@"vphoned: digitizer symbols missing, touch injection disabled");@@ -92,6 +94,21 @@ bool vp_hid_load(void) {return true;}+bool vp_hid_keyboard_hold(uint16_t page, uint16_t usage, bool down) {+ if (!vp_hid_load() || !pKeyboard) return false;+ IOHIDEventRef event = pKeyboard(kCFAllocatorDefault, mach_absolute_time(), page, usage, down, 0);+ if (!event) return false;+ // The same built-in marker and sender as IcliKit's ordinary key events.+ pSetInt(event, 4, 1);+ // kIOHIDEventFieldKeyboardLongPress. SBHPIOHID reads this field for Center.+ pSetInt(event, (3u << 16) | 5u, 1);+ pSetSender(event, 0x8000000817319372);+ // Input RPCs are ordered; finish dispatch before acknowledging the hold.+ dispatch_sync(gTouchQueue, ^{ pDispatch(gTouchClient, event); });+ CFRelease(event);+ return true;+}+// One hand event carrying `count` fingers, dispatched as a single gesture.static void dispatch_digitizer_points(const double *xs, const double *ys,int count, boolean_t range, boolean_t touch,diff --git a/VPhoneDaemon/Tests/HomePodHIDTests.m b/VPhoneDaemon/Tests/HomePodHIDTests.mnew file mode 100644index 00000000..8949e143--- /dev/null+++ b/VPhoneDaemon/Tests/HomePodHIDTests.m@@ -0,0 +1,53 @@+#import <Foundation/Foundation.h>+#include <assert.h>+#include "../Native/vphoned_touch.m"++static bool expectedDown;+static unsigned fields;+static unsigned dispatched;++static IOHIDEventRef keyboard(CFAllocatorRef allocator, uint64_t timestamp,+ uint32_t page, uint32_t usage, boolean_t down, uint32_t options) {+ (void)allocator;+ assert(timestamp && page == 0x0C && usage == 0xCD && down == expectedDown && options == 0);+ return (void *)CFDictionaryCreateMutable(NULL, 0, NULL, NULL);+}++static void setInt(IOHIDEventRef event, uint32_t field, int value) {+ assert(event && value == 1);+ if (field == 4) fields |= 1;+ else if (field == 0x30005) fields |= 2;+ else assert(false);+}++static void setSender(IOHIDEventRef event, uint64_t sender) {+ assert(event && sender == 0x8000000817319372ULL && fields == 3);+ fields |= 4;+}++static void dispatch(IOHIDEventSystemClientRef client, IOHIDEventRef event) {+ assert(client == gTouchClient && event && fields == 7);+ dispatched++;+}++int main(void) {+ @autoreleasepool {+ // Use the real encoder/dispatch function with captured IOKit calls.+ gTouchClient = (void *)1;+ gTouchQueue = dispatch_queue_create("homepod-hid-tests", DISPATCH_QUEUE_SERIAL);+ pKeyboard = keyboard;+ pSetInt = setInt;+ pSetSender = setSender;+ pDispatch = dispatch;+ for (unsigned index = 0; index < 2; index++) {+ fields = 0;+ expectedDown = index == 0;+ assert(vp_hid_keyboard_hold(0x0C, 0xCD, expectedDown));+ assert(dispatched == index + 1); // Dispatch precedes the RPC reply.+ }+ pKeyboard = NULL;+ assert(!vp_hid_keyboard_hold(0x0C, 0xCD, true));+ assert(dispatched == 2);+ puts("HomePod HID long-press encoding, paired release and unavailable-symbol tests passed");+ }+}diff --git a/VPhoneDaemon/Tests/run-homepod-hid-tests.sh b/VPhoneDaemon/Tests/run-homepod-hid-tests.shnew file mode 100755index 00000000..4b9be58f--- /dev/null+++ b/VPhoneDaemon/Tests/run-homepod-hid-tests.sh@@ -0,0 +1,9 @@+#!/bin/zsh+set -euo pipefail+tests="${0:a:h}"+temporary="$(mktemp -d "${TMPDIR:-/tmp}/vphone-homepod-hid.XXXXXX")"+trap 'rm -rf "$temporary"' EXIT+xcrun --sdk macosx clang -fobjc-arc -fmodules -Wall -Wextra -Werror -Wno-nullability-completeness \+ -fmodules-cache-path="$temporary/modules" -framework Foundation \+ "$tests/HomePodHIDTests.m" -o "$temporary/homepod-hid-tests"+"$temporary/homepod-hid-tests"diff --git a/VPhoneExecutable/VPhoneVirtualization/Tests/HomePodInputTests.swift b/VPhoneExecutable/VPhoneVirtualization/Tests/HomePodInputTests.swiftnew file mode 100644index 00000000..e779ecd8--- /dev/null+++ b/VPhoneExecutable/VPhoneVirtualization/Tests/HomePodInputTests.swift@@ -0,0 +1,65 @@+import AppKit++/// Exercise the actual AppKit hit areas and their emitted transitions.+@main+struct HomePodInputTests {+ @MainActor+ static func main() async throws {+ _ = NSApplication.shared+ let cap = VPhoneHomePodDisplayView(frame: NSRect(x: 0, y: 0, width: 480, height: 480))+ cap.layoutSubtreeIfNeeded()+ let buttons = cap.subviews.compactMap { $0 as? NSButton }+ let center = try require(buttons.first { $0.accessibilityLabel() == "HomePod touch surface" })+ let plus = try require(buttons.first { $0.accessibilityLabel() == "Increase volume" })+ let minus = try require(buttons.first { $0.accessibilityLabel() == "Decrease volume" })+ precondition(!center.isHidden && center.isAccessibilityElement())+ precondition(plus.nextKeyView === center && center.nextKeyView === minus)+ var events: [VPhoneHomePodDisplayView.ControlEvent] = []+ cap.onControlChange = { events.append($0) }++ // AX and rapid repeated taps retain distinct, immediate down/up pairs.+ for _ in 0..<3 { precondition(center.accessibilityPerformPress()) }+ precondition(events.count == 6)+ for (index, event) in events.enumerated() {+ precondition(event.control.usage == 0xCD && event.down == (index % 2 == 0))+ precondition(event.minimumHold == .zero && !event.longPress)+ }+ events.removeAll()+ precondition(plus.accessibilityPerformPress() && minus.accessibilityPerformPress())+ precondition(events.map { $0.control.usage } == [0xE9, 0xE9, 0xEA, 0xEA])+ precondition(events[1].minimumHold == .milliseconds(700) && events[3].minimumHold == .milliseconds(700))++ let down = try require(NSEvent.mouseEvent(with: .leftMouseDown, location: .zero, modifierFlags: [],+ timestamp: 0, windowNumber: 0, context: nil,+ eventNumber: 1, clickCount: 1, pressure: 1))+ let up = try require(NSEvent.mouseEvent(with: .leftMouseUp, location: .zero, modifierFlags: [],+ timestamp: 0, windowNumber: 0, context: nil,+ eventNumber: 2, clickCount: 1, pressure: 0))+ events.removeAll()+ center.mouseDown(with: down)+ center.mouseDown(with: down) // Repeats do not create extra presses/timers.+ try await Task.sleep(for: .milliseconds(650))+ center.mouseUp(with: up)+ precondition(events.count == 3)+ precondition(events.map(\.down) == [true, true, false])+ precondition(events.map(\.longPress) == [false, true, true])++ // Closing, focus loss and disconnect use the same release path. A+ // cancelled timer must not fire into a subsequent short press.+ events.removeAll()+ center.mouseDown(with: down)+ cap.releaseControls()+ center.mouseDown(with: down)+ center.mouseUp(with: up)+ try await Task.sleep(for: .milliseconds(650))+ precondition(events.count == 4 && events.allSatisfy { !$0.longPress })+ cap.releaseControls()+ precondition(events.count == 4)+ print("HomePod top-cap tap, multi-tap, hold, release and volume tests passed")+ }++ static func require<T>(_ value: T?) throws -> T {+ guard let value else { throw NSError(domain: "HomePodInputTests", code: 1) }+ return value+ }+}diff --git a/VPhoneExecutable/VPhoneVirtualization/Tests/run-homepod-input-tests.sh b/VPhoneExecutable/VPhoneVirtualization/Tests/run-homepod-input-tests.shnew file mode 100755index 00000000..38ce519d--- /dev/null+++ b/VPhoneExecutable/VPhoneVirtualization/Tests/run-homepod-input-tests.sh@@ -0,0 +1,23 @@+#!/bin/zsh+set -euo pipefail++tests="${0:a:h}"+repo="${tests:h:h:h}"+temporary="$(/usr/bin/mktemp -d "${TMPDIR:-/tmp}/vphone-homepod-input.XXXXXX")"+trap '/bin/rm -rf "$temporary"' EXIT++/usr/bin/xcrun --sdk macosx swiftc -swift-version 6 -strict-concurrency=complete \+ -module-cache-path "$temporary/ModuleCache" -emit-library -emit-module \+ -module-name VPhoneCoreKit -emit-module-path "$temporary/VPhoneCoreKit.swiftmodule" \+ "$repo/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneHomePodDisplay.swift" \+ -Xlinker -install_name -Xlinker '@rpath/libVPhoneCoreKit.dylib' \+ -o "$temporary/libVPhoneCoreKit.dylib"+/usr/bin/xcrun --sdk macosx swiftc -swift-version 6 -strict-concurrency=complete \+ -module-cache-path "$temporary/ModuleCache" -I "$temporary" -L "$temporary" -lVPhoneCoreKit \+ -Xlinker -rpath -Xlinker "$temporary" \+ "$tests/HomePodInputTests.swift" \+ "$tests:h/UI/UserInterface/HomePod/VPhoneHomePodDisplayView.swift" \+ "$tests:h/UI/UserInterface/HomePod/VPhoneHomePodMetalRenderer.swift" \+ "$tests:h/UI/UserInterface/HomePod/VPhoneHomePodShader.swift" \+ -o "$temporary/HomePodInputTests"+"$temporary/HomePodInputTests"diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swiftindex 17ae062a..80b94a33 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/GuestCommunication/VPhoneGuestControl.swift@@ -298,21 +298,22 @@ final class VPhoneGuestControl {sendHID(page: page, usage: usage, down: nil)}- func sendHIDDown(page: UInt32, usage: UInt32) {- sendHID(page: page, usage: usage, down: true)+ func sendHIDDown(page: UInt32, usage: UInt32, longPress: Bool = false) {+ sendHID(page: page, usage: usage, down: true, longPress: longPress)}- func sendHIDUp(page: UInt32, usage: UInt32, minimumHold: Duration = .zero) {- sendHID(page: page, usage: usage, down: false, minimumHold: minimumHold)+ func sendHIDUp(page: UInt32, usage: UInt32, minimumHold: Duration = .zero, longPress: Bool = false) {+ sendHID(page: page, usage: usage, down: false, minimumHold: minimumHold, longPress: longPress)}@ObservationIgnored private var heldHIDKeys: [UInt64: ContinuousClock.Instant] = [:]- private func sendHID(page: UInt32, usage: UInt32, down: Bool?, minimumHold: Duration = .zero) {+ private func sendHID(page: UInt32, usage: UInt32, down: Bool?, minimumHold: Duration = .zero, longPress: Bool = false) {var params: [String: Any] = ["page": page, "usage": usage]if let down {params["down"] = down}+ if longPress { params["long_press"] = true }let key = UInt64(page) << 32 | UInt64(usage)let previous = orderedInputorderedInput = Task {diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/HomePod/VPhoneHomePodDisplayView.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/HomePod/VPhoneHomePodDisplayView.swiftindex 90da7327..fe43d2c8 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/HomePod/VPhoneHomePodDisplayView.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/HomePod/VPhoneHomePodDisplayView.swift@@ -13,18 +13,26 @@ final class VPhoneHomePodDisplayView: NSView {case volumeDowncase volumeUpcase surface- }- /// Paired transitions preserve a physical hold until pointer/key release.- var onControlChange: ((Control, Bool, Duration) -> Void)?- /// Enabled only when the caller has an evidenced guest touch mapping.- var surfaceControlEnabled = false {- didSet {- surface.isHidden = !surfaceControlEnabled- surface.setAccessibilityElement(surfaceControlEnabled)- plus.nextKeyView = surfaceControlEnabled ? surface : minus+ /// SoundBoard's SBHPIOHID maps consumer Play/Pause to Center.+ var usage: UInt32 {+ switch self {+ case .volumeDown: 0xEA+ case .volumeUp: 0xE9+ case .surface: 0xCD+ }}}++ struct ControlEvent {+ let control: Control+ let down: Bool+ var minimumHold: Duration = .zero+ var longPress = false+ }++ /// Paired transitions preserve a physical hold until pointer/key release.+ var onControlChange: ((ControlEvent) -> Void)?private(set) var geometry: VPhoneHomePodDisplayGeometry?private(set) var displayFrame: VPhoneHomePodDisplayFrame?@@ -38,16 +46,14 @@ final class VPhoneHomePodDisplayView: NSView {setAccessibilityElement(false)addSubview(canvas)for button in [surface, minus, plus] {- button.onChange = { [weak self] control, down, minimumHold in- self?.onControlChange?(control, down, minimumHold)+ button.onChange = { [weak self] event in+ self?.onControlChange?(event)}addSubview(button)}surface.nextKeyView = minusminus.nextKeyView = plus- plus.nextKeyView = minus- surface.isHidden = true- surface.setAccessibilityElement(false)+ plus.nextKeyView = surfaceif let error = canvas.renderingError {let label = NSTextField(wrappingLabelWithString: "HomePod display unavailable: \(error)")label.translatesAutoresizingMaskIntoConstraints = false@@ -126,8 +132,10 @@ final class VPhoneHomePodDisplayView: NSView {@MainActorprivate final class VPhoneHomePodCapControl: NSButton {let control: VPhoneHomePodDisplayView.Control- var onChange: ((VPhoneHomePodDisplayView.Control, Bool, Duration) -> Void)?+ var onChange: ((VPhoneHomePodDisplayView.ControlEvent) -> Void)?private var isPressed = false+ private var longPress = false+ private var holdTask: Task<Void, Never>?init(control: VPhoneHomePodDisplayView.Control, label: String) {self.control = control@@ -194,21 +202,35 @@ private final class VPhoneHomePodCapControl: NSButton {}private func finishPress() {- // Give even instantaneous mouse/AX taps a usable consumer-key hold.- // The queue measures this from the guest's key-down acknowledgement.- releaseControl(minimumHold: .milliseconds(700))+ // Volume still needs a usable consumer-key hold. Center releases must+ // stay immediate so SoundBoard can coalesce double and triple taps.+ releaseControl(minimumHold: control == .surface ? .zero : .milliseconds(700))}private func pressControl() {guard !isPressed else { return }isPressed = true- onChange?(control, true, .zero)+ longPress = false+ onChange?(.init(control: control, down: true))+ if control == .surface {+ holdTask = Task { [weak self] in+ do { try await Task.sleep(for: .milliseconds(500)) }+ catch { return }+ guard let self, isPressed else { return }+ longPress = true+ // SoundBoard requires KeyboardLongPress, not repeated taps.+ onChange?(.init(control: control, down: true, longPress: true))+ }+ }}func releaseControl(minimumHold: Duration = .zero) {guard isPressed else { return }isPressed = false- onChange?(control, false, minimumHold)+ holdTask?.cancel()+ holdTask = nil+ onChange?(.init(control: control, down: false, minimumHold: minimumHold, longPress: longPress))+ longPress = false}// Visual markings belong to the optical shader; these views supply nativediff --git a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swiftindex cbba6626..469e3b42 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/UserInterface/VPhoneVirtualMachineWindowController.swift@@ -65,19 +65,13 @@ class VPhoneVirtualMachineWindowController: NSObject, NSWindowDelegate {let container: NSViewif homePodGuest {let cap = VPhoneHomePodDisplayView()- cap.onControlChange = { [weak self] button, down, minimumHold in+ cap.onControlChange = { [weak self] event inguard let control = self?.control else { return }- let usage: UInt32- switch button {- case .volumeUp: usage = 0xE9- case .volumeDown: usage = 0xEA- case .surface: return- }- if down {+ if event.down {guard control.isConnected else { return }- control.sendHIDDown(page: 0x0C, usage: usage)+ control.sendHIDDown(page: 0x0C, usage: event.control.usage, longPress: event.longPress)} else {- control.sendHIDUp(page: 0x0C, usage: usage, minimumHold: minimumHold)+ control.sendHIDUp(page: 0x0C, usage: event.control.usage, minimumHold: event.minimumHold, longPress: event.longPress)}}// Keep the diagnostic framebuffer attached for host automation,