Skip to content

Commit 6e0ca05

Browse files
committed
fix: restore iOS digitizer touch and edge gestures
1 parent ffd9cbf commit 6e0ca05

1 file changed

Lines changed: 54 additions & 44 deletions

File tree

cli/DFPrivateSimulatorDisplayBridge.m

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ static id DFCreateLegacyHIDClientForDevice(id device, NSError **error) {
13721372
NSSize displaySize,
13731373
BOOL touchDown,
13741374
uint32_t target,
1375+
IndigoHIDEdge edge,
13751376
NSError **error) {
13761377
DFIndigoHIDMessageForMouseNSEventFn mouseMessage = (DFIndigoHIDMessageForMouseNSEventFn)dlsym(RTLD_DEFAULT, "IndigoHIDMessageForMouseNSEvent");
13771378
if (mouseMessage == NULL) {
@@ -1390,7 +1391,7 @@ static id DFCreateLegacyHIDClientForDevice(id device, NSError **error) {
13901391
fmax(0.0, fmin(1.0, normalizedPoint.y))
13911392
);
13921393

1393-
DFIndigoMessage *baseMessage = (DFIndigoMessage *)mouseMessage(&ratioPoint, NULL, target, eventType, displaySize, 0);
1394+
DFIndigoMessage *baseMessage = (DFIndigoMessage *)mouseMessage(&ratioPoint, NULL, target, eventType, displaySize, edge);
13941395
if (baseMessage == NULL) {
13951396
if (error != NULL) {
13961397
*error = DFMakeError(
@@ -3894,26 +3895,26 @@ - (BOOL)sendTouchAtNormalizedX:(double)normalizedX
38943895
return;
38953896
}
38963897

3897-
IndigoHIDMessage *message = DFCreateIndigoTouchMessageDirect(CGPointMake(clampedX, clampedY),
3898-
displaySize,
3899-
phase,
3900-
target,
3901-
DFIndigoHIDEdgeNone);
3902-
BOOL freeWhenDone = YES;
3898+
BOOL touchDown = phase == DFPrivateSimulatorTouchPhaseBegan || phase == DFPrivateSimulatorTouchPhaseMoved;
3899+
IndigoHIDMessage *message = (IndigoHIDMessage *)DFCreateIndigoTouchMessage(CGPointMake(clampedX, clampedY),
3900+
displaySize,
3901+
touchDown,
3902+
target,
3903+
DFIndigoHIDEdgeNone,
3904+
&dispatchError);
39033905
if (message == NULL) {
3904-
BOOL touchDown = phase == DFPrivateSimulatorTouchPhaseBegan || phase == DFPrivateSimulatorTouchPhaseMoved;
3905-
message = (IndigoHIDMessage *)DFCreateIndigoTouchMessage(CGPointMake(clampedX, clampedY),
3906-
displaySize,
3907-
touchDown,
3908-
target,
3909-
&dispatchError);
3906+
message = DFCreateIndigoTouchMessageDirect(CGPointMake(clampedX, clampedY),
3907+
displaySize,
3908+
phase,
3909+
target,
3910+
DFIndigoHIDEdgeNone);
39103911
if (message == NULL) {
39113912
return;
39123913
}
39133914
}
39143915

39153916
NSError *messageError = nil;
3916-
if (!DFSendHIDMessage(hidClient, message, freeWhenDone, &messageError)) {
3917+
if (!DFSendHIDMessage(hidClient, message, YES, &messageError)) {
39173918
dispatchError = messageError ?: DFMakeError(
39183919
DFPrivateSimulatorErrorCodeTouchDispatchFailed,
39193920
@"SimulatorKit rejected the Indigo HID touch packet."
@@ -3989,17 +3990,27 @@ - (BOOL)sendEdgeTouchAtNormalizedX:(double)normalizedX
39893990
);
39903991

39913992
uint32_t target = DFIndigoDigitizerTarget;
3992-
IndigoHIDMessage *message = DFCreateIndigoEdgeTouchMessageOnMain(CGPointMake(clampedX, clampedY),
3993-
displaySize,
3994-
phase,
3995-
edge,
3996-
target);
3993+
IndigoHIDEdge hidEdge = DFIndigoHIDEdgeForPrivateTouchEdge(edge);
3994+
BOOL touchDown = phase == DFPrivateSimulatorTouchPhaseBegan || phase == DFPrivateSimulatorTouchPhaseMoved;
3995+
IndigoHIDMessage *message = (IndigoHIDMessage *)DFCreateIndigoTouchMessage(CGPointMake(clampedX, clampedY),
3996+
displaySize,
3997+
touchDown,
3998+
target,
3999+
hidEdge,
4000+
&dispatchError);
39974001
if (message == NULL) {
3998-
dispatchError = DFMakeError(
3999-
DFPrivateSimulatorErrorCodeTouchDispatchFailed,
4000-
@"SimulatorKit failed to create an edge-aware Indigo HID touch packet."
4001-
);
4002-
return;
4002+
message = DFCreateIndigoEdgeTouchMessageOnMain(CGPointMake(clampedX, clampedY),
4003+
displaySize,
4004+
phase,
4005+
edge,
4006+
target);
4007+
if (message == NULL) {
4008+
dispatchError = DFMakeError(
4009+
DFPrivateSimulatorErrorCodeTouchDispatchFailed,
4010+
@"SimulatorKit failed to create an edge-aware Indigo HID touch packet."
4011+
);
4012+
return;
4013+
}
40034014
}
40044015

40054016
NSError *messageError = nil;
@@ -4084,28 +4095,27 @@ - (BOOL)sendMultiTouchAtNormalizedX1:(double)normalizedX1
40844095
break;
40854096
}
40864097

4087-
IndigoHIDMessage *message = NULL;
40884098
uint32_t target = DFIndigoDigitizerTarget;
4089-
const NSUInteger maxAttempts = phase == DFPrivateSimulatorTouchPhaseMoved ? 12 : 3;
4090-
for (NSUInteger attempt = 0; attempt < maxAttempts; attempt++) {
4091-
message = DFCreateIndigoMultiTouchMessageDirect(CGPointMake(x1, y1),
4092-
CGPointMake(x2, y2),
4093-
displaySize,
4094-
phase,
4095-
target);
4096-
if (message != NULL) {
4097-
break;
4098-
}
4099-
usleep(5 * 1000);
4100-
}
4099+
BOOL touchDown = phase == DFPrivateSimulatorTouchPhaseBegan || phase == DFPrivateSimulatorTouchPhaseMoved;
4100+
IndigoHIDMessage *message = (IndigoHIDMessage *)DFCreateIndigoMultiTouchMessage(CGPointMake(x1, y1),
4101+
CGPointMake(x2, y2),
4102+
displaySize,
4103+
touchDown,
4104+
target,
4105+
&dispatchError);
41014106
if (message == NULL) {
4102-
BOOL touchDown = phase == DFPrivateSimulatorTouchPhaseBegan || phase == DFPrivateSimulatorTouchPhaseMoved;
4103-
message = (IndigoHIDMessage *)DFCreateIndigoMultiTouchMessage(CGPointMake(x1, y1),
4104-
CGPointMake(x2, y2),
4105-
displaySize,
4106-
touchDown,
4107-
target,
4108-
&dispatchError);
4107+
const NSUInteger maxAttempts = phase == DFPrivateSimulatorTouchPhaseMoved ? 12 : 3;
4108+
for (NSUInteger attempt = 0; attempt < maxAttempts; attempt++) {
4109+
message = DFCreateIndigoMultiTouchMessageDirect(CGPointMake(x1, y1),
4110+
CGPointMake(x2, y2),
4111+
displaySize,
4112+
phase,
4113+
target);
4114+
if (message != NULL) {
4115+
break;
4116+
}
4117+
usleep(5 * 1000);
4118+
}
41094119
if (message == NULL) {
41104120
return;
41114121
}

0 commit comments

Comments
 (0)