toolbox local soft keyboard toggle

This commit is contained in:
TrueZhuanjia committed 2025-07-02 17:02:20 +08:00
1 parent 14a384436c
commit a07e94ca74
5 files changed
+72 -10

No files matched your search

@@ -53,6 +53,7 @@ static CGFloat screenWidthInPoints;
} */ } */
_lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord; _lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord;
NSLog(@"gen _lowestTouchPointHeight %f markmark", _lowestTouchPointHeight);
if(_immediateTriggering){ if(_immediateTriggering){
lowestTouchPointYCoord = 0.0; //reset for next recoginition lowestTouchPointYCoord = 0.0; //reset for next recoginition
self.state = UIGestureRecognizerStateRecognized; self.state = UIGestureRecognizerStateRecognized;
@@ -68,6 +69,7 @@ static CGFloat screenWidthInPoints;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// [super touchesEnded:touches withEvent:event]; // [super touchesEnded:touches withEvent:event];
if(_immediateTriggering) return; if(_immediateTriggering) return;
uint8_t allTouchesCount = [[event allTouches] count]; uint8_t allTouchesCount = [[event allTouches] count];
if(allTouchesCount > _numberOfTouchesRequired) { if(allTouchesCount > _numberOfTouchesRequired) {
@@ -79,6 +81,7 @@ static CGFloat screenWidthInPoints;
if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){ if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){
lowestTouchPointYCoord = 0.0; //reset for next recognition lowestTouchPointYCoord = 0.0; //reset for next recognition
self.state = UIGestureRecognizerStateRecognized; self.state = UIGestureRecognizerStateRecognized;
NSLog(@"gen _lowestTouchPointHeight %f markmark touchesEnd", _lowestTouchPointHeight);
} }
} }
if (allTouchesCount == [touches count]) _isOnScreenControllerBeingPressed = false; // need to reset this flag anyway, when all fingers are lefting if (allTouchesCount == [touches count]) _isOnScreenControllerBeingPressed = false; // need to reset this flag anyway, when all fingers are lefting
+3
View File
@@ -35,6 +35,8 @@
@property (assign, nonatomic) UIView* streamFrameTopLayerView; @property (assign, nonatomic) UIView* streamFrameTopLayerView;
@property (assign, nonatomic) CGFloat streamAspectRatio; @property (assign, nonatomic) CGFloat streamAspectRatio;
@property (assign, nonatomic) CGRect originalFrame;
- (void) setupStreamView:(ControllerSupport*)controllerSupport - (void) setupStreamView:(ControllerSupport*)controllerSupport
interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate
@@ -57,6 +59,7 @@
- (OnScreenControlsLevel) getCurrentOscState; - (OnScreenControlsLevel) getCurrentOscState;
-(void)readyToBringUpSoftKeyboardByToolbox;
- (void)keyboardWillShow:(NSNotification *)notification; - (void)keyboardWillShow:(NSNotification *)notification;
- (void)keyboardWillHide; - (void)keyboardWillHide;
+53 -7
View File
@@ -23,6 +23,7 @@
#import "AbsoluteTouchHandler.h" #import "AbsoluteTouchHandler.h"
#import "KeyboardInputField.h" #import "KeyboardInputField.h"
#import "CustomTapGestureRecognizer.h" #import "CustomTapGestureRecognizer.h"
#import "LocalizationHelper.h"
static const double X1_MOUSE_SPEED_DIVISOR = 2.5; static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
@@ -70,6 +71,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
UIHoverGestureRecognizer *stylusHoverRecognizer; UIHoverGestureRecognizer *stylusHoverRecognizer;
#endif #endif
CGFloat HeightViewLiftedTo; CGFloat HeightViewLiftedTo;
UILabel* keyboardToggleTip;
UIKeyModifierFlags comboKeyModifierFlags; UIKeyModifierFlags comboKeyModifierFlags;
} }
@@ -99,17 +101,19 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[self addSubview:keyInputField]; [self addSubview:keyInputField];
isInputingText = false; isInputingText = false;
keyboardToggleRecognizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleKeyboard)]; [self refreshKeyboardToggleRecognizer:settings.keyboardToggleFingers.intValue]; //will be
keyboardToggleRecognizer.numberOfTouchesRequired = settings.keyboardToggleFingers.intValue; //will be changed accordinly by touch modes. keyboardToggleTip = [[UILabel alloc] init];
keyboardToggleRecognizer.tapDownTimeThreshold = 0.2; // tap down time threshold in seconds. keyboardToggleTip.frame = CGRectMake(0, 0, 35, 100);
keyboardToggleRecognizer.delaysTouchesBegan = NO; keyboardToggleTip.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
keyboardToggleRecognizer.delaysTouchesEnded = NO; keyboardToggleTip.text = [LocalizationHelper localizedStringForKey:@"Tap where you're going to input text"];
keyboardToggleTip.font = [UIFont systemFontOfSize:28];
keyboardToggleTip.userInteractionEnabled = false;
NSLog(@"setup streamView %f", CACurrentMediaTime()); NSLog(@"setup streamView %f", CACurrentMediaTime());
// if(settings.touchMode.intValue == NativeTouchOnly) [self addGestureRecognizer:keyboardToggleRecognizer]; //keep legacy approach in pure native mode // if(settings.touchMode.intValue == NativeTouchOnly) [self addGestureRecognizer:keyboardToggleRecognizer]; //keep legacy approach in pure native mode
// else [self->streamFrameTopLayerView addGestureRecognizer:keyboardToggleRecognizer]; //add to the superview in other modes // else [self->streamFrameTopLayerView addGestureRecognizer:keyboardToggleRecognizer]; //add to the superview in other modes
[self->streamFrameTopLayerView addGestureRecognizer:keyboardToggleRecognizer]; //add to the superview in other modes // [self->streamFrameTopLayerView addGestureRecognizer:keyboardToggleRecognizer]; //add to the superview in other modes
#if TARGET_OS_TV #if TARGET_OS_TV
// tvOS requires RelativeTouchHandler to manage Apple Remote input // tvOS requires RelativeTouchHandler to manage Apple Remote input
@@ -212,11 +216,23 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[self becomeFirstResponder]; [self becomeFirstResponder];
} }
- (void)refreshKeyboardToggleRecognizer:(uint8_t)numberOfTouches{
[self->_streamFrameTopLayerView removeGestureRecognizer:keyboardToggleRecognizer];
keyboardToggleRecognizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleKeyboard)];
keyboardToggleRecognizer.numberOfTouchesRequired = numberOfTouches; //will be changed accordinly by touch modes.
keyboardToggleRecognizer.tapDownTimeThreshold = 0.2; // tap down time threshold in seconds.
keyboardToggleRecognizer.delaysTouchesBegan = NO;
keyboardToggleRecognizer.delaysTouchesEnded = NO;
[self->_streamFrameTopLayerView addGestureRecognizer:keyboardToggleRecognizer];
}
- (void)keyboardWillShow:(NSNotification *)notification{ - (void)keyboardWillShow:(NSNotification *)notification{
NSLog(@"keyboard will show markmark %f", CACurrentMediaTime());
if(settings.liftStreamViewForKeyboard && !isInputingText){ if(settings.liftStreamViewForKeyboard && !isInputingText){
NSDictionary *userInfo = notification.userInfo; NSDictionary *userInfo = notification.userInfo;
// Get the keyboard size from the notification // Get the keyboard size from the notification
CGRect keyboardFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGRect keyboardFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSLog(@"keyboard will show markmark, lowest height %f", keyboardToggleRecognizer.lowestTouchPointHeight);
if(keyboardFrame.size.height < CGRectGetHeight([[UIScreen mainScreen] bounds]) * 0.25) return; // return in case of abnormal keyboard height if(keyboardFrame.size.height < CGRectGetHeight([[UIScreen mainScreen] bounds]) * 0.25) return; // return in case of abnormal keyboard height
HeightViewLiftedTo = keyboardFrame.size.height - keyboardToggleRecognizer.lowestTouchPointHeight + CGRectGetHeight([[UIScreen mainScreen] bounds]) * 0.1; // lift the StreamView to the height of lowest touch point of multi-finger tap gesture, while reserving the view of 1/10 screen height for remote typing. HeightViewLiftedTo = keyboardFrame.size.height - keyboardToggleRecognizer.lowestTouchPointHeight + CGRectGetHeight([[UIScreen mainScreen] bounds]) * 0.1; // lift the StreamView to the height of lowest touch point of multi-finger tap gesture, while reserving the view of 1/10 screen height for remote typing.
if(HeightViewLiftedTo < 0) HeightViewLiftedTo = 0; // set HeightViewLiftedTo to 0 if it is high enough and not going to be covered by keyboard. if(HeightViewLiftedTo < 0) HeightViewLiftedTo = 0; // set HeightViewLiftedTo to 0 if it is high enough and not going to be covered by keyboard.
@@ -224,24 +240,52 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
liftedStreamFrame.origin.y -= HeightViewLiftedTo; liftedStreamFrame.origin.y -= HeightViewLiftedTo;
self.frame = liftedStreamFrame; self.frame = liftedStreamFrame;
isInputingText = true; isInputingText = true;
[self refreshKeyboardToggleRecognizer:settings.keyboardToggleFingers.intValue];
} }
NSLog(@"keyboard will show %f", CACurrentMediaTime()); NSLog(@"keyboard will show %f", CACurrentMediaTime());
} }
// this method also deals with recovering streamview when local keyboard is turned off // this method also deals with recovering streamview when local keyboard is turned off
- (void)keyboardWillHide{ - (void)keyboardWillHide{
NSLog(@"keyboard will hide markmark %f", CACurrentMediaTime());
keyboardToggleRecognizer.numberOfTouchesRequired = settings.keyboardToggleFingers.intValue; // reset this number
if(isInputingText){ if(isInputingText){
/*
CGRect liftedStreamFrame = self.frame; CGRect liftedStreamFrame = self.frame;
// recover view position in keyboard hiding. // recover view position in keyboard hiding.
liftedStreamFrame.origin.y += HeightViewLiftedTo; liftedStreamFrame.origin.y += HeightViewLiftedTo;
self.frame = liftedStreamFrame; self.frame = liftedStreamFrame;
isInputingText = false; isInputingText = false;
*/
self.frame = _originalFrame;
isInputingText = NO;
} }
} }
-(void)readyToBringUpSoftKeyboardByToolbox{
NSLog(@"change num of fingers required");
[self refreshKeyboardToggleRecognizer:1];
keyboardToggleTip.translatesAutoresizingMaskIntoConstraints = NO;
NSLog(@"tip obj: %@", keyboardToggleTip);
/*[self addSubview:keyboardToggleTip];
[NSLayoutConstraint activateConstraints:@[
[keyboardToggleTip.centerXAnchor constraintEqualToAnchor:self.centerXAnchor constant:0],
//[keyboardToggleTip.centerYAnchor constraintEqualToAnchor:self.centerYAnchor constant:-self.bounds.size.height*0.75],
[keyboardToggleTip.centerYAnchor constraintEqualToAnchor:self.centerYAnchor constant:0],
[keyboardToggleTip.widthAnchor constraintEqualToConstant:100],
[keyboardToggleTip.heightAnchor constraintEqualToConstant:30]
// reserve height for navigation bar
]];
*/
}
- (void)toggleKeyboard{ - (void)toggleKeyboard{
NSLog(@"toggleKeyboard markmark, %d", isInputingText);
if (isInputingText) { if (isInputingText) {
Log(LOG_D, @"Closing the keyboard"); Log(LOG_D, @"Closing the keyboard");
[keyInputField resignFirstResponder]; [keyInputField resignFirstResponder];
@@ -272,6 +316,8 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[keyInputField addTarget:self action:@selector(onKeyboardPressed:) forControlEvents:UIControlEventEditingChanged]; [keyInputField addTarget:self action:@selector(onKeyboardPressed:) forControlEvents:UIControlEventEditingChanged];
// Undo causes issues for our state management, so turn it off // Undo causes issues for our state management, so turn it off
[keyInputField.undoManager disableUndoRegistration]; [keyInputField.undoManager disableUndoRegistration];
//[keyboardToggleTip removeFromSuperview];
} }
} }
@@ -226,7 +226,7 @@
[super viewDidAppear:animated]; [super viewDidAppear:animated];
_deviceWindow = self.view.window; _deviceWindow = self.view.window;
if (UIScreen.screens.count > 1 && [self isAirPlayEnabled]) { if (UIScreen.screens.count > 1 && [self isAirPlayEnabled]) {
[self prepExtScreen:UIScreen.screens.lastObject]; [self prepExtScreen:UIScreen.screens.lastObject];
} }
@@ -241,6 +241,8 @@
if(self->_settings.externalDisplayMode.intValue != 2) [self->_streamView insertSubview:self->_streamVideoRenderView atIndex:0]; if(self->_settings.externalDisplayMode.intValue != 2) [self->_streamView insertSubview:self->_streamVideoRenderView atIndex:0];
}); });
} }
self->_streamView.originalFrame = self->_streamView.frame;
// check to see if external screen is connected/disconnected // check to see if external screen is connected/disconnected
@@ -511,6 +513,10 @@
}]; }];
} }
- (void)bringUpSoftKeyboard{
[self->_streamView readyToBringUpSoftKeyboardByToolbox];
}
- (void)oscLayoutClosed{ - (void)oscLayoutClosed{
// Handle the callback // Handle the callback
[self->_streamView disableOnScreenControls]; // add this to get realtime back menu working. [self->_streamView disableOnScreenControls]; // add this to get realtime back menu working.
@@ -11,6 +11,7 @@ import UIKit
@objc protocol ToolBoxSpecialEntryDelegate: NSObjectProtocol { @objc protocol ToolBoxSpecialEntryDelegate: NSObjectProtocol {
@objc optional func openWidgetLayoutTool() @objc optional func openWidgetLayoutTool()
@objc optional func switchWidgetProfile() @objc optional func switchWidgetProfile()
@objc optional func bringUpSoftKeyboard()
} }
@@ -26,10 +27,11 @@ import UIKit
private let viewBackgroundColor = UIColor(white: 0.2, alpha: 0.8); private let viewBackgroundColor = UIColor(white: 0.2, alpha: 0.8);
private let highlightColor = UIColor(white: 0.39, alpha: 0.8); private let highlightColor = UIColor(white: 0.39, alpha: 0.8);
private let titleLabel = UILabel() private let titleLabel = UILabel()
@objc public var specialEntries : NSMutableArray = ["widgetLayoutTool"] @objc public var specialEntries : NSMutableArray = ["widgetSwitchTool", "widgetLayoutTool", "bringUpSoftKeyboard"]
private let specialEntryAliasDic : [String:String] = [ private let specialEntryAliasDic : [String:String] = [
"widgetSwitchTool":SwiftLocalizationHelper.localizedString(forKey: "[ Switch among on-screen widget profiles ]"), "widgetSwitchTool":SwiftLocalizationHelper.localizedString(forKey: "[ Switch among on-screen widget profiles ]"),
"widgetLayoutTool":SwiftLocalizationHelper.localizedString(forKey: "[ Open on-screen widget tool ]") "widgetLayoutTool":SwiftLocalizationHelper.localizedString(forKey: "[ Open on-screen widget tool ]"),
"bringUpSoftKeyboard":SwiftLocalizationHelper.localizedString(forKey: "[ Bring up soft keyboard ]")
] ]
private var viewPinned: Bool = false private var viewPinned: Bool = false
@@ -370,6 +372,8 @@ import UIKit
specialEntryDelegate?.openWidgetLayoutTool!() specialEntryDelegate?.openWidgetLayoutTool!()
case "widgetSwitchTool": case "widgetSwitchTool":
specialEntryDelegate?.switchWidgetProfile?() specialEntryDelegate?.switchWidgetProfile?()
case "bringUpSoftKeyboard":
specialEntryDelegate?.bringUpSoftKeyboard?()
default: break default: break
} }
} }