Author SHA1 Message Date
TrueZhuanJia 8cb38a7897 Revise contributors section in README.md
Updated contributor section to reflect main contributors and added links to full contributor lists in both Chinese and English.
2025-12-30 14:53:39 +08:00
TrueZhuanJia f285fd2d23 Update README.md 2025-12-30 14:48:46 +08:00
TrueZhuanJia 23103340f9 Update README.md 2025-11-21 08:45:45 +08:00
TrueZhuanJia e5fd48cf3d Update README.md 2025-11-20 15:04:27 +08:00
TrueZhuanJia 6df81095d0 Update README.md 2025-11-20 14:57:02 +08:00
TrueZhuanJia 261b8294a0 Update README.md 2025-10-25 20:55:37 +08:00
TrueZhuanJia 8a66aadb40 Update README.md 2025-09-15 21:45:13 +08:00
TrueZhuanJia ba9c2e5fab Update README.md 2025-08-07 10:57:05 +08:00
TrueZhuanJia 073f7f848c Update README.md 2025-08-07 10:48:26 +08:00
TrueZhuanJia 82f1c82ee4 Update README.md 2025-08-01 20:50:04 +08:00
TrueZhuanJia 6a3640b8be Update README.md 2025-08-01 20:41:37 +08:00
TrueZhuanJia 3e2e477fe8 Update README.md 2025-07-16 14:01:08 +08:00
TrueZhuanJia b66c372192 Update README.md 2025-06-26 16:14:34 +08:00
TrueZhuanJia 12f0bad824 Update README.md 2025-06-04 11:20:04 +08:00
TrueZhuanJia 79c3c21ae0 Update README.md 2025-05-29 17:22:22 +08:00
TrueZhuanJia 39c5d58564 Update README.md 2025-05-29 17:21:42 +08:00
TrueZhuanJia d8c58b45f0 Update README.md 2025-03-31 08:26:38 +08:00
TrueZhuanJia 4727139e0e Update README.md 2025-03-25 11:53:31 +08:00
TrueZhuanJia b461145fe4 Update README.md 2025-03-18 15:46:08 +08:00
TrueZhuanJia 5a82b0f480 Update README.md 2025-03-18 15:41:00 +08:00
TrueZhuanJia 3d028d792f Update README.md 2025-03-18 15:39:46 +08:00
TrueZhuanJia 66c8e3a9d3 Update README.md 2025-02-04 10:49:34 +08:00
TrueZhuanJia 51e9269865 Update README.md 2025-02-04 10:45:16 +08:00
TrueZhuanJia bc02f20762 Update README.md 2025-01-20 12:46:42 +08:00
TrueZhuanJia e26d1b20b5 Update README.md 2024-11-18 21:39:52 +08:00
TrueZhuanJia 6ae8cea6f3 Update README.md 2024-11-18 21:39:26 +08:00
TrueZhuanJia 41e94455f4 Update README.md 2024-10-25 08:51:23 +08:00
TrueZhuanJia d283ddf4ee Update README.md 2024-09-23 22:36:57 +08:00
True Zhuanjia 6a4c709dec Update README.md 2024-09-07 20:55:16 +08:00
True Zhuanjia 2c91ae2557 minor change 2024-06-01 13:35:51 +08:00
True Zhuanjia c629a1d5d5 minor change 2024-06-01 13:05:14 +08:00
True Zhuanjia 1e54c2d16f Logic improvement for native (absolute) touch 2024-05-31 20:49:05 +08:00
True Zhuanjia 42efa1f2c8 minor improvement 2024-05-31 19:23:36 +08:00
True Zhuanjia c9f4113534 fix pointerVelocityDivider bug 2024-05-30 23:24:26 +08:00
True Zhuanjia e3bf553566 fix pointerVelocityDivider bug 2024-05-30 23:20:04 +08:00
TrueZhuanJia e2478660f3 Update README.md 2024-05-30 21:00:54 +08:00
TrueZhuanJia 9106cad14a Update README.md 2024-05-30 20:43:40 +08:00
TrueZhuanJia 8a361cf927 Update README.md 2024-05-30 12:58:05 +08:00
True Zhuanjia 427873116b Add menu entries for pointer velocity tweak 2024-05-29 22:28:24 +08:00
True Zhuanjia 6c5cd094c3 PointerVelocity tweak core implementation 2024-05-29 00:54:42 +08:00
TrueZhuanJia 9b270b2e90 Update README.md 2024-05-28 17:51:49 +08:00
TrueZhuanJia b4bef088d4 Update README.md 2024-05-28 09:16:40 +08:00
True Zhuanjia e5fa7f9c72 fix view lift not working on first keyboard invoke. 2024-05-27 21:06:48 +08:00
True Zhuanjia 746479d359 fix view lift bug on iOS14 ipad mini5 2024-05-26 23:27:45 +08:00
TrueZhuanJia 7f6c14f92d Update README.md 2024-05-26 18:45:41 +08:00
TrueZhuanJia 1e0a244b49 Update README.md 2024-05-26 18:01:33 +08:00
TrueZhuanJia 5b9f29296e Update README.md 2024-05-26 17:48:10 +08:00
True Zhuanjia 2674267589 Update annotation 2024-05-26 15:35:15 +08:00
True Zhuanjia d64c746dab add menu entries for streamview lift & keyboard toolbar 2024-05-26 14:08:00 +08:00
True Zhuanjia d54205dec8 Implement view lifting for keyboard invoke. 2024-05-26 00:03:00 +08:00
TrueZhuanJia 6b48083ad9 Update README.md 2024-05-21 12:57:38 +08:00
TrueZhuanJia 7d9eb2aaa9 Update README.md 2024-05-18 09:54:14 +08:00
TrueZhuanJia d7aa2d00ba Update README.md 2024-05-18 00:04:38 +08:00
True Zhuanjia 743dad5f37 allow fingers to tap slider dragged to a position higher than 10, where equals the keyboard toggle is disabled 2024-05-17 23:10:07 +08:00
TrueZhuanJia 19dc6a68b3 Update README.md 2024-05-17 21:29:07 +08:00
True Zhuanjia 8d9e822bbe assign default values for new setting entries in menu 2024-05-17 12:52:06 +08:00
True Zhuanjia 5d7258a00a tweak iphone storyboard 2024-05-17 01:07:34 +08:00
True Zhuanjia 2b5601d154 Add menu entries in iphone storyboard. 2024-05-17 00:58:58 +08:00
True Zhuanjia a51d471f2d Add menu entry for swipe&exit screen edge, set for CustomEdgeSwipeRecognizer 2024-05-16 22:24:42 +08:00
True Zhuanjia 0f5ca5d8b0 Add menu entry for swipe&exit distance 2024-05-16 20:39:21 +08:00
True Zhuanjia f85b736c97 improve keyboard toggle by adding keyboard notification. minor UI string change 2024-05-16 17:44:18 +08:00
True Zhuanjia 72547b1b59 Fix [fingers to tap on keyboard] config not loading. 2024-05-16 01:59:32 +08:00
True Zhuanjia 4987298f79 Add menu entry for configurable fingers to tap on local keyboard 2024-05-15 22:04:07 +08:00
True Zhuanjia b1b0be886e Define CustomTapGestureRecognizer to reliably toggle local keyboard, better than UITapGestureRecognizer 2024-05-15 16:56:47 +08:00
True Zhuanjia 208688afe1 Refactor related codes to NativeTouchHandler 2024-05-15 11:35:51 +08:00
True Zhuanjia 82de44df54 Rewrite CustomEdgeSwipeGestureRecognizer to fix unexpected session disconnect, and for future configuration 2024-05-14 23:05:58 +08:00
True Zhuanjia 6207d77349 Re-enable keyboard toggle in native touch mode, with a gesture of 2 taps of 2 fingers. 2024-05-14 01:26:48 +08:00
TrueZhuanJia afc390bacf Update README.md 2024-05-13 21:47:42 +08:00
True Zhuanjia 4b2ae15efc bug fix 2024-05-13 01:35:37 +08:00
True Zhuanjia 0fda662370 Improved pointerId mechanism, 0 probability of repetition. 2024-05-12 21:48:57 +08:00
ZWM 4e59c3375e remove logs 2024-05-09 23:04:54 +08:00
ZWM 2e7ffc2c52 improve custom edge swipe recognizer on detecting start point. Swipe half screen from left edge to quit session now works on ipad mini5. 2024-05-09 23:00:19 +08:00
ZWM b98ccb2a30 update ignore 2024-05-01 01:11:13 +08:00
TrueZhuanJia 813a488844 Update README.md 2024-05-01 00:44:34 +08:00
TrueZhuanJia 4faa814ee1 Update README.md 2024-05-01 00:41:59 +08:00
TrueZhuanJia f80e56fa0f Update README.md 2024-05-01 00:16:20 +08:00
ZWM a43905d7f4 update Readme.md 2024-05-01 00:10:18 +08:00
ZWM 616238e847 Add a custom gesture recognizer to trigger session disconnection when 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).
2024-04-30 23:41:58 +08:00
ZWM fd8cc416ab Merged with 9.0.2 modification 2024-04-30 19:38:53 +08:00
ZWM 8dc445e744 TEMP
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
2024-04-30 18:23:11 +08:00
ZWM 218b203a0b Merge branch 'Moonlight-iOS-ZWM' of https://github.com/TrueZhuangJia/moonlight-ios into Moonlight-iOS-ZWM 2024-04-20 16:23:09 +08:00
ZWM 65e71909ed Update README.MD 2024-04-20 16:04:09 +08:00
TrueZhuanJia f08d7c7ac9 Update README.md 2024-04-19 19:46:03 +08:00
TrueZhuanJia b451b65251 Update README.md 2024-04-19 15:10:11 +08:00
TrueZhuanJia 9add83f2c8 Update README.md 2024-04-19 15:09:48 +08:00
TrueZhuanJia 023b013828 Update README.md 2024-04-19 15:05:07 +08:00
TrueZhuanJia 07af0e4457 Update README.md 2024-04-19 15:01:38 +08:00
TrueZhuanJia 164f5bff2e Update README.md 2024-04-19 14:59:06 +08:00
TrueZhuanJia 5e35318f07 Update README.md 2024-04-19 14:58:26 +08:00
TrueZhuangJia fe73054771 Update README.md 2024-04-13 19:34:24 +08:00
TrueZhuangJia a6adbfc8c6 Update README.md 2024-04-13 19:33:41 +08:00
TrueZhuangJia f997b35b1a Update README.md 2024-04-13 19:32:43 +08:00
TrueZhuangJia af37c253b1 Update README.md 2024-04-13 19:32:16 +08:00
TrueZhuangJia 600fc5885b Update README.md 2024-04-13 19:22:08 +08:00
TrueZhuangJia 8d751c0564 Update README.md 2024-04-13 19:21:42 +08:00
TrueZhuangJia 555726e417 Update README.md 2024-04-13 19:16:32 +08:00
TrueZhuangJia 1c90390262 Update README.md 2024-04-13 19:12:48 +08:00
TrueZhuangJia 98e6a28620 Update README.md 2024-04-13 19:10:31 +08:00
TrueZhuangJia d7e03e6464 Update README.md 2024-04-13 17:57:58 +08:00
ZWM a435b5bb45 remove unnecessary logs & annotations. 2024-04-13 16:53:10 +08:00
ZWM 8e5c9b58e2 Resolving bug caused by 64 bit touch event pointer converted to uint32_t touch pointer ID 2024-04-13 15:09:46 +08:00
ZWM 8d25d238b6 Remove "exitSwipeRecognizer" on none-tvOS Target, prevent accidentally exiting from remote desktop session in multi-touch mode. 2024-02-17 23:36:13 +08:00
ZWM 6a9150c447 Rename App to Moonlight-ZWM 2024-02-17 22:31:18 +08:00
ZWM 2316a9eb63 Rename Project 2024-02-17 21:39:11 +08:00
ZWM 2e403acf3e 9.0.0-AXX-MultiTouch 2024-02-17 21:31:43 +08:00
162 changed files with 3318 additions and 21658 deletions
-45
View File
@@ -1,45 +0,0 @@
name: Build IPAs
on:
push:
branches: [ "noWaterMark" ]
jobs:
build:
name: Build IPAs
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout submodules
run: "git submodule update --init --recursive"
- name: Build FullScreen Version
run: |
plutil -replace UIRequiresFullScreen -bool true Limelight/Limelight-Info.plist
xcodebuild -verbose -scheme Moonlight-ZWM -sdk iphoneos -configuration AppStoreDistribution archive -archivePath $PWD/build/MoonlightFullScreen.xcarchive CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED="NO" CODE_SIGN_ENTITLEMENTS="" CODE_SIGNING_ALLOWED="NO"
mkdir -p ./build/IPA_FullScreen && mkdir -p ./build/IPA_FullScreen/Payload
cp -r ./build/MoonlightFullScreen.xcarchive/Products/Applications/Moonlight-ZWM.app ./build/IPA_FullScreen/Payload/Moonlight-ZWM.app
cd ./build/IPA_FullScreen && zip -r ../../build/Moonlight-ZWM_FullScreen.ipa ./Payload/* && cd ../..
- name: Upload FullScreen IPA to Artifacts
uses: actions/upload-artifact@v4
with:
name: Moonlight-ZWM_FullScreen.ipa
path: build/Moonlight-ZWM_FullScreen.ipa
- name: Build StageManager Version
run: |
plutil -replace UIRequiresFullScreen -bool false Limelight/Limelight-Info.plist
xcodebuild -verbose -scheme Moonlight-ZWM -sdk iphoneos -configuration AppStoreDistribution archive -archivePath $PWD/build/MoonlightStageManager.xcarchive CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED="NO" CODE_SIGN_ENTITLEMENTS="" CODE_SIGNING_ALLOWED="NO"
mkdir -p ./build/IPA_StageManager && mkdir -p ./build/IPA_StageManager/Payload
cp -r ./build/MoonlightStageManager.xcarchive/Products/Applications/Moonlight-ZWM.app ./build/IPA_StageManager/Payload/Moonlight-ZWM.app
cd ./build/IPA_StageManager && zip -r ../../build/Moonlight-ZWM_StageManager.ipa ./Payload/* && cd ../..
- name: Upload StageManager IPA to Artifacts
uses: actions/upload-artifact@v4
with:
name: Moonlight-ZWM_StageManager.ipa
path: build/Moonlight-ZWM_StageManager.ipa
+7 -26
View File
@@ -7,8 +7,6 @@
//
#import "AppDelegate.h"
#import "MainFrameViewController.h"
#import "Moonlight-Swift.h"
@implementation AppDelegate
@@ -24,34 +22,17 @@ static NSString* DB_NAME = @"Moonlight_tvOS.bin";
static NSString* DB_NAME = @"Limelight_iOS.sqlite";
#endif
#if !TARGET_OS_TV
/*
// orietation limitatioin test
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
UIViewController *topController = window.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return [topController supportedInterfaceOrientations];
}
*/
/*
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
NSLog(@"orientation limit");
return UIInterfaceOrientationMaskLandscape;
}
*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for command tool customization after application launch (works only when user default is nil)
[CommandManager presetDefaultCommands];
#if !TARGET_OS_TV
UIApplicationShortcutItem* shortcut = [launchOptions valueForKey:UIApplicationLaunchOptionsShortcutItemKey];
if (shortcut != nil) {
_pcUuidToLoad = (NSString*)[shortcut.userInfo objectForKey:@"UUID"];
}
#endif
return YES;
}
#if !TARGET_OS_TV
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {
_pcUuidToLoad = (NSString*)[shortcutItem.userInfo objectForKey:@"UUID"];
_shortcutCompletionHandler = completionHandler;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-1
View File
@@ -9,7 +9,6 @@
#ifndef Limelight_mkcert_h
#define Limelight_mkcert_h
#include <sys/_types/_time_t.h>
#include <openssl/x509v3.h>
#include <openssl/pkcs12.h>
+6 -19
View File
@@ -19,16 +19,11 @@
width:(NSInteger)width
audioConfig:(NSInteger)audioConfig
onscreenControls:(NSInteger)onscreenControls
keyboardToggleFingers:(NSInteger)keyboardToggleFingers
oscLayoutToolFingers:(NSInteger)oscLayoutToolFingers
slideToSettingsScreenEdge:(NSInteger)slideToSettingsScreenEdge
slideToSettingsDistance:(CGFloat)slideToSettingsDistance
keyboardToggleFingers:(NSInteger)keyboardToggleFingers
swipeExitScreenEdge:(NSInteger)swipeExitScreenEdge
swipeToExitDistance:(CGFloat)swipeToExitDistance
pointerVelocityModeDivider:(CGFloat)pointerVelocityModeDivider
touchPointerVelocityFactor:(CGFloat)touchPointerVelocityFactor
mousePointerVelocityFactor:(CGFloat)mousePointerVelocityFactor
oscTapExlusionAreaSize:(CGFloat)oscTapExlusionAreaSize
reverseMouseWheelDirection:(BOOL)reverseMouseWheelDirection
largerStickLR1:(BOOL)largerStickLR1
liftStreamViewForKeyboard:(BOOL)liftStreamViewForKeyboard
showKeyboardToolbar:(BOOL)showKeyboardToolbar
optimizeGames:(BOOL)optimizeGames
@@ -36,26 +31,18 @@
swapABXYButtons:(BOOL)swapABXYButtons
audioOnPC:(BOOL)audioOnPC
preferredCodec:(uint32_t)preferredCodec
enableYUV444:(BOOL)enableYUV444
useFramePacing:(BOOL)useFramePacing
enableHdr:(BOOL)enableHdr
btMouseSupport:(BOOL)btMouseSupport
// absoluteTouchMode:(BOOL)absoluteTouchMode
touchMode:(NSInteger)touchMode
statsOverlayLevel:(NSInteger)statsOverlayLevel
statsOverlayEnabled:(BOOL)statsOverlayEnabled
unlockDisplayOrientation:(BOOL)unlockDisplayOrientation
resolutionSelected:(NSInteger)resolutionSelected
externalDisplayMode:(NSInteger)externalDisplayMode
localMousePointerMode:(NSInteger)localMousePointerMode;
absoluteTouchMode:(BOOL)absoluteTouchMode
statsOverlay:(BOOL)statsOverlay;
- (NSArray*) getHosts;
- (void) updateHost:(TemporaryHost*)host;
- (void) updateAppsForExistingHost:(TemporaryHost *)host;
- (void) removeHost:(TemporaryHost*)host;
- (void) removeApp:(TemporaryApp*)app;
- (Settings*) retrieveSettings;
- (void) saveData;
- (TemporarySettings*) getSettings;
- (void) updateUniqueId:(NSString*)uniqueId;
+9 -32
View File
@@ -59,15 +59,10 @@
audioConfig:(NSInteger)audioConfig
onscreenControls:(NSInteger)onscreenControls
keyboardToggleFingers:(NSInteger)keyboardToggleFingers
oscLayoutToolFingers:(NSInteger)oscLayoutToolFingers
slideToSettingsScreenEdge:(NSInteger)slideToSettingsScreenEdge
slideToSettingsDistance:(CGFloat)slideToSettingsDistance
swipeExitScreenEdge:(NSInteger)swipeExitScreenEdge
swipeToExitDistance:(CGFloat)swipeToExitDistance
pointerVelocityModeDivider:(CGFloat)pointerVelocityModeDivider
touchPointerVelocityFactor:(CGFloat)touchPointerVelocityFactor
mousePointerVelocityFactor:(CGFloat)mousePointerVelocityFactor
oscTapExlusionAreaSize:(CGFloat)oscTapExlusionAreaSize
reverseMouseWheelDirection:(BOOL)reverseMouseWheelDirection
largerStickLR1:(BOOL)largerStickLR1
liftStreamViewForKeyboard:(BOOL)liftStreamViewForKeyboard
showKeyboardToolbar:(BOOL)showKeyboardToolbar
optimizeGames:(BOOL)optimizeGames
@@ -75,18 +70,11 @@
swapABXYButtons:(BOOL)swapABXYButtons
audioOnPC:(BOOL)audioOnPC
preferredCodec:(uint32_t)preferredCodec
enableYUV444:(BOOL)enableYUV444
useFramePacing:(BOOL)useFramePacing
enableHdr:(BOOL)enableHdr
btMouseSupport:(BOOL)btMouseSupport
// absoluteTouchMode:(BOOL)absoluteTouchMode
touchMode:(NSInteger)touchMode
statsOverlayLevel:(NSInteger)statsOverlayLevel
statsOverlayEnabled:(BOOL)statsOverlayEnabled
unlockDisplayOrientation:(BOOL)unlockDisplayOrientation
resolutionSelected:(NSInteger)resolutionSelected
externalDisplayMode:(NSInteger)externalDisplayMode
localMousePointerMode:(NSInteger)localMousePointerMode {
absoluteTouchMode:(BOOL)absoluteTouchMode
statsOverlay:(BOOL)statsOverlay {
[_managedObjectContext performBlockAndWait:^{
Settings* settingsToSave = [self retrieveSettings];
@@ -97,15 +85,10 @@
settingsToSave.audioConfig = [NSNumber numberWithInteger:audioConfig];
settingsToSave.onscreenControls = [NSNumber numberWithInteger:onscreenControls];
settingsToSave.keyboardToggleFingers = [NSNumber numberWithInteger:(uint16_t)keyboardToggleFingers];
settingsToSave.oscLayoutToolFingers = [NSNumber numberWithInteger:(uint16_t)oscLayoutToolFingers];
settingsToSave.slideToSettingsScreenEdge = [NSNumber numberWithInteger:(uint32_t)slideToSettingsScreenEdge];
settingsToSave.slideToSettingsDistance = [NSNumber numberWithFloat:slideToSettingsDistance];
settingsToSave.swipeExitScreenEdge = [NSNumber numberWithInteger:(uint32_t)swipeExitScreenEdge];
settingsToSave.swipeToExitDistance = [NSNumber numberWithFloat:swipeToExitDistance];
settingsToSave.pointerVelocityModeDivider = [NSNumber numberWithFloat:pointerVelocityModeDivider];
settingsToSave.touchPointerVelocityFactor = [NSNumber numberWithFloat:touchPointerVelocityFactor];
settingsToSave.mousePointerVelocityFactor = [NSNumber numberWithFloat:mousePointerVelocityFactor];
settingsToSave.oscTapExlusionAreaSize = [NSNumber numberWithFloat:oscTapExlusionAreaSize];
settingsToSave.reverseMouseWheelDirection = reverseMouseWheelDirection;
settingsToSave.largerStickLR1 = largerStickLR1;
settingsToSave.liftStreamViewForKeyboard = liftStreamViewForKeyboard;
settingsToSave.showKeyboardToolbar = showKeyboardToolbar;
settingsToSave.optimizeGames = optimizeGames;
@@ -113,18 +96,12 @@
settingsToSave.swapABXYButtons = swapABXYButtons;
settingsToSave.playAudioOnPC = audioOnPC;
settingsToSave.preferredCodec = preferredCodec;
settingsToSave.enableYUV444 = enableYUV444;
settingsToSave.useFramePacing = useFramePacing;
settingsToSave.enableHdr = enableHdr;
settingsToSave.btMouseSupport = btMouseSupport;
// settingsToSave.absoluteTouchMode = absoluteTouchMode;
settingsToSave.touchMode = [NSNumber numberWithInteger:(uint16_t)touchMode];
settingsToSave.statsOverlayEnabled = statsOverlayEnabled;
settingsToSave.statsOverlayLevel = [NSNumber numberWithInteger:(uint16_t)statsOverlayLevel];
settingsToSave.unlockDisplayOrientation = unlockDisplayOrientation;
settingsToSave.resolutionSelected = [NSNumber numberWithInteger:resolutionSelected];
settingsToSave.externalDisplayMode = [NSNumber numberWithInteger:externalDisplayMode];
settingsToSave.localMousePointerMode = [NSNumber numberWithInteger:localMousePointerMode];
settingsToSave.absoluteTouchMode = absoluteTouchMode;
settingsToSave.statsOverlay = statsOverlay;
[self saveData];
}];
}
+4 -4
View File
@@ -28,7 +28,7 @@
self.externalAddress = host.externalAddress;
self.localAddress = host.localAddress;
self.ipv6Address = host.ipv6Address;
if(!(host.mac == nil || [host.mac isEqualToString:@"00:00:00:00:00:00"])) self.mac = host.mac; // try to fix invalid mac happens in some cases
self.mac = host.mac;
self.name = host.name;
self.uuid = host.uuid;
self.serverCodecModeSupport = host.serverCodecModeSupport;
@@ -70,9 +70,9 @@
if (self.ipv6Address != nil) {
parentHost.ipv6Address = self.ipv6Address;
}
// try to fix invalid mac happens in some cases
// 添加主机crash问题重点关注
if (!(self.mac == nil || [self.mac isEqualToString:@"00:00:00:00:00:00"])) parentHost.mac = self.mac;
if (self.mac != nil) {
parentHost.mac = self.mac;
}
if (self.serverCert != nil) {
parentHost.serverCert = self.serverCert;
}
+5 -22
View File
@@ -7,12 +7,6 @@
//
#import "Settings+CoreDataClass.h"
#define RELATIVE_TOUCH 0
#define REGULAR_NATIVE_TOUCH 1
#define PURE_NATIVE_TOUCH 2
#define ABSOLUTE_TOUCH 3
#define OSC_TOOL_FINGERS 4
@interface TemporarySettings : NSObject
@@ -25,26 +19,17 @@
@property (nonatomic, retain) NSNumber * audioConfig;
@property (nonatomic, retain) NSNumber * onscreenControls;
@property (nonatomic, retain) NSNumber * keyboardToggleFingers;
@property (nonatomic, retain) NSNumber * oscLayoutToolFingers;
@property (nonatomic, retain) NSNumber * slideToSettingsScreenEdge;
@property (nonatomic, retain) NSNumber * slideToSettingsDistance;
@property (nonatomic, retain) NSNumber * oscTapExlusionAreaSize;
@property (nonatomic, retain) NSNumber * swipeExitScreenEdge;
@property (nonatomic, retain) NSNumber * swipeToExitDistance;
@property (nonatomic, retain) NSNumber * touchPointerVelocityFactor;
@property (nonatomic, retain) NSNumber * mousePointerVelocityFactor;
@property (nonatomic, retain) NSNumber * pointerVelocityModeDivider;
@property (nonatomic, retain) NSString * uniqueId;
@property (nonatomic, retain) NSNumber * resolutionSelected;
@property (nonatomic, retain) NSNumber * externalDisplayMode;
@property (nonatomic, retain) NSNumber * localMousePointerMode;
@property (nonatomic) enum {
CODEC_PREF_AUTO,
CODEC_PREF_H264,
CODEC_PREF_HEVC,
CODEC_PREF_AV1,
} preferredCodec;
@property (nonatomic) BOOL enableYUV444;
@property (nonatomic) BOOL reverseMouseWheelDirection;
@property (nonatomic) BOOL largerStickLR1;
@property (nonatomic) BOOL useFramePacing;
@property (nonatomic) BOOL multiController;
@property (nonatomic) BOOL swapABXYButtons;
@@ -52,13 +37,11 @@
@property (nonatomic) BOOL optimizeGames;
@property (nonatomic) BOOL enableHdr;
@property (nonatomic) BOOL btMouseSupport;
// @property (nonatomic) BOOL absoluteTouchMode;
@property (nonatomic, retain) NSNumber * touchMode;
@property (nonatomic, retain) NSNumber * statsOverlayLevel;
@property (nonatomic) BOOL statsOverlayEnabled;
@property (nonatomic) BOOL absoluteTouchMode;
@property (nonatomic) BOOL statsOverlay;
@property (nonatomic) BOOL liftStreamViewForKeyboard;
@property (nonatomic) BOOL showKeyboardToolbar;
@property (nonatomic) BOOL unlockDisplayOrientation;
- (id) initFromSettings:(Settings*)settings;
+4 -17
View File
@@ -37,7 +37,6 @@
self.audioConfig = [NSNumber numberWithInteger:[[NSUserDefaults standardUserDefaults] integerForKey:@"audioConfig"]];
assert([self.audioConfig intValue] != 0);
self.preferredCodec = (typeof(self.preferredCodec))[[NSUserDefaults standardUserDefaults] integerForKey:@"preferredCodec"];
self.enableYUV444 = [[NSUserDefaults standardUserDefaults] boolForKey:@"enableYUV444"];
self.useFramePacing = [[NSUserDefaults standardUserDefaults] integerForKey:@"useFramePacing"] != 0;
self.playAudioOnPC = [[NSUserDefaults standardUserDefaults] boolForKey:@"audioOnPC"];
self.enableHdr = [[NSUserDefaults standardUserDefaults] boolForKey:@"enableHdr"];
@@ -76,7 +75,6 @@
self.width = settings.width;
self.audioConfig = settings.audioConfig;
self.preferredCodec = settings.preferredCodec;
self.enableYUV444 = settings.enableYUV444;
self.useFramePacing = settings.useFramePacing;
self.playAudioOnPC = settings.playAudioOnPC;
self.enableHdr = settings.enableHdr;
@@ -84,27 +82,16 @@
self.multiController = settings.multiController;
self.swapABXYButtons = settings.swapABXYButtons;
self.onscreenControls = settings.onscreenControls;
self.reverseMouseWheelDirection = settings.reverseMouseWheelDirection;
self.largerStickLR1 = settings.largerStickLR1;
self.btMouseSupport = settings.btMouseSupport;
// self.absoluteTouchMode = settings.absoluteTouchMode;
self.touchMode = settings.touchMode;
self.statsOverlayLevel = settings.statsOverlayLevel;
self.statsOverlayEnabled = settings.statsOverlayEnabled;
self.absoluteTouchMode = settings.absoluteTouchMode;
self.statsOverlay = settings.statsOverlay;
self.keyboardToggleFingers = settings.keyboardToggleFingers;
self.oscLayoutToolFingers = settings.oscLayoutToolFingers;
self.slideToSettingsScreenEdge = settings.slideToSettingsScreenEdge;
self.slideToSettingsDistance = settings.slideToSettingsDistance;
self.swipeExitScreenEdge = settings.swipeExitScreenEdge;
self.swipeToExitDistance = settings.swipeToExitDistance;
self.liftStreamViewForKeyboard = settings.liftStreamViewForKeyboard;
self.showKeyboardToolbar = settings.showKeyboardToolbar;
self.oscTapExlusionAreaSize = settings.oscTapExlusionAreaSize;
self.touchPointerVelocityFactor = settings.touchPointerVelocityFactor;
self.mousePointerVelocityFactor = settings.mousePointerVelocityFactor;
self.pointerVelocityModeDivider = settings.pointerVelocityModeDivider;
self.unlockDisplayOrientation = settings.unlockDisplayOrientation;
self.resolutionSelected = settings.resolutionSelected;
self.externalDisplayMode = settings.externalDisplayMode;
self.localMousePointerMode = settings.localMousePointerMode;
#endif
self.uniqueId = settings.uniqueId;
@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "a_button_HD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

@@ -1,25 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "arrow_uturn_backward_square-80x80@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "arrow_uturn_backward_square-120x120@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

@@ -1,25 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "arrow_uturn_backward_square_fill-80x80@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "arrow_uturn_backward_square_fill-120x120.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "b_button_HD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

@@ -1,25 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "chevron_compact_down@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "chevron_compact_down@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 848 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

@@ -1,25 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "chevron_compact_up@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "chevron_compact_up@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 833 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "DownButtonHD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

-21
View File
@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "l1_button_HD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

-21
View File
@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "l2_button_HD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "LeftButtonHD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

@@ -1,22 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "OSCLayoutExit_80x80@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "OSCLayoutExit_120x120@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 831 B

-21
View File
@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "r1_button_HD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

-21
View File
@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "r2_button_HD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "RightButtonHD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "SelectButtonHD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

@@ -1,25 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "square_and_arrow_down-80x80@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "square_and_arrow_down-120x120@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

@@ -1,25 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "square_and_arrow_up_on_square-80x80@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "square_and_arrow_up_on_square-120x120@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 950 B

@@ -1,23 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "stick_inner_48x49@1x.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "stick_inner_96x97@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "stick_inner_144x146@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "StartButtonHD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "StickInnerHD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "StickOuterHD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

-25
View File
@@ -1,25 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "trash_square-80x80@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "trash_square-120x120@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

@@ -1,22 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "trash_square_fill-80x80@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "trash_square_fill-120x120@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "UpButtonHD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "x_button_HD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

@@ -1,21 +0,0 @@
{
"images" : [
{
"filename" : "y_button_HD.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

+82 -109
View File
@@ -23,127 +23,100 @@
#define DOUBLE_TAP_DEAD_ZONE_DELTA 0.025f
@implementation AbsoluteTouchHandler {
StreamView* streamView;
StreamView* view;
NSTimer* longPressTimer;
UITouch* lastTouchDown;
CGPoint lastTouchDownLocation;
UITouch* lastTouchUp;
CGPoint lastTouchUpLocation;
// upper screen edge check
bool touchPointSpawnedAtUpperScreenEdge;
CGFloat slideGestureVerticalThreshold;
CGFloat screenWidthWithThreshold;
CGFloat EDGE_TOLERANCE;
}
- (id)initWithView:(StreamView*)view {
self = [self init];
self->streamView = view;
// upper screen check
EDGE_TOLERANCE = 15.0;
slideGestureVerticalThreshold = CGRectGetHeight([[UIScreen mainScreen] bounds]) * 0.4;
screenWidthWithThreshold = CGRectGetWidth([[UIScreen mainScreen] bounds]) - EDGE_TOLERANCE;
self->touchPointSpawnedAtUpperScreenEdge = false;
self->view = view;
return self;
}
- (void)onLongPressStart:(NSTimer*)timer {
// Raise the left click and start a right click
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_RIGHT);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint initialPoint = [[touches anyObject] locationInView:streamView];
if(initialPoint.y < slideGestureVerticalThreshold && (initialPoint.x < EDGE_TOLERANCE || initialPoint.x > screenWidthWithThreshold)) {
self->touchPointSpawnedAtUpperScreenEdge = true;
return; // we're done here. this touch event will not be sent to the remote PC.
}
touchPointSpawnedAtUpperScreenEdge = false; // reset this flag immediately if we get a touch event passing the check above, this fixes irresponsive touch after closing the command tool menu.
// Ignore touch down events with more than one finger
if ([[event allTouches] count] > 1) {
return;
}
UITouch* touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:streamView];
// Don't reposition for finger down events within the deadzone. This makes double-clicking easier.
if (touch.timestamp - lastTouchUp.timestamp > DOUBLE_TAP_DEAD_ZONE_DELAY ||
sqrt(pow((touchLocation.x / streamView.bounds.size.width) - (lastTouchUpLocation.x / streamView.bounds.size.width), 2) +
pow((touchLocation.y / streamView.bounds.size.height) - (lastTouchUpLocation.y / streamView.bounds.size.height), 2)) > DOUBLE_TAP_DEAD_ZONE_DELTA) {
[streamView updateCursorLocation:touchLocation isMouse:NO];
}
// Press the left button down
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT);
// Start the long press timer
longPressTimer = [NSTimer scheduledTimerWithTimeInterval:LONG_PRESS_ACTIVATION_DELAY
target:self
selector:@selector(onLongPressStart:)
userInfo:nil
repeats:NO];
lastTouchDown = touch;
lastTouchDownLocation = touchLocation;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if(touchPointSpawnedAtUpperScreenEdge) return; // we're done here. this touch event will not be sent to the remote PC.
// Ignore touch move events with more than one finger
if ([[event allTouches] count] > 1) {
return;
}
UITouch* touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:streamView];
if (sqrt(pow((touchLocation.x / streamView.bounds.size.width) - (lastTouchDownLocation.x / streamView.bounds.size.width), 2) +
pow((touchLocation.y / streamView.bounds.size.height) - (lastTouchDownLocation.y / streamView.bounds.size.height), 2)) > LONG_PRESS_ACTIVATION_DELTA) {
// Moved too far since touch down. Cancel the long press timer.
[longPressTimer invalidate];
longPressTimer = nil;
}
[streamView updateCursorLocation:[[touches anyObject] locationInView:streamView] isMouse:NO];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if(touchPointSpawnedAtUpperScreenEdge) return; // we're done here. this touch event will not be sent to the remote PC.
// Only fire this logic if all touches have ended
if ([[event allTouches] count] == [touches count]) {
// Cancel the long press timer
[longPressTimer invalidate];
longPressTimer = nil;
// Left button up on finger up
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
// Raise right button too in case we triggered a long press gesture
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_RIGHT);
// Remember this last touch for touch-down deadzoning
lastTouchUp = [touches anyObject];
lastTouchUpLocation = [lastTouchUp locationInView:streamView];
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
// Treat this as a normal touchesEnded event
[self touchesEnded:touches withEvent:event];
}
//- (void)onLongPressStart:(NSTimer*)timer {
// // Raise the left click and start a right click
// LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
// LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_RIGHT);
//}
//
//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// // Ignore touch down events with more than one finger
// return;
// if ([[event allTouches] count] > 1) {
// return;
// }
//
// UITouch* touch = [touches anyObject];
// CGPoint touchLocation = [touch locationInView:view];
//
// // Don't reposition for finger down events within the deadzone. This makes double-clicking easier.
// if (touch.timestamp - lastTouchUp.timestamp > DOUBLE_TAP_DEAD_ZONE_DELAY ||
// sqrt(pow((touchLocation.x / view.bounds.size.width) - (lastTouchUpLocation.x / view.bounds.size.width), 2) +
// pow((touchLocation.y / view.bounds.size.height) - (lastTouchUpLocation.y / view.bounds.size.height), 2)) > DOUBLE_TAP_DEAD_ZONE_DELTA) {
// [view updateCursorLocation:touchLocation isMouse:NO];
// }
//
// // Press the left button down
// LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT);
//
// // Start the long press timer
// longPressTimer = [NSTimer scheduledTimerWithTimeInterval:LONG_PRESS_ACTIVATION_DELAY
// target:self
// selector:@selector(onLongPressStart:)
// userInfo:nil
// repeats:NO];
//
// lastTouchDown = touch;
// lastTouchDownLocation = touchLocation;
//}
//
//- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// // Ignore touch move events with more than one finger
// return;
// if ([[event allTouches] count] > 1) {
// return;
// }
//
// UITouch* touch = [touches anyObject];
// CGPoint touchLocation = [touch locationInView:view];
//
// if (sqrt(pow((touchLocation.x / view.bounds.size.width) - (lastTouchDownLocation.x / view.bounds.size.width), 2) +
// pow((touchLocation.y / view.bounds.size.height) - (lastTouchDownLocation.y / view.bounds.size.height), 2)) > LONG_PRESS_ACTIVATION_DELTA) {
// // Moved too far since touch down. Cancel the long press timer.
// [longPressTimer invalidate];
// longPressTimer = nil;
// }
//
// [view updateCursorLocation:[[touches anyObject] locationInView:view] isMouse:NO];
//}
//
//- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
// // Only fire this logic if all touches have ended
// if ([[event allTouches] count] == [touches count]) {
// // Cancel the long press timer
// [longPressTimer invalidate];
// longPressTimer = nil;
//
// // Left button up on finger up
// LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
//
// // Raise right button too in case we triggered a long press gesture
// LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_RIGHT);
//
// // Remember this last touch for touch-down deadzoning
// lastTouchUp = [touches anyObject];
// lastTouchUpLocation = [lastTouchUp locationInView:view];
// }
//}
//
//- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
// // Treat this as a normal touchesEnded event
// [self touchesEnded:touches withEvent:event];
//}
@end
-492
View File
@@ -1,492 +0,0 @@
//
// KeyManager.swift
// Moonlight-ZWM
//
// Created by ZWM on 2024/7/23.
// Copyright © 2024 Moonlight Game Streaming Project. All rights reserved.
//
import Foundation
import UIKit
// Define the RemoteCommand class
@objc public class RemoteCommand: NSObject, NSSecureCoding {
// MARK: - NSSecureCoding
public static var supportsSecureCoding: Bool {
return true
}
// MARK: - Properties
@objc var keyboardCmdString: String
@objc var alias: String
// MARK: - Initialization
init(keyboardCmdString: String, alias: String) {
self.keyboardCmdString = keyboardCmdString
self.alias = alias
}
// MARK: - NSSecureCoding
required public init?(coder: NSCoder) {
guard let keyboardCmdString = coder.decodeObject(of: NSString.self, forKey: "keyboardCmdString") as String?,
let alias = coder.decodeObject(of: NSString.self, forKey: "alias") as String? else {
return nil
}
self.keyboardCmdString = keyboardCmdString
self.alias = alias
}
public func encode(with coder: NSCoder) {
coder.encode(keyboardCmdString, forKey: "keyboardCmdString")
coder.encode(alias, forKey: "alias")
}
}
// Define the CommandManager class
@objc public class CommandManager: NSObject {
@objc public static let shared = CommandManager()
@objc public static let mouseButtonMappings: [String: Int32] = ["M_LEFT" : BUTTON_LEFT,
"M_MIDDLE" : BUTTON_MIDDLE,
"M_RIGHT" : BUTTON_RIGHT,
"M_X1" : BUTTON_X1,
"M_X2" : BUTTON_X2]
@objc public static let oscButtonMappings: [String: Int32] = ["OSCA" : A_FLAG,
"OSCB" : B_FLAG,
"OSCX" : X_FLAG,
"OSCY" : Y_FLAG,
"OSCL1" : LB_FLAG,
"OSCR1" : RB_FLAG,
"OSCL3" : LS_CLK_FLAG,
"OSCR3" : RS_CLK_FLAG,
"OSCSTART" : PLAY_FLAG,
"OSCSELECT" : BACK_FLAG,
"OSCUP" : UP_FLAG,
"OSCDOWN" : DOWN_FLAG,
"OSCLEFT" : LEFT_FLAG,
"OSCRIGHT" : RIGHT_FLAG,
"OSCL2" : 0,
"OSCR2" : 0]
@objc public static let oscRectangleButtonCmds: [String] = [
"OSCUP",
"OSCDOWN",
"OSCLEFT",
"OSCRIGHT",
"OSCSTART",
"OSCSELECT"]
@objc public static let touchPadCmds: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD", "MOUSEPAD", "DPAD", "WASDPAD", "ARROWPAD"]
@objc public static let stickTouchPads: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD"]
@objc public static let nonVectorStickPads: [String] = ["LSPAD", "RSPAD"]
@objc public static let specialOverlayButtonCmds: [String] = ["SETTINGS"]
static let keyboardButtonMappings: [String: Int16] = [
// Windows Key Codes
"CTRL": 0x11, // VK_CONTROL
"SHIFT": 0x10, // VK_SHIFT
"ALT": 0x12, // VK_MENU
"F1": 0x70, // VK_F1
"F2": 0x71, // VK_F2
"F3": 0x72, // VK_F3
"F4": 0x73, // VK_F4
"F5": 0x74, // VK_F5
"F6": 0x75, // VK_F6
"F7": 0x76, // VK_F7
"F8": 0x77, // VK_F8
"F9": 0x78, // VK_F9
"F10": 0x79, // VK_F10
"F11": 0x7A, // VK_F11
"F12": 0x7B, // VK_F12
"A": 0x41, // 'A' key
"B": 0x42, // 'B' key
"C": 0x43, // 'C' key
"D": 0x44, // 'D' key
"E": 0x45, // 'E' key
"F": 0x46, // 'F' key
"G": 0x47, // 'G' key
"H": 0x48, // 'H' key
"I": 0x49, // 'I' key
"J": 0x4A, // 'J' key
"K": 0x4B, // 'K' key
"L": 0x4C, // 'L' key
"M": 0x4D, // 'M' key
"N": 0x4E, // 'N' key
"O": 0x4F, // 'O' key
"P": 0x50, // 'P' key
"Q": 0x51, // 'Q' key
"R": 0x52, // 'R' key
"S": 0x53, // 'S' key
"T": 0x54, // 'T' key
"U": 0x55, // 'U' key
"V": 0x56, // 'V' key
"W": 0x57, // 'W' key
"X": 0x58, // 'X' key
"Y": 0x59, // 'Y' key
"Z": 0x5A, // 'Z' key
"0": 0x30, // '0' key
"1": 0x31, // '1' key
"2": 0x32, // '2' key
"3": 0x33, // '3' key
"4": 0x34, // '4' key
"5": 0x35, // '5' key
"6": 0x36, // '6' key
"7": 0x37, // '7' key
"8": 0x38, // '8' key
"9": 0x39, // '9' key
"ESC": 0x1B, // VK_ESCAPE
"SPACE": 0x20, // VK_SPACE
"ENTER": 0x0D, // VK_RETURN
"TAB": 0x09, // VK_TAB
"BACKSPACE": 0x08, // VK_BACK
"INSERT": 0x2D, // VK_INSERT
"DEL": 0x2E, // VK_DELETE
"HOME": 0x24, // VK_HOME
"END": 0x23, // VK_END
"PG_UP": 0x21, // VK_PRIOR
"PG_DOWN": 0x22, // VK_NEXT
"UP_ARROW": 0x26, // VK_UP
"DOWN_ARROW": 0x28, // VK_DOWN
"LEFT_ARROW": 0x25, // VK_LEFT
"RIGHT_ARROW": 0x27, // VK_RIGHT
"NUM_LCK": 0x90, // VK_NUMLOCK
"SCR_LCK": 0x91, // VK_SCROLL
"CAPS_LOCK": 0x14, // VK_CAPITAL
"PAUSE": 0x13, // VK_PAUSE
"PR_SCR": 0x2C, // VK_SNAPSHOT
"NUMPAD0": 0x60, // VK_NUMPAD0
"NUMPAD1": 0x61, // VK_NUMPAD1
"NUMPAD2": 0x62, // VK_NUMPAD2
"NUMPAD3": 0x63, // VK_NUMPAD3
"NUMPAD4": 0x64, // VK_NUMPAD4
"NUMPAD5": 0x65, // VK_NUMPAD5
"NUMPAD6": 0x66, // VK_NUMPAD6
"NUMPAD7": 0x67, // VK_NUMPAD7
"NUMPAD8": 0x68, // VK_NUMPAD8
"NUMPAD9": 0x69, // VK_NUMPAD9
"MULTIPLY": 0x6A, // VK_MULTIPLY
"ADD": 0x6B, // VK_ADD
"SUBTRACT": 0x6D, // VK_SUBTRACT
"DECIMAL": 0x6E, // VK_DECIMAL
"DIVIDE": 0x6F, // VK_DIVIDE
"SEMI_COLON": 0xBA, // VK_OEM_1
"EQUALS": 0xBB, // VK_OEM_PLUS
"COMMA": 0xBC, // VK_OEM_COMMA
"MINUS": 0xBD, // VK_OEM_MINUS
"PERIOD": 0xBE, // VK_OEM_PERIOD
"FORWARD_SLASH": 0xBF, // VK_OEM_2
"GRAVE_ACCENT": 0xC0, // VK_OEM_3
"OPEN_BRACKET": 0xDB, // VK_OEM_4
"BACKSLASH": 0xDC, // VK_OEM_5
"CLOSE_BRACKET": 0xDD, // VK_OEM_6
"SINGLE_QUOTE": 0xDE, // VK_OEM_7
"VOLUME_MUTE": 0xAD, // VK_VOLUME_MUTE
"VOLUME_DOWN": 0xAE, // VK_VOLUME_DOWN
"VOLUME_UP": 0xAF, // VK_VOLUME_UP
"MEDIA_NEXT": 0xB0, // VK_MEDIA_NEXT_TRACK
"MEDIA_PREV": 0xB1, // VK_MEDIA_PREV_TRACK
"MEDIA_STOP": 0xB2, // VK_MEDIA_STOP
"MEDIA_PLAY_PAUSE": 0xB3, // VK_MEDIA_PLAY_PAUSE
"LAUNCH_MAIL": 0xB4, // VK_LAUNCH_MAIL
"LAUNCH_MEDIA_SELECT": 0xB5, // VK_LAUNCH_MEDIA_SELECT
"LAUNCH_APP1": 0xB6, // VK_LAUNCH_APP1
"LAUNCH_APP2": 0xB7, // VK_LAUNCH_APP2
"WIN": 0x5B,
"LEFT_WIN": 0x5B, // VK_LWIN
"RIGHT_WIN": 0x5C, // VK_RWIN
"APPS": 0x5D, // VK_APPS
// macOS Key Codes
"CMD": 0x37, // ⌘ Command
"OPT": 0x3A, // ⌥ Option
"CONTROL": 0x3B, // ⌃ Control
"SHIFT_MAC": 0x38, // ⇧ Shift
"FUNCTION": 0x3F, // fn
"DELETE_MAC": 0x75, // Forward Delete
"RETURN_MAC": 0x24, // Return
"ENTER_MAC": 0x4C, // Enter
"ESCAPE_MAC": 0x35, // Escape
"TAB_MAC": 0x30, // Tab
"SPACE_MAC": 0x31, // Space
"UP_ARROW_MAC": 0x7E, // Up Arrow
"DOWN_ARROW_MAC": 0x7D, // Down Arrow
"LEFT_ARROW_MAC": 0x7B, // Left Arrow
"RIGHT_ARROW_MAC": 0x7C, // Right Arrow
"F1_MAC": 0x7A, // F1
"F2_MAC": 0x78, // F2
"F3_MAC": 0x63, // F3
"F4_MAC": 0x76, // F4
"F5_MAC": 0x60, // F5
"F6_MAC": 0x61, // F6
"F7_MAC": 0x62, // F7
"F8_MAC": 0x64, // F8
"F9_MAC": 0x65, // F9
"F10_MAC": 0x6D, // F10
"F11_MAC": 0x67, // F11
"F12_MAC": 0x6F, // F12
"0_MAC": 0x52, // 0
"1_MAC": 0x53, // 1
"2_MAC": 0x54, // 2
"3_MAC": 0x55, // 3
"4_MAC": 0x56, // 4
"5_MAC": 0x57, // 5
"6_MAC": 0x58, // 6
"7_MAC": 0x59, // 7
"8_MAC": 0x5A, // 8
"9_MAC": 0x5B, // 9
"NUMPAD0_MAC": 0x4F, // Numpad 0
"NUMPAD1_MAC": 0x50, // Numpad 1
"NUMPAD2_MAC": 0x51, // Numpad 2
"NUMPAD3_MAC": 0x52, // Numpad 3
"NUMPAD4_MAC": 0x53, // Numpad 4
"NUMPAD5_MAC": 0x54, // Numpad 5
"NUMPAD6_MAC": 0x55, // Numpad 6
"NUMPAD7_MAC": 0x56, // Numpad 7
"NUMPAD8_MAC": 0x57, // Numpad 8
"NUMPAD9_MAC": 0x58, // Numpad 9
"NUMPAD_ADD_MAC": 0x45, // Numpad Add
"NUMPAD_SUBTRACT_MAC": 0x4A, // Numpad Subtract
"NUMPAD_MULTIPLY_MAC": 0x43, // Numpad Multiply
"NUMPAD_DIVIDE_MAC": 0x4B, // Numpad Divide
"NUMPAD_DECIMAL_MAC": 0x41, // Numpad Decimal
]
private var commands: [RemoteCommand] = []
public weak var viewController: CommandManagerViewController?
private override init() {
super.init()
loadCommands()
}
@objc static func presetDefaultCommands() {
let defaults = UserDefaults.standard
//if true { // save default entries if the data is empty.
if defaults.data(forKey: "savedCommands") == nil { // save default entries if the data is empty.
let defaultCommands: [RemoteCommand] = [
RemoteCommand(keyboardCmdString: "WIN", alias: "WIN"),
RemoteCommand(keyboardCmdString: "F11", alias: "F11"),
RemoteCommand(keyboardCmdString: "ESC", alias: "ESC"),
RemoteCommand(keyboardCmdString: "CTRL+SHIFT+ESC", alias: "任务管理器(Task Manager)"),
RemoteCommand(keyboardCmdString: "ALT+F1", alias: "N卡截图(Nvidia Screenshot)"),
RemoteCommand(keyboardCmdString: "ALT+F9", alias: "N卡录屏(Nvidia Screen Recording)"),
RemoteCommand(keyboardCmdString: "ALT+F4", alias: "关闭窗口(ALT+F4)"),
RemoteCommand(keyboardCmdString: "CTRL+A", alias: "全选(Select All)"),
RemoteCommand(keyboardCmdString: "CTRL+C", alias: "复制(Copy)"),
RemoteCommand(keyboardCmdString: "CTRL+V", alias: "粘贴(Paste)"),
RemoteCommand(keyboardCmdString: "WIN+D", alias: "切换桌面(Switch to Desktop)"),
RemoteCommand(keyboardCmdString: "WIN+P", alias: "多显模式(Project)"),
RemoteCommand(keyboardCmdString: "WIN+G", alias: "Xbox Game Bar"),
RemoteCommand(keyboardCmdString: "SHIFT+TAB", alias: "Steam Overlay"),
]
let data = try? NSKeyedArchiver.archivedData(withRootObject: defaultCommands, requiringSecureCoding: false)
defaults.set(data, forKey: "savedCommands")
}
}
@objc public func createTestKeyMappings() -> [String: Int16] {
return CommandManager.keyboardButtonMappings
}
// extractKeyStrings from keyboardCMDString
@objc public func extractKeyStringsFromComboCommand(from input: String) -> [String]? {
let keys = CommandManager.keyboardButtonMappings.keys.joined(separator: "|")
let pattern = "^(?:(\(keys))(?:\\+(\(keys))*)*)$"
guard let regex = try? NSRegularExpression(pattern: pattern, options: []) else {
print("Failed to create regex")
return nil
}
let range = NSRange(location: 0, length: input.utf16.count)
guard let match = regex.firstMatch(in: input, options: [], range: range) else {
print("No match found for input: \(input)")
return nil
}
print("Regex matched for input: \(input)")
let matchedString = (input as NSString).substring(with: match.range(at: 0))
let keyStrings = matchedString.split(separator: "+").map { String($0) }
guard !keyStrings.isEmpty else {
print("No key strings found in the matched string")
return nil
}
var validKeyStrings: [String] = []
for key in keyStrings {
if CommandManager.keyboardButtonMappings.keys.contains(key) {
validKeyStrings.append(key)
} else {
print(" '\(key)' is not defined in key mappings")
return nil //treat any illegal string as a whole
}
}
if validKeyStrings.isEmpty {
print("No valid key strings found in the matched string")
return nil
}
for (index, key) in validKeyStrings.enumerated() {
print("Valid Key \(index): \(key)")
}
return validKeyStrings
}
//super combo key button strings
@objc public func extractKeyStringsFromComboKeys(from input: String) -> [String]? {
let combinedStrings = [CommandManager.keyboardButtonMappings.keys.map { $0 as String },
CommandManager.oscButtonMappings.keys.map { $0 as String },
CommandManager.mouseButtonMappings.keys.map { $0 as String }]
.lazy // 零内存开销
.flatMap { $0 } // 三维展开
.map(String.init(describing:)) // 安全类型转换
let keys = combinedStrings.joined(separator: "|")
// print(keys)
let pattern = "^(?:(\(keys))(?:\\-(\(keys))*)*)$"
guard let regex = try? NSRegularExpression(pattern: pattern, options: []) else {
print("Failed to create regex")
return nil
}
let range = NSRange(location: 0, length: input.utf16.count)
guard let match = regex.firstMatch(in: input, options: [], range: range) else {
print("No match found for input: \(input)")
return nil
}
print("Regex matched for input: \(input)")
let matchedString = (input as NSString).substring(with: match.range(at: 0))
let keyStrings = matchedString.split(separator: "-").map { String($0) }
guard !keyStrings.isEmpty else {
print("No key strings found in the matched string")
return nil
}
var validKeyStrings: [String] = []
for key in keyStrings {
validKeyStrings.append(key)
}
if validKeyStrings.isEmpty {
print("No valid key strings found in the matched string")
return nil
}
for (index, key) in validKeyStrings.enumerated() {
print("Valid Key \(index): \(key)")
}
return validKeyStrings
}
@objc public func addCommand(_ command: RemoteCommand) -> Bool {
command.keyboardCmdString = command.keyboardCmdString.uppercased() // convert all letters to upper case
if(command.alias.trimmingCharacters(in: .whitespacesAndNewlines).count == 0) {command.alias = command.keyboardCmdString} // copy cmd string as alias when alias is empty
let keyStrings = extractKeyStringsFromComboCommand(from: command.keyboardCmdString)
if (keyStrings == nil) {return false} // in case of non-keyboard command strings, return false
commands.append(command)
saveCommands()
viewController?.reloadTableView() // don't know why but this reload has to be called from the CommandManager, doesn't work by calling it in the viewcontroller, probably related with the dialog box.
return true
}
@objc public func deleteCommand(at index: Int) {
guard index >= 0 && index < commands.count else {
return
}
commands.remove(at: index)
saveCommands()
}
@objc public func getAllCommands() -> [RemoteCommand] {
return commands
}
private func loadCommands() {
if let savedCommandsData = UserDefaults.standard.data(forKey: "savedCommands") {
do {
// Attempt to unarchive the data into an array of RemoteCommand
if let savedCommands = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, RemoteCommand.self], from: savedCommandsData) as? [RemoteCommand] {
// Assign the unarchived commands to your property
print(" Assign the unarchived commands to your property ")
commands = savedCommands
} else {
// Handle the case where the data could not be unarchived into the expected type
print("Data could not be unarchived into [RemoteCommand]")
}
} catch {
// Handle any errors that occur during unarchiving
print("Failed to unarchive savedCommands with error: \(error)")
}
}
}
private func saveCommands() {
if let data = try? NSKeyedArchiver.archivedData(withRootObject: commands, requiringSecureCoding: false) {
UserDefaults.standard.set(data, forKey: "savedCommands")
}
}
@objc public func sendKeyComboCommand(keyboardCmdStrings: [String], delay: TimeInterval = 0.2, index: Int = 0) { // we need a large delay for WAN streaming
// 如果已处理完所有按键,则开始释放按键
guard index < keyboardCmdStrings.count else {
// 释放按键
for keyStr in keyboardCmdStrings.reversed() { // 从后往前释放按键
if let keyCode = CommandManager.keyboardButtonMappings[keyStr] {
LiSendKeyboardEvent(keyCode, Int8(KEY_ACTION_UP), 0) // 释放按键
}
}
return
}
// 获取当前按键的映射值
if let keyCode = CommandManager.keyboardButtonMappings[keyboardCmdStrings[index]] {
// 发送当前按键的按下事件
LiSendKeyboardEvent(keyCode, Int8(KEY_ACTION_DOWN), 0)
// 延迟后递归处理下一个按键
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
self.sendKeyComboCommand(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index + 1)
}
} else {
print("No mapping found for \(keyboardCmdStrings[index])")
// 如果当前按键没有映射,跳过当前按键并继续下一个
self.sendKeyComboCommand(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index + 1)
}
}
@objc public func sendKeyComboDown(keyboardCmdStrings: [String]) { // we need a large delay for WAN streaming
for keyStr in keyboardCmdStrings {
if let keyCode = CommandManager.keyboardButtonMappings[keyStr] {
LiSendKeyboardEvent(keyCode, Int8(KEY_ACTION_DOWN), 0) // 释放按键
}
}
}
@objc public func sendKeyComboUp(keyboardCmdStrings: [String]) { // we need a large delay for WAN streaming
for keyStr in keyboardCmdStrings {
if let keyCode = CommandManager.keyboardButtonMappings[keyStr] {
LiSendKeyboardEvent(keyCode, Int8(KEY_ACTION_UP), 0) // 释放按键
}
}
return
}
}
-2
View File
@@ -46,8 +46,6 @@
-(void) setMotionEventState:(uint16_t)controllerNumber motionType:(uint8_t)motionType reportRateHz:(uint16_t)reportRateHz;
-(void) setControllerLed:(uint16_t)controllerNumber r:(uint8_t)r g:(uint8_t)g b:(uint8_t)b;
-(uint16_t) getActiveGamepadMask;
+(int) getConnectedGamepadMask:(StreamConfiguration*)streamConfig;
-(NSUInteger) getConnectedGamepadCount;
+14 -38
View File
@@ -46,7 +46,6 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
char _controllerNumbers;
bool _multiController;
bool _swapABXYButtons;
bool _captureMouse;
}
// UPDATE_BUTTON_FLAG(controller, flag, pressed)
@@ -355,10 +354,6 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
rightStickY = MAX_MAGNITUDE(rightStickY, controller.mergedWithController.lastRightStickY);
}
//NSLog(@"gamepadMask: %@", [self binaryRepresentationOfInteger:buttonFlags]); // we got the pressed OSC buttons here.
// Player 1 is always present for OSC
LiSendMultiControllerEvent(_multiController ? controller.playerIndex : 0, [self getActiveGamepadMask],
buttonFlags, leftTrigger, rightTrigger,
@@ -375,19 +370,6 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
}
}
- (NSString *)binaryRepresentationOfInteger:(int)number {
NSMutableString *binaryString = [NSMutableString string];
int numBits = sizeof(number) * 8;
for (int i = numBits - 1; i >= 0; i--) {
[binaryString appendString:((number >> i) & 1) ? @"1" : @"0"];
}
return binaryString;
}
+(BOOL) hasKeyboardOrMouse {
if (@available(iOS 14.0, tvOS 14.0, *)) {
return GCMouse.mice.count > 0 || GCKeyboard.coalescedKeyboard != nil;
@@ -865,25 +847,20 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
}
-(void) registerMouseCallbacks:(GCMouse*) mouse API_AVAILABLE(ios(14.0)) {
if (_captureMouse){
mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput * _Nonnull mouse, float deltaX, float deltaY) {
self->accumulatedDeltaX += deltaX / MOUSE_SPEED_DIVISOR;
self->accumulatedDeltaY += -deltaY / MOUSE_SPEED_DIVISOR;
mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput * _Nonnull mouse, float deltaX, float deltaY) {
self->accumulatedDeltaX += deltaX / MOUSE_SPEED_DIVISOR;
self->accumulatedDeltaY += -deltaY / MOUSE_SPEED_DIVISOR;
short truncatedDeltaX = (short)self->accumulatedDeltaX;
short truncatedDeltaY = (short)self->accumulatedDeltaY;
if (truncatedDeltaX != 0 || truncatedDeltaY != 0) {
LiSendMouseMoveEvent(truncatedDeltaX, truncatedDeltaY);
short truncatedDeltaX = (short)self->accumulatedDeltaX;
short truncatedDeltaY = (short)self->accumulatedDeltaY;
if (truncatedDeltaX != 0 || truncatedDeltaY != 0) {
LiSendMouseMoveEvent(truncatedDeltaX, truncatedDeltaY);
self->accumulatedDeltaX -= truncatedDeltaX;
self->accumulatedDeltaY -= truncatedDeltaY;
}
};
} else {
mouse.mouseInput.mouseMovedHandler = nil;
}
self->accumulatedDeltaX -= truncatedDeltaX;
self->accumulatedDeltaY -= truncatedDeltaY;
}
};
mouse.mouseInput.leftButton.pressedChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
LiSendMouseButtonEvent(pressed ? BUTTON_ACTION_PRESS : BUTTON_ACTION_RELEASE, BUTTON_LEFT);
@@ -1084,7 +1061,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
// Even if no gamepads are present, we will always count one if OSC is enabled,
// or it's set to auto and no keyboard or mouse is present. Absolute touch mode
// disables the OSC.
if (level != OnScreenControlsLevelOff && (![ControllerSupport hasKeyboardOrMouse] || level != OnScreenControlsLevelAuto) && (settings.touchMode.intValue == RELATIVE_TOUCH)) {
if (level != OnScreenControlsLevelOff && (![ControllerSupport hasKeyboardOrMouse] || level != OnScreenControlsLevelAuto) && !settings.absoluteTouchMode) {
mask |= 0x1;
}
@@ -1126,7 +1103,6 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
}
}
_captureMouse = (streamConfig.localMousePointerMode == 0);
if (@available(iOS 14.0, tvOS 14.0, *)) {
for (GCMouse* mouse in [GCMouse mice]) {
[self registerMouseCallbacks:mouse];
@@ -1,37 +0,0 @@
//
// LayoutOnScreenControls.h
// Moonlight
//
// Created by Long Le on 9/26/22.
// Copyright © 2022 Moonlight Game Streaming Project. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "OnScreenControls.h"
#import "Moonlight-Swift.h"
NS_ASSUME_NONNULL_BEGIN
/**
This object is a subclass of 'OnScreenControls' and adds additional properties and functions which allow the user to drag and drop each of the 19 on screen controller buttons in order to change their positions on screen. The object is used in the 'LayoutOnScreenControlsViewController' thus allowing the user to drag, drop, hide, unhide, on screen controller buttons.
Note that this is in contrast to the game stream view which displays an 'OnScreenControls' object on screen that allows the app to register taps on each button as controller input. It does not (and naturally should not) allow the user to move the buttons around the screen.
*/
@interface LayoutOnScreenControls : OnScreenControls
@property UIView* _view;
@property NSMutableArray *layoutChanges;
@property CALayer *layerBeingDragged;
@property UIViewController *layoutToolVC;
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport
streamConfig:(StreamConfiguration*)streamConfig oscLevel:(int)oscLevel;
- (CALayer*) controllerLayerFromName:(NSString*)name;
- (BOOL) isLayer:(CALayer*)layer hoveringOverButton:(UIButton*)button;
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
// - (void) updateGuidelinesForOnScreenWidget:(OnScreenWidgetView* )widget;
@end
NS_ASSUME_NONNULL_END
@@ -1,337 +0,0 @@
//
// LayoutOnScreenControls.m
// Moonlight
//
// Created by Long Le on 9/26/22.
// Copyright © 2022 Moonlight Game Streaming Project. All rights reserved.
//
#import "LayoutOnScreenControls.h"
#import "OSCProfilesTableViewController.h"
#import "OnScreenButtonState.h"
#import "OSCProfilesManager.h"
@interface LayoutOnScreenControls ()
@end
@implementation LayoutOnScreenControls {
UIButton *trashCanButton;
UIView *horizontalGuideline;
UIView *verticalGuideline;
}
@synthesize layerBeingDragged;
@synthesize _view;
@synthesize layoutChanges;
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport streamConfig:(StreamConfiguration*)streamConfig oscLevel:(int)oscLevel {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateGuidelinesForOnScreenWidget:)
name:@"OnScreenWidgetMovedByTouch" // This is a special notification for reloading the on screen keyboard buttons. which can't be executed by _oscProfilesTableViewController.needToUpdateOscLayoutTVC code block, and has to be triggered by a notification
object:nil];
_view = view;
_view.multipleTouchEnabled = false;
self = [super initWithView:view controllerSup:controllerSupport streamConfig:streamConfig];
self.isLayingOut = true; // make sure the super class have a flag to tell it's currently laying out the OSCs, intead play mode.
self._level = oscLevel;
layoutChanges = [[NSMutableArray alloc] init]; // will contain OSC button layout changes the user has made for this profile
[self drawButtons];
[self drawGuidelines]; // add the blue guidelines that appear when button is being tapped and dragged
return self;
}
#pragma mark - Drawing
/**
* This method overrides the superclass's drawButtons method. The purpose of this method is to create a dPad parent layer, and add the four dPad buttons to it so that the user can drag the entire dPad around, directional buttons and all, as one unit as is the expected behavior. Note that we do not want the four dPad buttons to be child layers of a CALayer parent layer on the game stream view since the touch logic implemented for the four dPad buttons on the game stream view is written assuming the dPad buttons are not children of another parent CALayer
*/
- (void) drawButtons {
[super setDPadCenter]; // Set custom position for D-Pad here
[super setAnalogStickPositions]; // Set custom position for analog sticks here
[super drawBumpers];
[super drawButtons];
UIImage* downButtonImage = [UIImage imageNamed:@"DownButton"];
UIImage* rightButtonImage = [UIImage imageNamed:@"RightButton"];
UIImage* upButtonImage = [UIImage imageNamed:@"UpButton"];
UIImage* leftButtonImage = [UIImage imageNamed:@"LeftButton"];
// create dPad background layer
self._dPadBackground = [CALayer layer];
self._dPadBackground.name = @"dPad";
self._dPadBackground.frame = CGRectMake(self.D_PAD_CENTER_X,
self.D_PAD_CENTER_Y,
self._leftButton.frame.size.width * 2 + BUTTON_DIST,
self._leftButton.frame.size.width * 2 + BUTTON_DIST);
self._dPadBackground.position = CGPointMake(self.D_PAD_CENTER_X, self.D_PAD_CENTER_Y); // since dPadBackground's dimensions have change after settings its width and height you need to reset its position again here
[self.OSCButtonLayers addObject:self._dPadBackground];
[_view.layer addSublayer:self._dPadBackground];
// add dPad buttons to parent layer
[self._dPadBackground addSublayer:self._downButton];
[self._dPadBackground addSublayer:self._rightButton];
[self._dPadBackground addSublayer:self._upButton];
[self._dPadBackground addSublayer:self._leftButton];
[self resizeControllerLayerWith:self._dPadBackground and:_dPadSizeFactor];
/*
// reposition each dPad button within their parent dPadBackground layer
self._downButton.frame = CGRectMake(self._dPadBackground.frame.size.width/3, self._dPadBackground.frame.size.height/2 + D_PAD_DIST, downButtonImage.size.width, downButtonImage.size.height);
self._rightButton.frame = CGRectMake(self._dPadBackground.frame.size.width/2 + D_PAD_DIST, self._dPadBackground.frame.size.height/3, rightButtonImage.size.width, rightButtonImage.size.height);
self._upButton.frame = CGRectMake(self._dPadBackground.frame.size.width/3, 0, upButtonImage.size.width, upButtonImage.size.height);
self._leftButton.frame = CGRectMake(0, self._dPadBackground.frame.size.height/3, leftButtonImage.size.width, leftButtonImage.size.height);*/
}
/**
* draws a horizontal and vertical line that is made visible and positioned over whichever button the user is dragging around the screen
*/
- (void) drawGuidelines {
horizontalGuideline = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self._view.frame.size.width * 2, 2)];
horizontalGuideline.backgroundColor = [UIColor blueColor];
horizontalGuideline.hidden = YES;
[self._view addSubview: horizontalGuideline];
verticalGuideline = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 2, self._view.frame.size.height * 2)];
verticalGuideline.backgroundColor = [UIColor blueColor];
verticalGuideline.hidden = YES;
[self._view addSubview: verticalGuideline];
}
- (void) updateGuidelinesForOnScreenWidget: (NSNotification *)notification{
/* have guidelines follow wherever the user is touching on the screen */
OnScreenWidgetView* widget = notification.object;
horizontalGuideline.hidden = verticalGuideline.hidden = NO;
horizontalGuideline.center = verticalGuideline.center = CGPointMake(CGRectGetMidX(widget.frame), CGRectGetMidY(widget.frame));
/*
Telegraph to the user whether the horizontal and/or vertical guidelines line up with one or more of the buttons on screen by doing the following:
-Change horizontal guideline color to yellow if its y-position is almost equal to that of one of the buttons on screen.
-Change vertical guideline color to yellow if its x-position is almost equal to that of one of the buttons on screen.
*/
horizontalGuideline.backgroundColor = [UIColor blueColor]; // change horizontal guideline back to blue if it doesn't line up with one of the on screen buttons
for (CALayer *button in self.OSCButtonLayers) { // horizontal guideline position check
if ((layerBeingDragged != button) && !button.isHidden) {
if ((horizontalGuideline.center.y < button.position.y + 1) &&
(horizontalGuideline.center.y > button.position.y - 1)) {
horizontalGuideline.backgroundColor = [UIColor yellowColor];
break;
}
}
}
for(UIView* view in self.layoutToolVC.view.subviews){
if ([view isKindOfClass:[OnScreenWidgetView class]] && view != widget) {
if ((horizontalGuideline.center.y < view.center.y + 1) && (horizontalGuideline.center.y > view.center.y - 1)) {
horizontalGuideline.backgroundColor = [UIColor yellowColor];
break;
}
}
}
verticalGuideline.backgroundColor = [UIColor blueColor]; // change vertical guideline back to blue if it doesn't line up with one of the on screen buttons
for (CALayer *button in self.OSCButtonLayers) { // vertical guideline position check
if ((layerBeingDragged != button) && !button.isHidden) {
if ((verticalGuideline.center.x < button.position.x + 1) &&
(verticalGuideline.center.x > button.position.x - 1)) {
verticalGuideline.backgroundColor = [UIColor yellowColor];
break;
}
}
}
for(UIView* view in self.layoutToolVC.view.subviews){
if ([view isKindOfClass:[OnScreenWidgetView class]] && view != widget) {
if ((verticalGuideline.center.x < view.center.x + 1) && (verticalGuideline.center.x > view.center.x - 1)) {
verticalGuideline.backgroundColor = [UIColor yellowColor];
break;
}
}
}
}
#pragma mark - Queries
/* used to determine whether user is dragging an OSC button (of type CALayer) over the trash can with the intent of hiding that button */
- (BOOL) isLayer:(CALayer *)layer hoveringOverButton:(UIButton *)button {
CGRect buttonConvertedRect = [self._view convertRect:button.imageView.frame fromView:button.superview];
if (CGRectIntersectsRect(layer.frame, buttonConvertedRect)) {
return YES;
}
else {
return NO;
}
}
/* returns reference to button layer object given the button's name*/
- (CALayer*)controllerLayerFromName: (NSString*)name {
for (CALayer *buttonLayer in self.OSCButtonLayers) {
if ([buttonLayer.name isEqualToString:name]) {
return buttonLayer;
}
}
return nil;
}
#pragma mark - Touch
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Reset variables related to on screen controller button drag and drop routine. These variables should be reset in 'touchesCancelled' or 'touchesEnded' but these may not be called in unaccounted-for edge cases such as when the user opens various OS-level control center related views by dragging down from the top of the screen, or dragging up from the bottom of the screen. Since Apple likes to add new control centers and new ways of opening them (i.e. Dynamic Island on iPhone 14 Pro) it's best to reset these variables here when the user is beginning a new on screen controller button drag routine */
[[NSNotificationCenter defaultCenter] postNotificationName:@"LegacyOscCALayerSelectedNotification" object:self];
layerBeingDragged = nil;
horizontalGuideline.backgroundColor = [UIColor blueColor];
verticalGuideline.backgroundColor = [UIColor blueColor];
for (UITouch* touch in touches) { // Process touch
CGPoint touchLocation = [touch locationInView:_view];
touchLocation = [[touch view] convertPoint:touchLocation toView:nil];
CALayer *layer = [_view.layer hitTest:touchLocation];
/* Don't let user drag and move anything other than on screen controller buttons, which are CALayer types. The reason is that 'LayoutOnScreenControls' should only be responsible for managing and letting users move on screen controller buttons. Since this class's view is currently set to be set equal to the 'LayoutOnScreenControlsViewController' view it belongs to, we need to make sure touches on the VC's objects don't propagate down to 'LayoutOnScreenControls'. Weird stuff can happen to the UI buttons that belong to that VC (trash can button, undo button, save button, etc), such as them being dragged around the screen with the user's touches */
for (UIView *subview in self._view.subviews) {
if (CGRectContainsPoint(subview.frame, touchLocation)) {
if (![subview isKindOfClass:[CALayer class]]) {
return;
}
}
}
if (layer == self._upButton ||
layer == self._downButton ||
layer == self._leftButton ||
layer == self._rightButton) { // don't let user drag individual dPad buttons
layerBeingDragged = self._dPadBackground;
}
else if (layer == self._rightStick) { // only let user drag right stick's background, not the inner analog stick itself
layerBeingDragged = self._rightStickBackground;
}
else if (layer == self._leftStick) { // only let user drag left stick's background, not the inner analog stick itself
layerBeingDragged = self._leftStickBackground;
}
else if(layer == self._aButton ||
layer == self._bButton ||
layer == self._xButton ||
layer == self._yButton ||
layer == self._l1Button ||
layer == self._l2Button ||
layer == self._r1Button ||
layer == self._r2Button ||
layer == self._selectButton ||
layer == self._startButton){ // we must iterates all the controller button layers manually here, to prevent other widgets being dragged accidently
layerBeingDragged = layer;
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"ControllerCALayerSelected" object:layerBeingDragged]; // inform that a CALayer of onScreen controller has being selected
/* save the name, position, and visibility of button being touched in array in case user wants to undo the change later */
OnScreenButtonState *onScreenButtonState = [[OnScreenButtonState alloc] initWithButtonName:layerBeingDragged.name buttonType:LegacyOscButton andPosition:layerBeingDragged.position];
// add hidden attr here
onScreenButtonState.isHidden = layerBeingDragged.isHidden;
[layoutChanges addObject:onScreenButtonState];
[[NSNotificationCenter defaultCenter] postNotificationName:@"OSCLayoutChanged" object:self]; // lets the view controller know whether to fade the undo button in or out depending on whether there are any further OSC layout changes the user is allowed to undo
/* make guide lines visible and position them over the button the user is touching */
horizontalGuideline.center = layerBeingDragged.position;
horizontalGuideline.hidden = NO;
verticalGuideline.center = layerBeingDragged.position;
verticalGuideline.hidden = NO;
}
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:_view];
layerBeingDragged.position = touchLocation; // move object to touch location
/* have guidelines follow wherever the user is touching on the screen */
horizontalGuideline.center = layerBeingDragged.position;
verticalGuideline.center = layerBeingDragged.position;
/*
Telegraph to the user whether the horizontal and/or vertical guidelines line up with one or more of the buttons on screen by doing the following:
-Change horizontal guideline color to yellow if its y-position is almost equal to that of one of the buttons on screen.
-Change vertical guideline color to yellow if its x-position is almost equal to that of one of the buttons on screen.
*/
horizontalGuideline.backgroundColor = [UIColor blueColor]; // change horizontal guideline back to blue if it doesn't line up with one of the on screen buttons
for (CALayer *button in self.OSCButtonLayers) { // horizontal guideline position check
if ((layerBeingDragged != button) && !button.isHidden) {
if ((horizontalGuideline.center.y < button.position.y + 1) &&
(horizontalGuideline.center.y > button.position.y - 1)) {
horizontalGuideline.backgroundColor = [UIColor yellowColor];
break;
}
}
}
// alignment with onScreenWidgets
for(UIView* view in self.layoutToolVC.view.subviews){
if ([view isKindOfClass:[OnScreenWidgetView class]]) {
if ((horizontalGuideline.center.y < view.center.y + 1) && (horizontalGuideline.center.y > view.center.y - 1)) {
horizontalGuideline.backgroundColor = [UIColor yellowColor];
break;
}
}
}
verticalGuideline.backgroundColor = [UIColor blueColor]; // change vertical guideline back to blue if it doesn't line up with one of the on screen buttons
for (CALayer *button in self.OSCButtonLayers) { // vertical guideline position check
if ((layerBeingDragged != button) && !button.isHidden) {
if ((verticalGuideline.center.x < button.position.x + 1) &&
(verticalGuideline.center.x > button.position.x - 1)) {
verticalGuideline.backgroundColor = [UIColor yellowColor];
break;
}
}
}
// alignment with onScreenWidgets
for(UIView* view in self.layoutToolVC.view.subviews){
if ([view isKindOfClass:[OnScreenWidgetView class]]) {
if ((verticalGuideline.center.x < view.center.x + 1) && (verticalGuideline.center.x > view.center.x - 1)) {
verticalGuideline.backgroundColor = [UIColor yellowColor];
break;
}
}
}
}
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
layerBeingDragged = nil;
horizontalGuideline.hidden = YES;
verticalGuideline.hidden = YES;
horizontalGuideline.backgroundColor = [UIColor blueColor];
verticalGuideline.backgroundColor = [UIColor blueColor];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
layerBeingDragged = nil;
horizontalGuideline.hidden = YES;
verticalGuideline.hidden = YES;
horizontalGuideline.backgroundColor = [UIColor blueColor];
verticalGuideline.backgroundColor = [UIColor blueColor];
}
@end
-32
View File
@@ -1,32 +0,0 @@
//
// OSCProfile.h
// Moonlight
//
// Created by Long Le on 12/22/22.
// Copyright © 2022 Moonlight Game Streaming Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "OnScreenButtonState.h"
NS_ASSUME_NONNULL_BEGIN
/**
This object contains information pertaining to any of the user created, custom on screen controller layout configurations, or 'profiles.' The object contains a 'name' property for easy reference, as well as an 'isSelected' property which is used to determine whether this particular custom OSC layout should show on screen during game stream view. Only one 'OSCProfile' is set to 'isSelected' at any given time. The object also contains an array of 'OnScreenButtonStates' which provides information that allows us to move and hide/unhide each of the 19 on screen buttons. Note that the 'buttonStates' property should contain an NSMutableArray of ENCODED 'OnScreenButtonState' objects. This allows us to save the 'OSCProfile' object to NSUserDefaults.
Additionally the 'OSCProfile' object adopts encoding and decoding protocols so that we can encode the object before saving it to NSUserDefaults. By saving this object to NSUserDefaults we allow the user to save and load their custom on screen controller button layouts between app launches
*/
@interface OSCProfile : NSObject <NSCoding, NSSecureCoding>
@property NSString *name;
@property NSMutableArray <OnScreenButtonState *> *buttonStates;
@property BOOL isSelected;
- (id) initWithName:(NSString*)name buttonStates:(NSMutableArray*)buttonStates isSelected:(BOOL)isSelected;
+ (BOOL) supportsSecureCoding;
- (id) initWithCoder:(NSCoder*)decoder;
- (void) encodeWithCoder:(NSCoder*)encoder;
@end
NS_ASSUME_NONNULL_END
-43
View File
@@ -1,43 +0,0 @@
//
// OSCProfile.m
// Moonlight
//
// Created by Long Le on 12/22/22.
// Copyright © 2022 Moonlight Game Streaming Project. All rights reserved.
//
#import "OSCProfile.h"
@implementation OSCProfile
- (id) initWithName:(NSString*)name buttonStates:(NSMutableArray*)buttonStates isSelected:(BOOL)isSelected {
if ((self = [self init])) {
self.name = name;
self.buttonStates = buttonStates;
self.isSelected = isSelected;
}
return self;
}
+ (BOOL) supportsSecureCoding {
return YES;
}
- (void) encodeWithCoder:(NSCoder*)encoder {
[encoder encodeObject:self.name forKey:@"name"];
[encoder encodeObject:self.buttonStates forKey:@"buttonStates"];
[encoder encodeBool:self.isSelected forKey:@"isSelected"];
}
- (id) initWithCoder:(NSCoder*)decoder {
if (self = [super init]) {
self.name = [decoder decodeObjectForKey:@"name"];
self.buttonStates = [decoder decodeObjectForKey:@"buttonStates"];
self.isSelected = [decoder decodeBoolForKey:@"isSelected"];
}
return self;
}
@end
@@ -1,69 +0,0 @@
//
// OSCProfilesManager.h
// Moonlight
//
// Created by Long Le on 1/1/23.
// Copyright © 2023 Moonlight Game Streaming Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "OSCProfile.h"
NS_ASSUME_NONNULL_BEGIN
/**
This singleton object can be accessed from any class and provides methods to get and set on screen controller profile related data.
Note that the implementation file contains a number of 'Helper' methods. These helper methods are only used in this class's implementation file and help to reduce re-writing large blocks of code that are called multiple times throughout the file
*/
@interface OSCProfilesManager : NSObject
+ (OSCProfilesManager *) sharedManager;
+ (void) setOnScreenWidgetViewsSet:(NSMutableSet* )set;
#pragma mark - Getters
/**
* Returns an array of decoded profile objects
*/
- (NSMutableArray *) getAllProfiles;
/**
* Returns the OSC Profile that is currently selected to be displayed on screen during game streaming
*/
- (OSCProfile *) getSelectedProfile;
/**
* Returns the index of the 'selected' profile within the array it's in
*/
- (NSInteger) getIndexOfSelectedProfile;
#pragma mark - Setters
/**
* Sets the profile object with the particular 'name' as the selected profile to be displayed on screen during game streaming
*/
- (void) setProfileToSelected:(NSString *)name;
/**
* Saves a profile object with a particular 'name' and an array of button layers (the CALayer button layers are the objects currently visible on screen) to persistent storage
*/
- (void) saveProfileWithName:(NSString*)name andButtonLayers:(NSMutableArray *)buttonLayers;
- (bool) updateSelectedProfile:(NSMutableArray *) oscButtonLayers;
/**
* Delete current selected profile.
*/
- (void) deleteCurrentSelectedProfile;
#pragma mark - Queries
/**
* Lets the caller of this method know whether a profile with a given name already exists in persistent storage
*/
- (BOOL) profileNameAlreadyExist:(NSString*)name;
@end
NS_ASSUME_NONNULL_END
@@ -1,333 +0,0 @@
//
// OSCProfilesManager.m
// Moonlight
//
// Created by Long Le on 1/1/23.
// Copyright © 2023 Moonlight Game Streaming Project. All rights reserved.
//
#import "OSCProfilesManager.h"
#import "OnScreenButtonState.h"
#import "Moonlight-Swift.h"
#import "LayoutOnScreenControlsViewController.h"
#import "OnScreenControls.h"
@implementation OSCProfilesManager
static NSMutableSet *OnScreenWidgetViews;
#pragma mark - Initializer
+ (OSCProfilesManager *) sharedManager {
static OSCProfilesManager *_sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedManager = [[self alloc] init];
});
return _sharedManager;
}
#pragma mark - Class Helper Methods
+ (void) setOnScreenWidgetViewsSet:(NSMutableSet* )set{
OnScreenWidgetViews = set;
}
/**
* Returns the profile whose 'name' property has a value that is equal to the 'name' passed into the method
*/
- (OSCProfile *) OSCProfileWithName:(NSString*)name {
NSMutableArray *profiles = [self getAllProfiles];
for (OSCProfile *profile in profiles) {
if ([profile.name isEqualToString:name]) {
return profile;
}
}
return nil;
}
/**
* Returns an array of encoded 'OSCProfile' objects from the array of decoded 'OSCProfile' objects passed into this method
*/
- (NSMutableArray *) encodedProfilesFromArray:(NSMutableArray *)profiles {
NSMutableArray *profilesEncoded = [[NSMutableArray alloc] init];
/* encode each profile and add them back into an array */
for (OSCProfile *profile in profiles) { //
NSData *profileEncoded = [NSKeyedArchiver archivedDataWithRootObject:profile requiringSecureCoding:YES error:nil];
[profilesEncoded addObject:profileEncoded];
}
return profilesEncoded;
}
/**
* Delete an 'OSCProfile' object of specific index for another in the 'OSCProfile' objects array stored in persistent storage
*/
-(void)deleteCurrentSelectedProfile{
NSMutableArray *profiles = [self getAllProfiles];
NSInteger selectedIndex = [self getIndexOfSelectedProfile];
/* Remove the selected profile */
if(selectedIndex != 0) [profiles removeObjectAtIndex:selectedIndex]; //deleting default profile (index 0) is not allowed
else {
NSLog(@"Default profile!"); // to be updated here.
}
selectedIndex--;
if(selectedIndex < 0) selectedIndex = 0;
OSCProfile *newSelectedProfile = [profiles objectAtIndex:selectedIndex];
newSelectedProfile.isSelected = YES;
NSMutableArray *profilesEncoded = [self encodedProfilesFromArray:profiles]; // encode each 'profile' object in the array and add them to a new array
/* Encode the array itself, NOT the objects in the array, which are already encoded. Save array to persistent storage */
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profilesEncoded requiringSecureCoding:YES error:nil];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"OSCProfiles"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
/**
* Replaces one 'OSCProfile' object for another in the 'OSCProfile' objects array stored in persistent storage
*/
- (void) replaceProfile:(OSCProfile*)oldProfile withProfile:(OSCProfile*)newProfile {
NSMutableArray *profiles = [self getAllProfiles];
for (OSCProfile *profile in profiles) { // set all profiles' 'isSelected' property to NO since the new profile we're saving over the old profile with will be the 'selected' profile
profile.isSelected = NO;
}
/* Set the new profile as the selected one. The reasoning behind this is that this method is currently being used when the user saves over an existing profile with another profile that has the same name. The expected behavior is that the newly saved profile becomes the selected profile which will show on screen when they launch the game stream view */
newProfile.isSelected = YES;
/* Remove the old profile from the array and insert the new profile into its place */
int index = 0;
for (int i = 0; i < profiles.count; i++) {
if ([[profiles[i] name] isEqualToString: oldProfile.name]) {
index = i;
}
}
[profiles removeObjectAtIndex:index];
[profiles insertObject:newProfile atIndex:index];
NSMutableArray *profilesEncoded = [self encodedProfilesFromArray:profiles]; // encode each 'profile' object in the array and add them to a new array
/* Encode the array itself, NOT the objects in the array, which are already encoded. Save array to persistent storage */
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profilesEncoded requiringSecureCoding:YES error:nil];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"OSCProfiles"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
#pragma mark - Globally Accessible Methods
#pragma mark - Getters
- (NSMutableArray *) getAllProfiles {
NSData *profilesArrayEncoded = [[NSUserDefaults standardUserDefaults] objectForKey: @"OSCProfiles"]; // Get the encoded array of encoded OSC profiles from persistent storage
NSSet *classes = [NSSet setWithObjects:[NSString class], [NSMutableData class], [NSMutableArray class], [OSCProfile class], [OnScreenButtonState class], nil];
NSMutableArray *profilesEncoded = [NSKeyedUnarchiver unarchivedObjectOfClasses:classes fromData:profilesArrayEncoded error:nil]; // Decode the encoded array itself, NOT the objects contained in the array
/* Decode each of the encoded profiles, place them into an array, then return the array */
NSMutableArray *profilesDecoded = [[NSMutableArray alloc] init];
OSCProfile *profileDecoded;
for (NSData *profileEncoded in profilesEncoded) {
profileDecoded = [NSKeyedUnarchiver unarchivedObjectOfClasses: classes fromData:profileEncoded error: nil];
[profilesDecoded addObject: profileDecoded];
}
return profilesDecoded;
}
- (OSCProfile *) getSelectedProfile {
NSMutableArray *profiles = [self getAllProfiles];
for (OSCProfile *profile in profiles) {
if (profile.isSelected) {
return profile;
}
}
return nil;
}
- (NSInteger) getIndexOfSelectedProfile {
NSMutableArray *profiles = [self getAllProfiles];
for (OSCProfile *profile in profiles) {
if (profile.isSelected == YES) {
return [profiles indexOfObject:profile];
}
}
return 0; // if none of the profiles in the array have their 'isSelected' property set to YES (which should not be possible) return the 'Default' profile as the 'selected' profile
}
#pragma mark - Setters
- (void) setProfileToSelected:(NSString *)name {
NSMutableArray *profiles = [self getAllProfiles];
/* Iterate through each profile. If its name equals the value of the 'name' parameter passed into this method then set the profile's 'isSelected' property to YES, otherwise set the value to NO */
for (OSCProfile *profile in profiles) {
if ([profile.name isEqualToString:name]) {
profile.isSelected = YES;
}
else {
profile.isSelected = NO;
}
}
NSMutableArray *profilesEncoded = [self encodedProfilesFromArray:profiles]; // encode each 'profile' object in the array and add them to a new array
/* Encode the array itself, NOT the objects inside the array, which have already been encoded by this point */
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profilesEncoded requiringSecureCoding:YES error:nil];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"OSCProfiles"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (bool) updateSelectedProfile:(NSMutableArray *) oscButtonLayers {
NSMutableArray* buttonStatesEncoded = [self convertOnScreenControllerAndButtonsToButtonStates:oscButtonLayers];
if([self getIndexOfSelectedProfile]==0) return false;
OSCProfile *newProfile = [[OSCProfile alloc] initWithName:[self getSelectedProfile].name
buttonStates:buttonStatesEncoded isSelected:YES]; // create a new 'OSCProfile'. Set the array of encoded button states created above to the 'buttonStates' property of the new profile, along with a 'name'. Set 'isSelected' argument to YES which will set this saved profile as the one that will show up in the game stream view
/* set all saved OSCProfiles 'isSelected' property to NO since the new profile you're adding will be set as the selected profile */
NSMutableArray *profiles = [self getAllProfiles];
for (OSCProfile *profile in profiles) {
profile.isSelected = NO;
}
[self replaceProfile:[self getSelectedProfile] withProfile:newProfile];
return true;
}
- (void) saveProfileWithName:(NSString*)name andButtonLayers:(NSMutableArray *)oscButtonLayers {
NSMutableArray* buttonStatesEncoded = [self convertOnScreenControllerAndButtonsToButtonStates:oscButtonLayers];
OSCProfile *newProfile = [[OSCProfile alloc] initWithName:name
buttonStates:buttonStatesEncoded isSelected:YES]; // create a new 'OSCProfile'. Set the array of encoded button states created above to the 'buttonStates' property of the new profile, along with a 'name'. Set 'isSelected' argument to YES which will set this saved profile as the one that will show up in the game stream view
/* set all saved OSCProfiles 'isSelected' property to NO since the new profile you're adding will be set as the selected profile */
NSMutableArray *profiles = [self getAllProfiles];
for (OSCProfile *profile in profiles) {
profile.isSelected = NO;
}
if ([self profileNameAlreadyExist:name]) { // if a saved profile with the same 'name' already exists in persistent storage then overwrite it and save the change to persistent storage
[self replaceProfile:[self OSCProfileWithName:name] withProfile:newProfile];
}
else { // otherwise encode then add the new profile to the end of the OSCProfiles array
NSData *newProfileEncoded = [NSKeyedArchiver archivedDataWithRootObject:newProfile requiringSecureCoding:YES error:nil];
NSMutableArray *profilesEncoded = [self encodedProfilesFromArray:profiles];
[profilesEncoded addObject:newProfileEncoded];
/* Encode the 'profilesEncoded' array itself, NOT the objects in the 'profilesEncoded' array, all of which are already encoded by this point */
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profilesEncoded requiringSecureCoding:YES error:nil];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"OSCProfiles"];
[[NSUserDefaults standardUserDefaults] synchronize];
// saving test:
/*
NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
NSString *path = [documentsPath stringByAppendingPathComponent:@"newDefault.bin"];
[newProfileEncoded writeToFile:path atomically:YES];
NSLog(@"默认 Profile 数据已保存到: %@", path);
*/
}
}
- (NSMutableArray* ) convertOnScreenControllerAndButtonsToButtonStates:(NSMutableArray *) oscButtonLayers {
/* iterate through each OSC button the user sees on screen, create an 'OnScreenButtonState' object from each button, encode each object, and then add each object to an array */
/*
NSSet *validPositionButtonNames = [NSSet setWithObjects:
@"l2Button",
@"l1Button",
@"dPad",
@"selectButton",
@"leftStickBackground",
@"rightStickBackground",
@"r2Button",
@"r1Button",
@"aButton",
@"bButton",
@"xButton",
@"yButton",
@"startButton",
nil]; */
NSMutableArray *buttonStatesEncoded = [[NSMutableArray alloc] init];
// save on-screen game controller buttons & sticks as buttonstate:
for (CALayer *oscButtonLayer in oscButtonLayers) {
OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:oscButtonLayer.name buttonType:LegacyOscButton andPosition:oscButtonLayer.position];
// add hidden attr here
buttonState.isHidden = oscButtonLayer.isHidden;
buttonState.oscLayerSizeFactor = [OnScreenControls getControllerLayerSizeFactor:oscButtonLayer];
buttonState.backgroundAlpha = oscButtonLayer.opacity;
NSLog(@"oscLayerName: %@, opacity: %f, ", oscButtonLayer.name, buttonState.backgroundAlpha);
// buttonState.oscLayerSizeFactor = oscButtonLayer.bounds;
NSData *buttonStateEncoded = [NSKeyedArchiver archivedDataWithRootObject:buttonState requiringSecureCoding:YES error:nil];
[buttonStatesEncoded addObject: buttonStateEncoded];
}
// save on-screen widget views (keyboard & mouse command) as buttonstate:
for(OnScreenWidgetView* widgetView in OnScreenWidgetViews){
OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:widgetView.keyString buttonType:CustomOnScreenWidget andPosition:widgetView.center];
buttonState.alias = widgetView.keyLabel;
buttonState.timestamp = widgetView.timestamp;
buttonState.widthFactor = widgetView.widthFactor;
buttonState.heightFactor = widgetView.heightFactor;
buttonState.backgroundAlpha = widgetView.backgroundAlpha;
buttonState.borderWidth = widgetView.borderWidth;
buttonState.sensitivityFactor = widgetView.sensitivityFactor;
buttonState.stickIndicatorOffset = widgetView.stickIndicatorOffset;
NSData *buttonStateEncoded = [NSKeyedArchiver archivedDataWithRootObject:buttonState requiringSecureCoding:YES error:nil];
[buttonStatesEncoded addObject: buttonStateEncoded];
}
return buttonStatesEncoded;
}
#pragma mark - Queries
- (BOOL) profileNameAlreadyExist:(NSString*)name {
NSMutableArray *profiles = [self getAllProfiles];
/* Iterate through the decoded profiles and return 'YES' if one of the profiles' 'name' properties equals the 'name' passed into this method */
for (OSCProfile *profile in profiles) {
if ([profile.name isEqualToString:name]) {
return YES;
}
}
return NO;
}
@end
@@ -1,52 +0,0 @@
//
// OnScreenButtonState.h
// Moonlight
//
// Created by Long Le on 10/20/22.
// Copyright © 2022 Moonlight Game Streaming Project. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
This object is used to save positional and visibility information for any particular on screen virtual controller button.
We are able to associate this 'OnScreenButtonState' object and its corresponding CALayer onscreen controller button by setting their 'name' properties equal; in our particular case we give them descriptive names such as 'aButton', 'upButton', 'leftStick', etc. By keeping references to the 19 on screen controller buttons (CALayers) in an array, and creating 19 'OnScreenButtonState' objects with names corresponding to these 19 CALayers and keeping them in an array, we can iterate through both arrays to find OSC buttons (CALayers) with the same name as one of the 'OnScreenButtonStateObjects' and then set the CALayer on screen control button's 'position' and 'hidden' property according to the value of the 'OnScreenButtonState' objects 'position' and 'isHidden' properties.
Naturally we would like the user to be able to save their controller layout configurations so that they can load them between app launches, so we adopt encoding/decoding related protocols so we encode these 'OnScreenButtonState' objects and save them to NSUserDefaults
*/
// OS Button state info obj to be modified
@interface OnScreenButtonState : NSObject <NSCoding, NSSecureCoding>
@property NSString *name;
@property NSString *alias;
@property CGPoint position;
@property (nonatomic, assign) BOOL isHidden;
@property (nonatomic, assign) uint8_t buttonType;
@property (nonatomic, assign) NSTimeInterval timestamp;
@property (nonatomic, assign) CGFloat widthFactor; // for OnScreenWidgetView
@property (nonatomic, assign) CGFloat heightFactor; // for OnScreenWidgetView
@property (nonatomic, assign) CGFloat borderWidth; // for OnScreenWidgetView
@property (nonatomic, assign) CGFloat sensitivityFactor; // for OnScreenWidgetView
@property (nonatomic, assign) CGFloat stickIndicatorOffset; // for OnScreenWidgetView
@property (nonatomic, assign) CGFloat oscLayerSizeFactor; // for OnScreenController CALayer
@property (nonatomic, assign) CGFloat backgroundAlpha; // for OnScreenController CALayer
// @property (nonatomic, assign) BOOL hasValidPosition;
typedef NS_ENUM(NSInteger, OnScreenButtonType) {
LegacyOscButton,
CustomOnScreenWidget
};
- (id) initWithButtonName:(NSString*)name buttonType:(uint8_t)buttonType andPosition:(CGPoint)position;
+ (BOOL) supportsSecureCoding;
- (void) encodeWithCoder:(NSCoder*)encoder;
- (id) initWithCoder:(NSCoder*)decoder;
@end
NS_ASSUME_NONNULL_END
@@ -1,64 +0,0 @@
//
// OnScreenButtonState.m
// Moonlight
//
// Created by Long Le on 10/20/22.
// Copyright © 2022 Moonlight Game Streaming Project. All rights reserved.
//
#import "OnScreenButtonState.h"
@implementation OnScreenButtonState
- (id) initWithButtonName:(NSString*)name buttonType:(uint8_t)buttonType andPosition:(CGPoint)position {
if ((self = [self init])) {
self.name = name;
//self.isHidden = isHidden;
self.position = position;
self.buttonType = buttonType;
}
return self;
}
+ (BOOL) supportsSecureCoding {
return YES;
}
- (void) encodeWithCoder:(NSCoder*)encoder {
[encoder encodeObject:self.name forKey:@"name"];
[encoder encodeObject:self.alias forKey:@"alias"];
[encoder encodeDouble:self.timestamp forKey:@"timestamp"];
[encoder encodeInt:self.buttonType forKey:@"buttonType"];
[encoder encodeCGPoint:self.position forKey:@"position"];
[encoder encodeBool:self.isHidden forKey:@"isHidden"];
[encoder encodeFloat:self.widthFactor forKey:@"widthFactor"];
[encoder encodeFloat:self.heightFactor forKey:@"heightFactor"];
[encoder encodeFloat:self.sensitivityFactor forKey:@"velocityFactor"];
[encoder encodeFloat:self.stickIndicatorOffset forKey:@"stickIndicatorOffset"];
[encoder encodeFloat:self.oscLayerSizeFactor forKey:@"oscLayerSizeFactor"];
[encoder encodeFloat:self.backgroundAlpha forKey:@"backgroundAlpha"];
[encoder encodeFloat:self.borderWidth forKey:@"borderWidth"];
}
- (id) initWithCoder:(NSCoder*)decoder {
if (self = [super init]) {
self.name = [decoder decodeObjectForKey:@"name"];
self.alias = [decoder decodeObjectForKey:@"alias"];
self.timestamp = [decoder decodeDoubleForKey:@"timestamp"];
self.buttonType = [decoder decodeIntForKey:@"buttonType"];
self.position = [decoder decodeCGPointForKey:@"position"];
self.isHidden = [decoder decodeBoolForKey:@"isHidden"];
self.widthFactor = [decoder decodeFloatForKey:@"widthFactor"];
self.heightFactor = [decoder decodeFloatForKey:@"heightFactor"];
self.sensitivityFactor = [decoder decodeFloatForKey:@"velocityFactor"];
self.stickIndicatorOffset = [decoder decodeFloatForKey:@"stickIndicatorOffset"];
self.oscLayerSizeFactor = [decoder decodeFloatForKey:@"oscLayerSizeFactor"];
self.backgroundAlpha = [decoder decodeFloatForKey:@"backgroundAlpha"];
self.borderWidth = [decoder decodeFloatForKey:@"borderWidth"];
}
return self;
}
@end
+4 -10
View File
@@ -10,19 +10,13 @@
#define CustomTapGestureRecognizer_h
@interface CustomTapGestureRecognizer : UIGestureRecognizer{
CGFloat lowestTouchPointYCoord;
}
@interface CustomTapGestureRecognizer : UIGestureRecognizer
@property (nonatomic, assign) uint8_t numberOfTouchesRequired;
@property (nonatomic, assign) bool immediateTriggering; // if enabled, trigger the signal on touchesBegan stage.
@property (nonatomic, assign) double tapDownTimeThreshold; // tap down threshold in seconds.
@property (nonatomic, assign) bool isOnScreenControllerBeingPressed; // will be set by the onscreencontrol class
//@property (nonatomic, assign) bool haveOnScreenButtonsOnStreamview;
@property (nonatomic, readonly) CGFloat lowestTouchPointHeight;
@property (nonatomic, readonly) bool gestureCaptured;
@property (nonatomic, readonly) NSTimeInterval gestureCapturedTime;
@property (nonatomic, assign) double tapDownTimeThreshold;
@property (atomic, readonly) CGFloat lowestTouchPointHeight;
@end
#endif /* CustomTapGestureRecognizer_h */
+12 -67
View File
@@ -9,104 +9,49 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIGestureRecognizerSubclass.h>
#import "CustomTapGestureRecognizer.h"
#import "Moonlight-Swift.h"
// The most accurate & reliable tap gesture recognizer of iOS:
// - Almost 100% recoginition rate. UITapGestureRecognizer of Apple API fails frequently, just a piece of crap.
// - When immediateTriggering is set to false (for native multi-touch):
// Gesture signal will be triggered on touchesEnded stage, multi finger touch operations will not be interrupted by the arising keyboard.
// Instances of different [numberOfTouchesRequired] barely compete with each other, for example, the chance of 3-finger gesture get triggered by 4 or 5 finger tap is very small.
// - Set property immediateTriggering to true, to ensure the priority of keyboard toggle in non-native touch mode, in compete with 2-finger gestures.
// - This recognizer also provides properties like gestureCapturedTime, to be accessed outside the class for useful purpose.
@implementation CustomTapGestureRecognizer
static NSTimeInterval multiFingerDownTime;
static bool multiFingerDown;
static CGFloat screenHeightInPoints;
static CGFloat screenWidthInPoints;
static CGFloat lowestTouchPointYCoord = 0.0;
- (instancetype)initWithTarget:(nullable id)target action:(nullable SEL)action {
self = [super initWithTarget:target action:action];
screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]);
screenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]);
lowestTouchPointYCoord = 0.0;
_numberOfTouchesRequired = 3;
_immediateTriggering = false;
_tapDownTimeThreshold = 0.3;
_gestureCaptured = false;
_isOnScreenControllerBeingPressed = false;
return self;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// Check if the number of touches and taps meets the required criteria
if ([[event allTouches] count] == _numberOfTouchesRequired) {
_gestureCapturedTime = CACurrentMediaTime();
_gestureCaptured = true;
multiFingerDownTime = CACurrentMediaTime();
multiFingerDown = true;
for(UITouch *touch in [event allTouches]){
if(lowestTouchPointYCoord < [touch locationInView:self.view].y) lowestTouchPointYCoord = [touch locationInView:self.view].y;
}
// this mechanism is deprecated.
/* if(_numberOfTouchesRequired == 2){
NSArray *twoTouches = [[event allTouches] allObjects];
_areVirtualControllerTaps = fabs([twoTouches[1] locationInView:self.view].x - [twoTouches[0] locationInView:self.view].x) > screenWidthInPoints/3;
} */
_lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord;
if(_immediateTriggering){
lowestTouchPointYCoord = 0.0; //reset for next recoginition
self.state = UIGestureRecognizerStateRecognized;
return;
}
self.state = UIGestureRecognizerStatePossible;
}
if ([[event allTouches] count] > _numberOfTouchesRequired) {
_gestureCaptured = false;
self.state = UIGestureRecognizerStateFailed;
}
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// [super touchesEnded:touches withEvent:event];
if(_immediateTriggering) return;
uint8_t allTouchesCount = [[event allTouches] count];
if(allTouchesCount > _numberOfTouchesRequired) {
_gestureCaptured = false;
self.state = UIGestureRecognizerStateFailed;
}
else if(_gestureCaptured && allTouchesCount == [touches count] && !_isOnScreenControllerBeingPressed && ![self isOnScreenWidgetViewBeingPressed]){ //must exclude virtual controller & onscreen button taps here to prevent stucked button, _areVirtualControllerTaps flag is set by onscreencontrols, containOnScreenButtonsTaps will be returned by iterating all widget views in streamframeview
_gestureCaptured = false; //reset for next recognition
if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){
if(multiFingerDown && [[event allTouches] count] == [touches count]){
multiFingerDown = false;
if((CACurrentMediaTime() - multiFingerDownTime) < _tapDownTimeThreshold / 1000){
lowestTouchPointYCoord = 0.0; //reset for next recognition
self.state = UIGestureRecognizerStateRecognized;
}
}
if (allTouchesCount == [touches count]) _isOnScreenControllerBeingPressed = false; // need to reset this flag anyway, when all fingers are lefting
}
// it was a not a perfect choice to code OnScreenWidgetView in Swift...
// we're unable to import this class to swift codebase by the bridging header,and have to exlucde the onscreen button taps here
// by iterating every widget view instances. but it's basically ok since the number of widgetViews are always limited.
// and this method will only be called when the recognizer is active & and the taps passes all the checks and is about to ge triggered.
- (bool)isOnScreenWidgetViewBeingPressed {
NSTimeInterval allFingersTapDownTime = CACurrentMediaTime() - _gestureCapturedTime; //RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S has been passed to this recognizer as _tapDownTimeShreshold, we'll decide how to deal with pressed flag of on-screen widget views based on tapDownTime
bool gotOneWidgetPressed = false;
// the tap gestures are all added to the streamFrameTopLayerView, where all the OnScreenWidgetViews are added. so we can iterate them in this way:
for(UIView* view in self.view.subviews){
if ([view isKindOfClass:[OnScreenWidgetView class]]) {
OnScreenWidgetView* widgetView = (OnScreenWidgetView*) view;
if(gotOneWidgetPressed && allFingersTapDownTime <= _tapDownTimeThreshold){ // once we have just 1 button pressed already,& the tapDownTime has not exceeded the threshold, we'll reset pressed flag for the all the widgetViews.
widgetView.pressed = false; //reset the flag for widgetView
continue;
}
if(widgetView.pressed){
gotOneWidgetPressed = true; //got one button pressed
if(allFingersTapDownTime <= _tapDownTimeThreshold) widgetView.pressed = false; // reset the flag for current widgetView if tapDowntime is still within the threshold, if not, leave the flag for mouse scroller gesture in relative touch mode.
}
}
+ (CGFloat)lowestTouchPointHeight{
@synchronized (self){
return self.lowestTouchPointHeight;
}
return gotOneWidgetPressed;
}
@end
-3
View File
@@ -248,9 +248,6 @@
case UIKeyboardHIDUsageKeyboardRightAlt:
keyCode = 0xA5;
break;
case UIKeyboardHIDUsageKeyboardErrorUndefined:
NSLog(@"Undefined key pressed");
return false;
case 669: // This value corresponds to the "Globe" or "Language" key on most Apple branded iPad keyboards.
keyCode = 0x1B; // This value corresponds to "Escape", which is missing from most Apple branded iPad keyboards.
break;
@@ -2,6 +2,3 @@
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#include <Limelight.h>
#import "OnScreenControls.h"
// #import "RelativeTouchHandler.h"
+17 -8
View File
@@ -2,24 +2,33 @@
// NativeTouchHandler.h
// Moonlight
//
// Created by ZWM on 2024/6/16.
// Created by ZWM on 2024/5/14.
// Copyright © 2024 Moonlight Game Streaming Project. All rights reserved.
//
#import "StreamView.h"
#import "DataManager.h"
#include <Limelight.h>
NS_ASSUME_NONNULL_BEGIN
@interface NativeTouchHandler : UIResponder
@property (nonatomic, assign) NSMutableSet<UITouch *>* touchesCapturedByOnScreenButtons;
@interface TouchPointer : NSObject
- (id)initWithView:(StreamView* )view andSettings:(TemporarySettings*)settings;
+ (void)initContextWith:(StreamView *)view;
+ (void)populatePointerId:(UITouch*)touch;
+ (void)removePointerId:(UITouch*)touch;
+ (uint32_t) retrievePointerIdFromDict:(UITouch*)touch;
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation;
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor;
+ (void)populatePointerObjIntoDict:(UITouch*)touch;
+ (void)removePointerObjFromDict:(UITouch*)touch;
+ (void)updatePointerObjInDict:(UITouch *)touch;
+ (CGPoint)selectCoordsFor:(UITouch *)touch;
- (instancetype)initWith:(UITouch *)touch;
@end
NS_ASSUME_NONNULL_END
+107 -132
View File
@@ -2,163 +2,138 @@
// NativeTouchHandler.m
// Moonlight
//
// Created by ZWM on 2024/6/16.
// Created by ZWM on 2024/5/14.
// Copyright © 2024 Moonlight Game Streaming Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "NativeTouchHandler.h"
#import "NativeTouchPointer.h"
#import "OnScreenControls.h"
#import "StreamView.h"
#include <Limelight.h>
// Use a Dictionary to store UITouch object's memory address as key, and pointerId as value,字典存放UITouch对象地址和pointerId映射关系
// pointerId will be generated from electronic noise, by arc4_random, pointerId,由随机噪声生成
// Use a NSSet store pointerId, for quick repeition inquiry, NSSet存放活跃的pointerId合集,用于快速查找,以防重复.
static NSMutableDictionary *pointerIdDict; //pointerId Dict for native touch.
static NSMutableSet<NSNumber *> *pointerIdSet; //pointerIdSet for native touch.
static NSMutableDictionary *pointerDict;
static CGFloat pointerVelocityFactor;
static CGFloat pointerVelocityDivider;
static CGFloat pointerVelocityDividerLocation;
@implementation NativeTouchHandler {
StreamView* streamView;
TemporarySettings* currentSettings;
bool activateCoordSelector;
bool touchPointSpawnedAtUpperScreenEdge;
// Use a Dictionary to store UITouch object's memory address as key, and pointerId as value,字典存放UITouch对象地址和pointerId映射关系
// pointerId will be generated from a pre-defined pool
// Use a NSSet store active pointerId,
NSMutableDictionary *pointerIdDict; //pointerId Dict for active touches.
NSMutableSet<NSNumber *> *activePointerIds; //pointerId Set for active touches.
NSMutableSet<NSNumber *> *pointerIdPool; //pre-defined pool of pointerIds.
NSMutableSet<NSNumber *> *unassignedPointerIds;
StreamView *streamView;
CGFloat slideGestureVerticalThreshold;
CGFloat screenWidthWithThreshold;
CGFloat EDGE_TOLERANCE;
@implementation TouchPointer{
CGPoint initialPoint;
CGPoint latestPoint;
CGPoint previousPoint;
CGPoint latestRelativePoint;
CGPoint previousRelativePoint;
CGFloat velocityX;
CGFloat velocityY;
}
- (id)initWithView:(StreamView*)view andSettings:(TemporarySettings*)settings{
self = [super init];
self->streamView = view;
self->currentSettings = settings;
self->activateCoordSelector = currentSettings.pointerVelocityModeDivider.floatValue != 1.0;
// self->notPureNativeTouchMode = !(currentSettings.touchMode.intValue == PURE_NATIVE_TOUCH);
self->pointerIdDict = [NSMutableDictionary dictionary];
self->pointerIdPool = [NSMutableSet set];
for (uint8_t i = 0; i <= 10; i++) { //ipadOS supports upto 11 finger touches
[self->pointerIdPool addObject:@(i)];
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation{
pointerVelocityDivider = dividerLocation;
}
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor{
pointerVelocityFactor = velocityFactor;
}
- (instancetype)initWith:(UITouch *)touch{
self = [self init];
self->initialPoint = [touch locationInView:streamView];
self->latestPoint = self->initialPoint;
self->latestRelativePoint = self->initialPoint;
return self;
}
self->activePointerIds = [NSMutableSet set];
// self->excludedPointerIds = [[NSMutableSet alloc] init];
self->touchPointSpawnedAtUpperScreenEdge = false;
EDGE_TOLERANCE = 15.0;
slideGestureVerticalThreshold = CGRectGetHeight([[UIScreen mainScreen] bounds]) * 0.4;
screenWidthWithThreshold = CGRectGetWidth([[UIScreen mainScreen] bounds]) - EDGE_TOLERANCE;
[NativeTouchPointer setPointerVelocityDivider:settings.pointerVelocityModeDivider.floatValue];
[NativeTouchPointer setPointerVelocityFactor:settings.touchPointerVelocityFactor.floatValue];
[NativeTouchPointer initContextWithView:self->streamView];
//_touchesCapturedByOnScreenButtons = [[NSMutableSet alloc] init];
return self;
}
// generate & populate pointerId into NSDict & NSSet, called in touchesBegan
- (void)handleTouchDown:(UITouch*)touch{
//populate pointerId
uintptr_t memAddrValue = (uintptr_t)touch;
unassignedPointerIds = [pointerIdPool mutableCopy]; //reset unassignedPointerIds
[unassignedPointerIds minusSet:activePointerIds];
uint8_t pointerId = [[unassignedPointerIds anyObject] unsignedIntValue];
[pointerIdDict setObject:@(pointerId) forKey:@(memAddrValue)];
[activePointerIds addObject:@(pointerId)];
//check if touch point is spawned on the left or right upper half screen edges, event to remote PC. this is for better handling in-stream slide gesture
CGPoint initialPoint = [touch locationInView:self->streamView];
if(initialPoint.y < slideGestureVerticalThreshold && (initialPoint.x < EDGE_TOLERANCE || initialPoint.x > screenWidthWithThreshold)) {
self->touchPointSpawnedAtUpperScreenEdge = true;
// [excludedPointerIds addObject:@(pointerId)];
- (void)updatePointerCoords:(UITouch *)touch{
previousPoint = latestPoint;
latestPoint = [touch locationInView:streamView];
if (pointerVelocityFactor != 1.0f){
velocityX = latestPoint.x - previousPoint.x;
velocityY = latestPoint.y - previousPoint.y;
previousRelativePoint = latestRelativePoint;
latestRelativePoint.x = previousRelativePoint.x + pointerVelocityFactor * velocityX;
latestRelativePoint.y = previousRelativePoint.y + pointerVelocityFactor * velocityY;
}
}
// remove pointerId in touchesEnded or touchesCancelled
- (void)removePointerId:(UITouch*)touch{
uintptr_t memAddrValue = (uintptr_t)touch;
NSNumber* pointerIdObj = [pointerIdDict objectForKey:@(memAddrValue)];
+ (void)initContextWith:(StreamView *)view{
streamView = view;
pointerIdDict = [NSMutableDictionary dictionary];
pointerIdSet = [NSMutableSet set];
pointerDict = [NSMutableDictionary dictionary];
pointerVelocityDividerLocation = CGRectGetWidth([[UIScreen mainScreen] bounds]) * pointerVelocityDivider;
NSLog(@"pointerVelocityDivider: %.2f", pointerVelocityDivider);
NSLog(@"pointerVelocityDividerLocation: %.2f", pointerVelocityDividerLocation);
}
+ (void)populatePointerObjIntoDict:(UITouch*)touch{
[pointerDict setObject:[[TouchPointer alloc] initWith:touch] forKey:@((uint64_t)touch)];
}
+ (void)removePointerObjFromDict:(UITouch*)touch{
uint64_t eventAddrValue = (uint64_t)touch;
TouchPointer* pointer = [pointerDict objectForKey:@(eventAddrValue)];
if(pointer != nil){
[pointerDict removeObjectForKey:@(eventAddrValue)];
}
}
+ (void)updatePointerObjInDict:(UITouch *)touch{
[[pointerDict objectForKey:@((uint64_t)touch)] updatePointerCoords:touch];
}
+ (CGPoint)selectCoordsFor:(UITouch *)touch{
TouchPointer *pointer = [pointerDict objectForKey:@((uint64_t)touch)];
if((pointer -> initialPoint).x > pointerVelocityDividerLocation){ //if first contact coords locates on the right side of divider.
return pointer->latestRelativePoint;
}
return [touch locationInView:streamView];
}
// 随机生成pointerId并填入NSDict和NSSet
// generate & populate pointerId into NSDict & NSSet, called in UITouchPhaseBegan
+ (void)populatePointerId:(UITouch*)touch{
uint64_t eventAddrValue = (uint64_t)touch;
uint32_t randomPointerId = arc4random_uniform(UINT32_MAX); // generate pointerId from eletronic noise.
for(;;){
if([pointerIdSet containsObject:@(randomPointerId)]) randomPointerId = arc4random_uniform(UINT32_MAX); // in case of new pointerId collides with existing ones, generate again.
else{ // populate pointerId into NSDict & NSSet.
[pointerIdDict setObject:@(randomPointerId) forKey:@(eventAddrValue)];
[pointerIdSet addObject:@(randomPointerId)];
return;
}
}
}
// remove pointerId in UITouchPhaseEnded condition
+ (void)removePointerId:(UITouch*)touch{
uint64_t eventAddrValue = (uint64_t)touch;
NSNumber* pointerIdObj = [pointerIdDict objectForKey:@(eventAddrValue)];
if(pointerIdObj != nil){
[activePointerIds removeObject:pointerIdObj];
[pointerIdDict removeObjectForKey:@(memAddrValue)];
// if([excludedPointerIds containsObject:pointerIdObj]) [excludedPointerIds removeObject:pointerIdObj]; // remove pointer id from excludedPointerId NSSet
[pointerIdSet removeObject:pointerIdObj];
[pointerIdDict removeObjectForKey:@(eventAddrValue)];
}
}
// 从字典中获取UITouch事件对应的pointerId
// called in method of sendTouchEvent
- (uint8_t) retrievePointerIdFromDict:(UITouch*)touch{
return [[pointerIdDict objectForKey:@((uintptr_t)touch)] unsignedIntValue];
// call this only when NSDcit & NSSet is up-to-date.
+ (uint32_t) retrievePointerIdFromDict:(UITouch*)touch{
return [[pointerIdDict objectForKey:@((uint64_t)touch)] unsignedIntValue];
}
- (void)sendTouchEvent:(UITouch*)touch withTouchtype:(uint8_t)touchType{
if(touchPointSpawnedAtUpperScreenEdge) return; // we're done here. this touch event will not be sent to the remote PC. and this must be checked after coord selector finishes populating new relative coords, or the app will crash!
CGPoint targetCoords;
// NSLog(@"excluded count: %d", (uint32_t)[excludedPointerIds count]);
if(activateCoordSelector && touch.phase == UITouchPhaseMoved) targetCoords = [NativeTouchPointer selectCoordsFor:touch]; // coordinates of touch pointer replaced to relative ones here.
else targetCoords = [touch locationInView:streamView];
CGPoint location = [streamView adjustCoordinatesForVideoArea:targetCoords];
CGSize videoSize = [streamView getVideoAreaSize];
CGFloat normalizedX = location.x / videoSize.width;
CGFloat normalizedY = location.y / videoSize.height;
uint8_t pointerId = [self retrievePointerIdFromDict:touch];
if([NativeTouchPointer getPointerObjFromDict:touch].needResetCoords){ // access whether the current pointer has reached the boundary, and need a coord reset.
LiSendTouchEvent(LI_TOUCH_EVENT_UP, pointerId, normalizedX, normalizedY, 0, 0, 0, 0); //event must sent from the lowest level directy by LiSendTouchEvent to simulate continous dragging to another point on screen
LiSendTouchEvent(LI_TOUCH_EVENT_DOWN, pointerId, 0.3, 0.4, 0, 0, 0, 0);
}else LiSendTouchEvent(touchType, pointerId, normalizedX, normalizedY,(touch.force / touch.maximumPossibleForce) / sin(touch.altitudeAngle),0.0f, 0.0f,[streamView getRotationFromAzimuthAngle:[touch azimuthAngleInView:streamView]]);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch* touch in touches){
// continue to the next loop if current touch is already captured by OSC. works only in regular native touch
if([OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) continue;
[self handleTouchDown:touch]; //generate & populate pointerId
if(activateCoordSelector) [NativeTouchPointer populatePointerObjIntoDict:touch];
[self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_DOWN];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// NSLog(@"captured by OSB touches: %d", (uint32_t)[OnScreenControls.touchAddrsCapturedByOnScreenControls count]);
for (UITouch* touch in touches){
// continue to the next loop if current touch is already captured by OSC. works only in regular native touch
if([OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) continue;
if(activateCoordSelector) [NativeTouchPointer updatePointerObjInDict:touch];
[self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_MOVE];
[[NativeTouchPointer getPointerObjFromDict:touch] doesNeedResetCoords]; // execute the judging of doesReachBoundary for current pointer instance. (happens after the event is sent to Sunshine service)
}
return;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch* touch in touches){
// continue to the next loop if current touch is already captured by OSC. works only in regular native touch
if([OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) continue;
[self sendTouchEvent:touch withTouchtype:LI_TOUCH_EVENT_UP]; //send touch event before remove pointerId
[self removePointerId:touch]; //then remove pointerId
if(activateCoordSelector) [NativeTouchPointer removePointerObjFromDict:touch];
}
if(touchPointSpawnedAtUpperScreenEdge && [[event allTouches] count] == [touches count]) touchPointSpawnedAtUpperScreenEdge = false;
return;
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesEnded:touches withEvent:event];
}
@end
-37
View File
@@ -1,37 +0,0 @@
//
// NativeTouchPointer.h
// Moonlight
//
// Created by ZWM on 2024/5/14.
// Copyright © 2024 Moonlight Game Streaming Project. All rights reserved.
//
#import "StreamView.h"
#import "NativeTouchHandler.h"
NS_ASSUME_NONNULL_BEGIN
@interface NativeTouchPointer : NSObject
@property (nonatomic, assign) bool needResetCoords;
+ (void)initContextWithView:(StreamView *)view;
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation;
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor;
+ (NativeTouchPointer* )getPointerObjFromDict:(UITouch*)touch;
- (bool)doesNeedResetCoords;
+ (void)populatePointerObjIntoDict:(UITouch*)touch;
+ (void)removePointerObjFromDict:(UITouch*)touch;
+ (void)updatePointerObjInDict:(UITouch *)touch;
+ (CGPoint)selectCoordsFor:(UITouch *)touch;
- (instancetype)initWithTouch:(UITouch *)touch;
@end
NS_ASSUME_NONNULL_END
-125
View File
@@ -1,125 +0,0 @@
//
// NativeTouchPointer.m
// Moonlight
//
// Created by ZWM on 2024/5/14.
// Copyright © 2024 Moonlight Game Streaming Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "NativeTouchPointer.h"
#include <Limelight.h>
// native touch pointer ojbect that stores & manipulates touch coordinates
static NSMutableDictionary *pointerObjDict;
static CGFloat pointerVelocityFactor;
static CGFloat pointerVelocityDivider;
static CGFloat pointerVelocityDividerLocationByPoints;
static CGFloat streamViewHeight;
static CGFloat streamViewWidth;
static CGFloat fixedResetCoordX;
static CGFloat fixedResetCoordY;
static StreamView* _streamView;
@implementation NativeTouchPointer{
CGPoint initialPoint;
CGPoint latestPoint;
CGPoint previousPoint;
CGPoint latestRelativePoint;
CGPoint previousRelativePoint;
bool useRelativeCoords;
}
- (instancetype)initWithTouch:(UITouch *)touch{
self = [super init];
self->initialPoint = [touch locationInView:_streamView];
self->latestPoint = self->initialPoint;
self->latestRelativePoint = self->initialPoint;
return self;
}
- (bool)doesNeedResetCoords{
bool boundaryReached = (latestRelativePoint.x > streamViewWidth || latestRelativePoint.x < 0.0f || latestRelativePoint.y > streamViewHeight || latestRelativePoint.y < 0.0f);
bool withinExcludedArea = (initialPoint.x > streamViewWidth * (0.75) && initialPoint.x < streamViewWidth) && (initialPoint.y > streamViewHeight * (0.8) && initialPoint.y < streamViewHeight);
_needResetCoords = (pointerVelocityFactor > 1.0f) && self->useRelativeCoords && boundaryReached && !withinExcludedArea;
// boundary detection & coordinates reset to the specific point for HK:StarTrail(needs a very high pointer velocity)
// must exclude touch pointer that uses native coords instead of relative ones.
// also exclude touch pointer created within the bottom right corner
return _needResetCoords;
}
- (void)updatePointerCoords:(UITouch *)touch{
previousPoint = latestPoint;
latestPoint = [touch locationInView:_streamView];
previousRelativePoint = latestRelativePoint;
if(_needResetCoords){// boundary detection & coordinates reset to the central screen point for HK:StarTrail(needs a very high pointer velocity); // boundary detection & coordinates reset to specific point for HK:StarTrail(needs a very high pointer velocity)
previousRelativePoint.x = fixedResetCoordX;
previousRelativePoint.y = fixedResetCoordY;
}
latestRelativePoint.x = previousRelativePoint.x + pointerVelocityFactor * (latestPoint.x - previousPoint.x);
latestRelativePoint.y = previousRelativePoint.y + pointerVelocityFactor * (latestPoint.y - previousPoint.y);
}
+ (void)initContextWithView:(StreamView *)view {
_streamView = view;
streamViewWidth = _streamView.frame.size.width;
fixedResetCoordX = streamViewWidth * 0.3;
streamViewHeight = _streamView.frame.size.height;
fixedResetCoordY = streamViewHeight * 0.4;
NSLog(@"stream wdith %f, stream height %f", streamViewWidth, streamViewHeight);
pointerObjDict = [NSMutableDictionary dictionary];
pointerVelocityDividerLocationByPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]) * pointerVelocityDivider;
NSLog(@"pointerVelocityDivider: %.2f", pointerVelocityDivider);
NSLog(@"pointerVelocityFactor: %.2f", pointerVelocityFactor);
NSLog(@"pointerVelocityDividerLocationByPoints: %.2f", pointerVelocityDividerLocationByPoints);
}
+ (void)setPointerVelocityDivider:(CGFloat)dividerLocation{
pointerVelocityDivider = dividerLocation;
}
+ (void)setPointerVelocityFactor:(CGFloat)velocityFactor{
pointerVelocityFactor = velocityFactor;
}
+ (void)populatePointerObjIntoDict:(UITouch*)touch{
[pointerObjDict setObject:[[NativeTouchPointer alloc] initWithTouch:touch] forKey:@((uintptr_t)touch)];
}
+ (void)removePointerObjFromDict:(UITouch*)touch{
uintptr_t memAddrValue = (uintptr_t)touch;
NativeTouchPointer* pointer = [pointerObjDict objectForKey:@(memAddrValue)];
if(pointer != nil){
[pointerObjDict removeObjectForKey:@(memAddrValue)];
}
}
+ (NativeTouchPointer* )getPointerObjFromDict:(UITouch*)touch{
return [pointerObjDict objectForKey:@((uintptr_t)touch)];
}
+ (void)updatePointerObjInDict:(UITouch *)touch{
[[pointerObjDict objectForKey:@((uintptr_t)touch)] updatePointerCoords:touch];
}
+ (CGPoint)selectCoordsFor:(UITouch *)touch{
NativeTouchPointer *pointer = [pointerObjDict objectForKey:@((uintptr_t)touch)];
if(pointer == nil) return CGPointMake(0, 0);
if((pointer -> initialPoint).x > pointerVelocityDividerLocationByPoints){ //if first contact coords locates on the right side of divider.
pointer -> useRelativeCoords = true;
return pointer->latestRelativePoint;
}
else{
pointer -> useRelativeCoords = false;
return[touch locationInView:_streamView];
}
}
@end
+4 -104
View File
@@ -7,130 +7,30 @@
//
#import <Foundation/Foundation.h>
#import "ControllerSupport.h"
#import "CustomTapGestureRecognizer.h"
#import "OSCProfile.h"
#define MIN_CONTROLLER_LAYER_ALPHA 0.23
@class ControllerSupport;
@class StreamConfiguration;
// sending self as an instance to OnScreenWidgetView or other related classes
@protocol InstanceProviderDelegate <NSObject>
- (void)getOnScreenControlsInstance:(id)sender; // Renamed delegate method
@end
static const float D_PAD_DIST = 10;
static const float BUTTON_DIST = 20;
@interface OnScreenControls : NSObject{
@protected
CGFloat _leftStickSizeFactor;
CGFloat _leftStickOpacity;
CGFloat _rightStickSizeFactor;
CGFloat _rightStickOpacity;
CGFloat _dPadSizeFactor;
}
@interface OnScreenControls : NSObject
typedef NS_ENUM(NSInteger, OnScreenControlsLevel) {
OnScreenControlsLevelOff,
OnScreenControlsLevelAuto,
OnScreenControlsLevelSimple,
OnScreenControlsLevelFull,
OnScreenControlsLevelCustom,
OnScreenControlsLevelAuto, // move it here instead of delete , to ensure integrity of the codes
// Internal levels selected by ControllerSupport
OnScreenControlsLevelAutoGCGamepad,
OnScreenControlsLevelAutoGCExtendedGamepad,
OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons
};
@property (nonatomic, weak) id<InstanceProviderDelegate> delegate; // Delegate property
- (void)sendInstance;
// @property (nonatomic, assign) CustomTapGestureRecognizer* mouseRightClickTapRecognizer; // this object will be passed to onscreencontrols class for areVirtualControllerTaps flag setting
@property (nonatomic, assign) bool isLayingOut;
//@property (nonatomic) NSMutableSet<UITouch* >* touchesCapturedByOnScreenButtons;
@property (nonatomic, assign) CGRect standardRoundButtonBounds;
@property (nonatomic, assign) CGRect standardRectangleButtonBounds;
@property (nonatomic, assign) CGRect standardStickBounds;
@property (nonatomic, assign) CGRect standardStickBackgroundBounds;
@property (nonatomic, assign) CGRect standardUpDownButtonBounds;
@property (nonatomic, assign) CGRect standardLeftRightButtonBounds;
@property (nonatomic, assign) CGPoint leftStickCenter;
@property (nonatomic, assign) CGPoint rightStickCenter;
@property CALayer* _aButton;
@property (nonatomic, assign) CGFloat aButtonSizeFactor;
@property CALayer* _bButton;
@property (nonatomic, assign) CGFloat bButtonSizeFactor;
@property CALayer* _xButton;
@property (nonatomic, assign) CGFloat xButtonSizeFactor;
@property CALayer* _yButton;
@property (nonatomic, assign) CGFloat yButtonSizeFactor;
@property CALayer* _startButton;
@property CALayer* _selectButton;
@property CALayer* _r1Button;
@property CALayer* _r2Button;
@property CALayer* _r3Button;
@property CALayer* _l1Button;
@property CALayer* _l2Button;
@property CALayer* _l3Button;
@property CALayer* _upButton;
@property CALayer* _downButton;
@property CALayer* _leftButton;
@property CALayer* _rightButton;
@property CALayer* _leftStickBackground;
@property CALayer* _leftStick;
@property CALayer* _rightStickBackground;
@property CALayer* _rightStick;
@property CALayer* _dPadBackground; // parent layer that contains each individual dPad button so user can drag them around the screen together
@property float D_PAD_CENTER_X;
@property float D_PAD_CENTER_Y;
@property OnScreenControlsLevel _level;
@property NSMutableArray *OSCButtonLayers;
+ (NSMutableSet* )touchAddrsCapturedByOnScreenControls;
+ (void) testMethod;
- (void) sendRightStickTouchPadEvent:(CGFloat) stickX : (CGFloat) stickY;
- (void) clearRightStickTouchPadFlag;
- (void) sendLeftStickTouchPadEvent:(CGFloat) stickX : (CGFloat) stickY;
- (void) clearLeftStickTouchPadFlag;
- (void) pressDownControllerButton: (int)flag;
- (void) releaseControllerButton: (int)flag;
- (void) updateLeftTrigger:(unsigned char)input;
- (void) updateRightTrigger:(unsigned char)input;
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport streamConfig:(StreamConfiguration*)streamConfig;
- (BOOL) handleTouchDownEvent:(NSSet*)touches;
- (BOOL) handleTouchUpEvent:(NSSet*)touches;
- (BOOL) handleTouchMovedEvent:(NSSet*)touches;
- (void) setLevel:(OnScreenControlsLevel)level;
- (void) show;
- (void) setupComplexControls;
- (void) drawButtons;
- (void) drawBumpers;
- (void) updateControls;
- (OnScreenControlsLevel) getLevel;
- (void) setDPadCenter;
- (void) setAnalogStickPositions;
- (void) positionAndResizeSingleControllerLayers;
- (void) resizeControllerLayerWith:(CALayer*)layer and:(CGFloat)sizeFactor;
- (void) adjustControllerLayerOpacityWith:(CALayer*)layer and:(CGFloat)alpha;
+ (CGFloat) getControllerLayerSizeFactor:(CALayer*)layer;
- (CGFloat) getControllerLayerOpacity:(CALayer*)layer;
- (void) show;
@end
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More