From 8e5c9b58e23592b099a957c116928eae8fe58e96 Mon Sep 17 00:00:00 2001 From: ZWM <> Date: Sat, 13 Apr 2024 15:09:46 +0800 Subject: [PATCH] Resolving bug caused by 64 bit touch event pointer converted to uint32_t touch pointer ID --- Limelight/Input/StreamView.h | 2 +- Limelight/Input/StreamView.m | 18 ++++++++++++++++-- moonlight-common/moonlight-common-c | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Limelight/Input/StreamView.h b/Limelight/Input/StreamView.h index 9f500101..febf32b0 100644 --- a/Limelight/Input/StreamView.h +++ b/Limelight/Input/StreamView.h @@ -11,11 +11,11 @@ #import "Moonlight-Swift.h" #import "StreamConfiguration.h" + @protocol UserInteractionDelegate - (void) userInteractionBegan; - (void) userInteractionEnded; - @end #if TARGET_OS_TV diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index 82e3dc61..c5eb6ec6 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -14,6 +14,7 @@ #import "RelativeTouchHandler.h" #import "AbsoluteTouchHandler.h" #import "KeyboardInputField.h" +#import "zlib.h" //to implement crc32 checksum static const double X1_MOUSE_SPEED_DIVISOR = 2.5; @@ -239,6 +240,16 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; return 90 - MIN(90, altitudeDegs); } +// convert 64bit pointer to CRC32 checksum +- (uint32_t)crc32OfUint64:(uint64_t)value { + // uint64_t可以被视为字符数组来计算CRC32 + char data[sizeof(value)]; + memcpy(data, &value, sizeof(value)); + uint32_t crc = crc32(0, Z_NULL, 0); + crc = crc32(crc, (const Bytef *)data, sizeof(value)); + return crc; +} + - (void)trySendTouchEvent:(UITouch*)event index:(int)index{ uint8_t type; NSLog(@"trySendTouchEvent %ld,%d",(long)event.phase,(uint32_t)event); @@ -299,13 +310,16 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; // default: // return; // } - + uint32_t pointerId = [self crc32OfUint64:((uint64_t)event)]; // convert pointer event(64bit) to CRC32 checksum as touch pointer ID. + // There's no pointerId like Android in definition of iOS touch event "UITouch", we use pointer to UITouch to generate touch pointer ID. + // Since touch pointer ID is defined to be uint32_t, I implement CRC32 checksum to the 64bit address, which avoids touch pointer ID repetition. CGPoint location = [self adjustCoordinatesForVideoArea:[event locationInView:self]]; CGSize videoSize = [self getVideoAreaSize]; - LiSendTouchEvent(type,(uint32_t)event,location.x / videoSize.width, location.y / videoSize.height,(event.force / event.maximumPossibleForce) / sin(event.altitudeAngle),0.0f, 0.0f,[self getRotationFromAzimuthAngle:[event azimuthAngleInView:self]]); + LiSendTouchEvent(type,pointerId,location.x / videoSize.width, location.y / videoSize.height,(event.force / event.maximumPossibleForce) / sin(event.altitudeAngle),0.0f, 0.0f,[self getRotationFromAzimuthAngle:[event azimuthAngleInView:self]]); } + - (void)sendStylusEvent:(UITouch*)event { uint8_t type; diff --git a/moonlight-common/moonlight-common-c b/moonlight-common/moonlight-common-c index 4f983ff5..ec171fd7 160000 --- a/moonlight-common/moonlight-common-c +++ b/moonlight-common/moonlight-common-c @@ -1 +1 @@ -Subproject commit 4f983ff5849dfa63ce8a0d8de2f69f94f8bfd56a +Subproject commit ec171fd7cab4cb8b7eb6416f1ad9ad62e339efb2