Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Native Touch Passthrough and Better Gesture Recognizing #628

Conversation

TrueZhuangJia
Copy link

@TrueZhuangJia TrueZhuangJia commented May 17, 2024

Hello everyone,

I've been waiting for a true native-touch oriented version of moonlight-iOS for so long, that I have to fork it myself. Here's the changes made in my fork:

  1. The native touch passthrough coded following the logic of moonlight-android.

    One of the key challenge is, iOS does not offer a pointerId attribute for UITouch object like android.
    I use a dictionary & a set for mapping UITouch object memory address to pointerId, which was generated from arc4random(), with a mechanism to prevent collision.
    Related codes are placed in NativeTouchHandler.m . Here's how native touch works out now:
    331657445-46af86e8-ef69-4923-a36b-0a7b54856b22



  2. Refactored Better Session Exit Gesture Recognition to Prevent Accidental Exits.

    I suggest, if we implement native multi-touch on moonlight-iOS, preventing unexpected session exit is a must-have feature.
    Unlike the official moonlight which serves as a streaming client for mainly game controller players, native touch player like me needs to perform intense touch operation on screen, which triggers the original exit gesture recognition unexpectedly, it's so frustrating if you suddenly exit the remote desktop during gameplay.
    So I wrote a recognizer to replace the iOS native API, requiring a swipe from the screen edge to a certain distance to trigger the exit to the desktop. The trigger threshold for the swipe distance and which edge to start the swipe from have been added to the settings menu. For user who prefers the original way, just set distance to 0.

    image
    And this is how it works:
    longSwipeToExit
    Related codes are placed in CustomEdgeSwipeGestureRecognizer.m, this custom defined recognizer is added to StreamFrameViewController.



  3. Refactored Better Tap Gesture Recognition for Reliable Local Keyboard Toggle.

    I read a comment from the maintainer that conflict between 3-finger keyboard toggling & android gesture is one of the reasons why native-touch is not enabled on official moonlight-android yet. My answer to that question is adding configurable finger number for the user to decide.
    On iOS however, there're additional issues if you wanna implement the same multi-finger tap keyboard toggle:
    The official version of Moonlight-iOS triggers the local keyboard switch when it detects three touch points on the screen, a mechanism that makes three-point dragging interrupted by the showing up of keyboard.
    I also tried UITapGestureRecognizer provided by iOS native API: the success rate of gesture recognition would decrease, and even continuous failures could occur.
    Therefore, I rewrote a TapGestureRecognizer with a recognition rate of almost 100% , and having no affect on multi-point dragging(keyboard invoked on all-fingers-up, with a down time threshold limitation, similar to moonlight-Android)
    To prevent local keyboard from being invoked unexpectedly, I add the required number of fingers for tap recognizer to the setting menu like my android fork. It is recommended to set 3-finger triggering on phones and 4 or more on tablets (as your palm might touch the screen, forming a third touch point when using a tablet).
    image
    Here's a *.gif example of setting "Fingers to Tap" to 4 on my ipad mini6:
    testt5
    Related codes are placed in CustomTapGestureRecognizer.m, this custom defined recognizer is added to StreamView.




My ipad mini6 is on iOS 17.2, I missed the trollstore and there's no jailbreak yet. Please consider reviewing or even merging my implementation into the official version, Sideloading app on iOS and the 7 day refresh is just, painful.

Thank you for your attention~

ZWM and others added 30 commits February 17, 2024 21:31
…y exiting from remote desktop session in multi-touch mode.
Merge branch 'Moonlight-iOS-Official9.0.2' into Moonlight-iOS-ZWM2

* Moonlight-iOS-Official9.0.2: (29 commits)
  Update README.md
  Update README.md
  Update README.md
  Update README.md
  Update README.md
  Update README.md
  Update README.md
  Update README.md
  Update README.md
  Version 9.0.2
  Update moonlight-common-c to resolve build warning
  Improve smooth scrolling precision
  mapped the Globe/Language key to Escape
  yes 0x0D is the correct code for Enter according to Microsoft's documentation
  Update moonlight-common-c with RTSP encryption and QoS improvements
  Remove xcpretty in CI
  Update AppVeyor images
  Remove CPU core count check
  Update moonlight-common-c with finalized encryption changes
  Opt in for video encryption on A10 and later SoCs
  ...

# Conflicts:
#	Limelight/Input/StreamView.m
#	Moonlight-ZWM.xcodeproj/project.pbxproj
… user swipe with a horizontal distance that exceeds half screen width, this works better in native-touch passthrough.

Original ios-moonlight triggers session disconnection with a short swipe from left edge, which happens frequently & unexpectedly in an intense native-touch passthrough gaming condition (like GenshinImpact).
TrueZhuangJia and others added 29 commits May 13, 2024 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant