toolbox local soft keyboard toggle

This commit is contained in:
TrueZhuanjia
2025-07-02 17:02:20 +08:00
parent 14a384436c
commit a07e94ca74
5 changed files with 72 additions and 10 deletions
@@ -53,6 +53,7 @@ static CGFloat screenWidthInPoints;
} */
_lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord;
NSLog(@"gen _lowestTouchPointHeight %f markmark", _lowestTouchPointHeight);
if(_immediateTriggering){
lowestTouchPointYCoord = 0.0; //reset for next recoginition
self.state = UIGestureRecognizerStateRecognized;
@@ -68,6 +69,7 @@ static CGFloat screenWidthInPoints;
- (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) {
@@ -79,6 +81,7 @@ static CGFloat screenWidthInPoints;
if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){
lowestTouchPointYCoord = 0.0; //reset for next recognition
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
+3
View File
@@ -35,6 +35,8 @@
@property (assign, nonatomic) UIView* streamFrameTopLayerView;
@property (assign, nonatomic) CGFloat streamAspectRatio;
@property (assign, nonatomic) CGRect originalFrame;
- (void) setupStreamView:(ControllerSupport*)controllerSupport
interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate
@@ -57,6 +59,7 @@
- (OnScreenControlsLevel) getCurrentOscState;
-(void)readyToBringUpSoftKeyboardByToolbox;
- (void)keyboardWillShow:(NSNotification *)notification;
- (void)keyboardWillHide;
+53 -7
View File
@@ -23,6 +23,7 @@
#import "AbsoluteTouchHandler.h"
#import "KeyboardInputField.h"
#import "CustomTapGestureRecognizer.h"
#import "LocalizationHelper.h"
static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
@@ -70,6 +71,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
UIHoverGestureRecognizer *stylusHoverRecognizer;
#endif
CGFloat HeightViewLiftedTo;
UILabel* keyboardToggleTip;
UIKeyModifierFlags comboKeyModifierFlags;
}
@@ -99,17 +101,19 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[self addSubview:keyInputField];
isInputingText = false;
keyboardToggleRecognizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleKeyboard)];
keyboardToggleRecognizer.numberOfTouchesRequired = settings.keyboardToggleFingers.intValue; //will be changed accordinly by touch modes.
keyboardToggleRecognizer.tapDownTimeThreshold = 0.2; // tap down time threshold in seconds.
keyboardToggleRecognizer.delaysTouchesBegan = NO;
keyboardToggleRecognizer.delaysTouchesEnded = NO;
[self refreshKeyboardToggleRecognizer:settings.keyboardToggleFingers.intValue]; //will be
keyboardToggleTip = [[UILabel alloc] init];
keyboardToggleTip.frame = CGRectMake(0, 0, 35, 100);
keyboardToggleTip.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
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());
// 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
[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
// tvOS requires RelativeTouchHandler to manage Apple Remote input
@@ -212,11 +216,23 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[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{
NSLog(@"keyboard will show markmark %f", CACurrentMediaTime());
if(settings.liftStreamViewForKeyboard && !isInputingText){
NSDictionary *userInfo = notification.userInfo;
// Get the keyboard size from the notification
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
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.
@@ -224,24 +240,52 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
liftedStreamFrame.origin.y -= HeightViewLiftedTo;
self.frame = liftedStreamFrame;
isInputingText = true;
[self refreshKeyboardToggleRecognizer:settings.keyboardToggleFingers.intValue];
}
NSLog(@"keyboard will show %f", CACurrentMediaTime());
}
// this method also deals with recovering streamview when local keyboard is turned off
- (void)keyboardWillHide{
NSLog(@"keyboard will hide markmark %f", CACurrentMediaTime());
keyboardToggleRecognizer.numberOfTouchesRequired = settings.keyboardToggleFingers.intValue; // reset this number
if(isInputingText){
/*
CGRect liftedStreamFrame = self.frame;
// recover view position in keyboard hiding.
liftedStreamFrame.origin.y += HeightViewLiftedTo;
self.frame = liftedStreamFrame;
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{
NSLog(@"toggleKeyboard markmark, %d", isInputingText);
if (isInputingText) {
Log(LOG_D, @"Closing the keyboard");
[keyInputField resignFirstResponder];
@@ -272,6 +316,8 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[keyInputField addTarget:self action:@selector(onKeyboardPressed:) forControlEvents:UIControlEventEditingChanged];
// Undo causes issues for our state management, so turn it off
[keyInputField.undoManager disableUndoRegistration];
//[keyboardToggleTip removeFromSuperview];
}
}
@@ -226,7 +226,7 @@
[super viewDidAppear:animated];
_deviceWindow = self.view.window;
if (UIScreen.screens.count > 1 && [self isAirPlayEnabled]) {
[self prepExtScreen:UIScreen.screens.lastObject];
}
@@ -241,6 +241,8 @@
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
@@ -511,6 +513,10 @@
}];
}
- (void)bringUpSoftKeyboard{
[self->_streamView readyToBringUpSoftKeyboardByToolbox];
}
- (void)oscLayoutClosed{
// Handle the callback
[self->_streamView disableOnScreenControls]; // add this to get realtime back menu working.
@@ -11,6 +11,7 @@ import UIKit
@objc protocol ToolBoxSpecialEntryDelegate: NSObjectProtocol {
@objc optional func openWidgetLayoutTool()
@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 highlightColor = UIColor(white: 0.39, alpha: 0.8);
private let titleLabel = UILabel()
@objc public var specialEntries : NSMutableArray = ["widgetLayoutTool"]
@objc public var specialEntries : NSMutableArray = ["widgetSwitchTool", "widgetLayoutTool", "bringUpSoftKeyboard"]
private let specialEntryAliasDic : [String:String] = [
"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
@@ -370,6 +372,8 @@ import UIKit
specialEntryDelegate?.openWidgetLayoutTool!()
case "widgetSwitchTool":
specialEntryDelegate?.switchWidgetProfile?()
case "bringUpSoftKeyboard":
specialEntryDelegate?.bringUpSoftKeyboard?()
default: break
}
}