Define CustomTapGestureRecognizer to reliably toggle local keyboard, better than UITapGestureRecognizer
This commit is contained in:
1 parent
208688afe1
commit
b1b0be886e
4 files changed
+71
-5
No files matched your search
@@ -86,7 +86,6 @@
|
|||||||
self.absoluteTouchMode = settings.absoluteTouchMode;
|
self.absoluteTouchMode = settings.absoluteTouchMode;
|
||||||
self.statsOverlay = settings.statsOverlay;
|
self.statsOverlay = settings.statsOverlay;
|
||||||
|
|
||||||
self.keyboardToggleTaps = @1;
|
|
||||||
self.keyboardToggleFingers = @4;
|
self.keyboardToggleFingers = @4;
|
||||||
#endif
|
#endif
|
||||||
self.uniqueId = settings.uniqueId;
|
self.uniqueId = settings.uniqueId;
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
//
|
||||||
|
// CustomTapGestureRecognizer.h
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Admin on 2024/5/15.
|
||||||
|
// Copyright © 2024 Moonlight Game Streaming Project. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef CustomTapGestureRecognizer_h
|
||||||
|
#define CustomTapGestureRecognizer_h
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@interface CustomTapGestureRecognizer : UIGestureRecognizer
|
||||||
|
|
||||||
|
@property (nonatomic, assign) uint8_t numberOfTouchesRequired;
|
||||||
|
@property (nonatomic, assign) double tapDownTimeThreshold;
|
||||||
|
|
||||||
|
@end
|
||||||
|
#endif /* CustomTapGestureRecognizer_h */
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// CustomTapGestureRecognizer.m
|
||||||
|
// Moonlight
|
||||||
|
//
|
||||||
|
// Created by Admin on 2024/5/15.
|
||||||
|
// Copyright © 2024 Moonlight Game Streaming Project. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <UIKit/UIGestureRecognizerSubclass.h>
|
||||||
|
#import "CustomTapGestureRecognizer.h"
|
||||||
|
|
||||||
|
@implementation CustomTapGestureRecognizer
|
||||||
|
|
||||||
|
static NSTimeInterval multiFingerDownTime;
|
||||||
|
static bool multiFingerDown;
|
||||||
|
|
||||||
|
- (instancetype)initWithTarget:(nullable id)target action:(nullable SEL)action {
|
||||||
|
self = [super initWithTarget:target action:action];
|
||||||
|
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) {
|
||||||
|
multiFingerDownTime = CACurrentMediaTime();
|
||||||
|
multiFingerDown = true;
|
||||||
|
self.state = UIGestureRecognizerStatePossible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||||
|
// [super touchesEnded:touches withEvent:event];
|
||||||
|
if(multiFingerDown && [[event allTouches] count] == [touches count]){
|
||||||
|
multiFingerDown = false;
|
||||||
|
if((CACurrentMediaTime() - multiFingerDownTime) < _tapDownTimeThreshold / 1000) self.state = UIGestureRecognizerStateRecognized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -15,6 +15,8 @@
|
|||||||
#import "RelativeTouchHandler.h"
|
#import "RelativeTouchHandler.h"
|
||||||
#import "AbsoluteTouchHandler.h"
|
#import "AbsoluteTouchHandler.h"
|
||||||
#import "KeyboardInputField.h"
|
#import "KeyboardInputField.h"
|
||||||
|
#import "CustomTapGestureRecognizer.h"
|
||||||
|
|
||||||
|
|
||||||
static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
||||||
|
|
||||||
@@ -24,7 +26,6 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
KeyboardInputField* keyInputField;
|
KeyboardInputField* keyInputField;
|
||||||
BOOL isInputingText;
|
BOOL isInputingText;
|
||||||
NSMutableSet* keysDown;
|
NSMutableSet* keysDown;
|
||||||
uint32_t keyboardToggleFingers;
|
|
||||||
float streamAspectRatio;
|
float streamAspectRatio;
|
||||||
|
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
BOOL hasUserInteracted;
|
BOOL hasUserInteracted;
|
||||||
|
|
||||||
NSDictionary<NSString *, NSNumber *> *dictCodes;
|
NSDictionary<NSString *, NSNumber *> *dictCodes;
|
||||||
|
CustomTapGestureRecognizer *keyboardToggleRecognizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setupStreamView:(ControllerSupport*)controllerSupport
|
- (void) setupStreamView:(ControllerSupport*)controllerSupport
|
||||||
@@ -67,8 +69,13 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
[keyInputField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
|
[keyInputField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
|
||||||
[keyInputField setSpellCheckingType:UITextSpellCheckingTypeNo];
|
[keyInputField setSpellCheckingType:UITextSpellCheckingTypeNo];
|
||||||
[self addSubview:keyInputField];
|
[self addSubview:keyInputField];
|
||||||
keyboardToggleFingers = settings.keyboardToggleFingers.intValue;
|
|
||||||
//[self addGestureRecognizer:_keyboardToggleTapRecognizer];
|
keyboardToggleRecognizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleKeyboard)];
|
||||||
|
keyboardToggleRecognizer.numberOfTouchesRequired = settings.keyboardToggleFingers.intValue;
|
||||||
|
keyboardToggleRecognizer.tapDownTimeThreshold = 300.0; // tap down time threshold in milli seconds.
|
||||||
|
keyboardToggleRecognizer.delaysTouchesBegan = NO;
|
||||||
|
keyboardToggleRecognizer.delaysTouchesEnded = NO;
|
||||||
|
[self addGestureRecognizer:keyboardToggleRecognizer];
|
||||||
|
|
||||||
#if TARGET_OS_TV
|
#if TARGET_OS_TV
|
||||||
// tvOS requires RelativeTouchHandler to manage Apple Remote input
|
// tvOS requires RelativeTouchHandler to manage Apple Remote input
|
||||||
@@ -480,7 +487,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
// is triggered.
|
// is triggered.
|
||||||
[touchHandler touchesBegan:touches withEvent:event];
|
[touchHandler touchesBegan:touches withEvent:event];
|
||||||
|
|
||||||
if ([[event allTouches] count] == keyboardToggleFingers) [self toggleKeyboard];
|
// if ([[event allTouches] count] == keyboardToggleFingers) [self toggleKeyboard];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user