|
38 | 38 | typedef IndigoHIDMessage *(*DFIndigoHIDMessageForKeyboardNSEventFn)(NSEvent *event); |
39 | 39 | typedef IndigoHIDMessage *(*DFIndigoHIDMessageForButtonFn)(uint32_t buttonCode, uint32_t operation, uint32_t target); |
40 | 40 | typedef IndigoHIDMessage *(*DFIndigoHIDMessageForHIDArbitraryFn)(uint32_t target, uint32_t page, uint32_t usage, uint32_t operation); |
| 41 | +typedef IndigoHIDMessage *(*DFIndigoHIDMessageForScrollEventFn)(uint32_t target, double deltaX, double deltaY, double momentumPhase); |
41 | 42 | typedef IndigoHIDMessage *(*DFIndigoHIDServiceMessageFn)(void); |
42 | 43 |
|
43 | 44 | #pragma pack(push, 4) |
@@ -1431,6 +1432,29 @@ static void DFWarmIndigoHIDServices(id hidClient) { |
1431 | 1432 | return message; |
1432 | 1433 | } |
1433 | 1434 |
|
| 1435 | +static IndigoHIDMessage *DFCreateScrollHIDMessage(uint32_t target, double deltaX, double deltaY, NSError **error) { |
| 1436 | + DFIndigoHIDMessageForScrollEventFn scrollMessage = (DFIndigoHIDMessageForScrollEventFn)dlsym(RTLD_DEFAULT, "IndigoHIDMessageForScrollEvent"); |
| 1437 | + if (scrollMessage == NULL) { |
| 1438 | + if (error != NULL) { |
| 1439 | + *error = DFMakeError( |
| 1440 | + DFPrivateSimulatorErrorCodeTouchDispatchFailed, |
| 1441 | + @"SimulatorKit did not expose IndigoHIDMessageForScrollEvent." |
| 1442 | + ); |
| 1443 | + } |
| 1444 | + return NULL; |
| 1445 | + } |
| 1446 | + |
| 1447 | + IndigoHIDMessage *message = scrollMessage(target, deltaX, deltaY, 0); |
| 1448 | + if (message == NULL && error != NULL) { |
| 1449 | + *error = DFMakeError( |
| 1450 | + DFPrivateSimulatorErrorCodeTouchDispatchFailed, |
| 1451 | + [NSString stringWithFormat:@"SimulatorKit could not construct scroll HID for delta %.3f.", deltaY] |
| 1452 | + ); |
| 1453 | + } |
| 1454 | + |
| 1455 | + return message; |
| 1456 | +} |
| 1457 | + |
1434 | 1458 | static BOOL DFCallSwiftUnitAngleMeasurementGetterByFunction(id selfObject, void *function, DFUnitAngleMeasurement *measurement) { |
1435 | 1459 | if (selfObject == nil || function == NULL || measurement == NULL) { |
1436 | 1460 | return NO; |
@@ -3497,6 +3521,57 @@ - (BOOL)sendHardwareButtonNamed:(NSString *)buttonName |
3497 | 3521 | return success; |
3498 | 3522 | } |
3499 | 3523 |
|
| 3524 | +- (BOOL)rotateDigitalCrownByDelta:(double)delta |
| 3525 | + error:(NSError * _Nullable __autoreleasing *)error { |
| 3526 | + if (!isfinite(delta)) { |
| 3527 | + if (error != NULL) { |
| 3528 | + *error = DFMakeError( |
| 3529 | + DFPrivateSimulatorErrorCodeTouchDispatchFailed, |
| 3530 | + @"Digital Crown delta must be finite." |
| 3531 | + ); |
| 3532 | + } |
| 3533 | + return NO; |
| 3534 | + } |
| 3535 | + |
| 3536 | + __block BOOL success = NO; |
| 3537 | + __block NSError *dispatchError = nil; |
| 3538 | + |
| 3539 | + dispatch_block_t work = ^{ |
| 3540 | + if (self->_hidClient == nil) { |
| 3541 | + dispatchError = DFMakeError( |
| 3542 | + DFPrivateSimulatorErrorCodeTouchDispatchFailed, |
| 3543 | + @"SimulatorKit did not provide a headless HID client for Digital Crown rotation." |
| 3544 | + ); |
| 3545 | + return; |
| 3546 | + } |
| 3547 | + |
| 3548 | + NSError *messageError = nil; |
| 3549 | + IndigoHIDMessage *message = DFCreateScrollHIDMessage(DFIndigoTouchTarget, 0, delta, &messageError); |
| 3550 | + if (message == NULL || !DFSendHIDMessage(self->_hidClient, message, YES, &messageError)) { |
| 3551 | + dispatchError = messageError; |
| 3552 | + return; |
| 3553 | + } |
| 3554 | + |
| 3555 | + DFLog(@"Sending Digital Crown rotation delta=%.3f", delta); |
| 3556 | + success = YES; |
| 3557 | + }; |
| 3558 | + |
| 3559 | + if (dispatch_get_specific(DFPrivateSimulatorCallbackQueueKey) != NULL) { |
| 3560 | + work(); |
| 3561 | + } else { |
| 3562 | + dispatch_sync(_callbackQueue, work); |
| 3563 | + } |
| 3564 | + |
| 3565 | + if (!success && error != NULL) { |
| 3566 | + *error = dispatchError ?: DFMakeError( |
| 3567 | + DFPrivateSimulatorErrorCodeTouchDispatchFailed, |
| 3568 | + @"SimulatorKit rejected Digital Crown rotation." |
| 3569 | + ); |
| 3570 | + } |
| 3571 | + |
| 3572 | + return success; |
| 3573 | +} |
| 3574 | + |
3500 | 3575 | - (BOOL)rotateRight:(NSError * _Nullable __autoreleasing *)error { |
3501 | 3576 | return [self rotateByDegrees:90.0 error:error]; |
3502 | 3577 | } |
|
0 commit comments