Skip to content

Commit d65dca6

Browse files
committed
feat(ios): replace Device Hub folding with simulator HID
1 parent fde74ac commit d65dca6

22 files changed

Lines changed: 216 additions & 779 deletions

File tree

‎apple/fold-helper/Fold.m‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#import <Foundation/Foundation.h>
2+
#import <mach/mach_time.h>
3+
4+
// Private simulator HID entry points; the host verifies the resulting hinge independently.
5+
extern CFDataRef IOCFSerialize(CFTypeRef object, CFOptionFlags options);
6+
extern CFTypeRef IOHIDEventCreateVendorDefinedEvent(CFAllocatorRef allocator, uint64_t timestamp,
7+
uint32_t usagePage, uint32_t usage, uint32_t version, const uint8_t *data,
8+
CFIndex length, uint32_t options);
9+
extern CFTypeRef IOHIDEventSystemClientCreate(CFAllocatorRef allocator);
10+
extern void IOHIDEventSystemClientDispatchEvent(CFTypeRef client, CFTypeRef event);
11+
12+
int main(int argc, const char *argv[]) {
13+
@autoreleasepool {
14+
if (argc != 2) return 2;
15+
NSDictionary *angles = @{@"closed": @0, @"half-open": @130, @"open": @180};
16+
NSNumber *angle = angles[@(argv[1])];
17+
if (!angle) {
18+
fprintf(stderr, "Expected closed, half-open, or open\n");
19+
return 2;
20+
}
21+
NSDictionary *payload = @{
22+
@"provider": @"com.apple.Virtualization.VirtualMachines",
23+
@"source": @"hinge-slider-control",
24+
@"type": @"range",
25+
@"value": angle,
26+
};
27+
CFDataRef data = IOCFSerialize((__bridge CFTypeRef)payload, 1);
28+
if (!data) {
29+
fprintf(stderr, "Unable to serialize simulator hinge payload\n");
30+
return 1;
31+
}
32+
CFTypeRef client = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
33+
CFTypeRef event = IOHIDEventCreateVendorDefinedEvent(kCFAllocatorDefault,
34+
mach_absolute_time(), 0xff61, 0x5b, 0, CFDataGetBytePtr(data), CFDataGetLength(data), 0);
35+
if (client && event) IOHIDEventSystemClientDispatchEvent(client, event);
36+
BOOL dispatched = client && event;
37+
if (event) CFRelease(event);
38+
if (client) CFRelease(client);
39+
CFRelease(data);
40+
if (!dispatched) fprintf(stderr, "Unable to create simulator HID client or event\n");
41+
return dispatched ? 0 : 1;
42+
}
43+
}

‎apple/macos-helper/Package.swift‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,13 @@ let package = Package(
1414
.target(
1515
name: "AgentDeviceMacOSInput"
1616
),
17-
.target(
18-
name: "AgentDeviceMacOSDeviceHub"
19-
),
2017
.executableTarget(
2118
name: "AgentDeviceMacOSHelper",
22-
dependencies: ["AgentDeviceMacOSInput", "AgentDeviceMacOSDeviceHub"]
19+
dependencies: ["AgentDeviceMacOSInput"]
2320
),
2421
.testTarget(
2522
name: "AgentDeviceMacOSInputTests",
2623
dependencies: ["AgentDeviceMacOSInput"]
2724
),
28-
.testTarget(
29-
name: "AgentDeviceMacOSDeviceHubTests",
30-
dependencies: ["AgentDeviceMacOSDeviceHub"]
31-
),
3225
]
3326
)

‎apple/macos-helper/Sources/AgentDeviceMacOSDeviceHub/DeviceHubPose.swift‎

Lines changed: 0 additions & 47 deletions
This file was deleted.

‎apple/macos-helper/Sources/AgentDeviceMacOSDeviceHub/DeviceHubWindowInventory.swift‎

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)