11#import <QuartzCore/QuartzCore.h>
12#import <GameController/GameController.h>
13#import <objc/runtime.h>
14#import "RDPSessionViewController.h"
15#import "RDPSessionToolbar.h"
16#import "RDPOverlayStyle.h"
17#import "RDPKeyboard.h"
19#import "Toast+UIView.h"
20#import "ConnectionParams.h"
22#define TOOLBAR_HEIGHT 44
23#define KEYBOARD_CURSOR_MARGIN 44.0
25@interface RDPSessionViewController (Private)
26- (void)showSessionToolbar:(BOOL)show;
27- (void)initGestureRecognizers;
28- (void)suspendSession;
29- (void)fitSessionViewToViewport;
30- (void)centerSessionViewInViewport;
31- (void)setKeyboardOverlap:(CGFloat)overlap;
32- (CGRect)sessionViewportFrame;
33- (void)installHingeInteraction;
36- (void)showConnectingViewWithText:(NSString *)text;
37- (void)hideConnectingView;
38- (void)endBackgroundTask;
39- (void)scheduleRemoteResize;
40- (void)cancelRemoteResize;
41- (void)sendRemoteResize;
42- (CGPoint)remotePositionForSessionViewPosition:(CGPoint)position;
43- (CGPoint)sessionViewPositionForRemotePosition:(CGPoint)position;
44- (CGPoint)clampedSessionViewCursorPosition:(CGPoint)position;
45- (NSDictionary *)eventDescriptorForMouseEvent:(
int)event position:(CGPoint)position;
46- (void)handleMouseMoveForPosition:(CGPoint)position;
47- (CGPoint)currentCursorViewPosition;
48- (void)moveCursorByViewportDelta:(CGPoint)delta;
49- (void)moveCursorToSessionViewPosition:(CGPoint)position;
50- (void)sendMouseButtonEvent:(
int)event;
51- (BOOL)isKeyboardActive;
53- (CGFloat)advancedKeyboardHeight;
54- (void)resetTextInput;
55- (void)commitTextInput;
59@interface RDPSessionTextField : UITextField
62@implementation RDPSessionTextField
67 if ([[
self text] length] == 0)
68 [[
RDPKeyboard getSharedRDPKeyboard] sendBackspaceKeyStroke];
69 [
super deleteBackward];
74@implementation RDPSessionViewController
76#pragma mark class methods
78- (id)initWithNibName:(NSString *)nibNameOrNil
79 bundle:(NSBundle *)nibBundleOrNil
80 session:(RDPSession *)session
82 self = [
super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
85 _session = [session retain];
86 [_session setDelegate:
self];
87 _session_initilized = NO;
89 _advanced_keyboard_view = nil;
90 _sent_text = [@"" retain];
91 _last_session_viewport_size = CGSizeZero;
93 _session_toolbar_visible = NO;
95 _cursor_view_position = CGPointZero;
96 _last_mouse_pan_location = CGPointZero;
97 _has_cursor_view_position = NO;
98 _has_user_moved_cursor = NO;
99 _mouse_pan_active = NO;
100 _long_press_active = NO;
101 _mouse_drag_active = NO;
102 _pointer_is_indirect = NO;
115 object_setClass(_session_toolbar, [RDPSessionToolbar
class]);
117 if (RDPSupportLiquidGlass() == NO)
120 UIToolbarAppearance *appearance = [[[UIToolbarAppearance alloc] init] autorelease];
123 [appearance configureWithTransparentBackground];
124 [_session_toolbar setStandardAppearance:appearance];
125 [_session_toolbar setCompactAppearance:appearance];
126 [_session_toolbar setScrollEdgeAppearance:appearance];
127 [_session_toolbar setCompactScrollEdgeAppearance:appearance];
132 [_dummy_textfield setInputAccessoryView:_keyboard_toolbar];
135 [_dummy_textfield setAutocapitalizationType:UITextAutocapitalizationTypeNone];
136 [_dummy_textfield setSpellCheckingType:UITextSpellCheckingTypeNo];
137 [_dummy_textfield setSmartQuotesType:UITextSmartQuotesTypeNo];
138 [_dummy_textfield setSmartDashesType:UITextSmartDashesTypeNo];
139 [_dummy_textfield setSmartInsertDeleteType:UITextSmartInsertDeleteTypeNo];
140 [_dummy_textfield addTarget:
self
141 action:@selector(textInputChanged:)
142 forControlEvents:UIControlEventEditingChanged];
146 [[_dummy_textfield inputAssistantItem] setLeadingBarButtonGroups:@[]];
147 [[_dummy_textfield inputAssistantItem] setTrailingBarButtonGroups:@[]];
150 [
self initGestureRecognizers];
154 setFrame:CGRectMake(0.0, -TOOLBAR_HEIGHT, [[
self view] bounds].size.width, TOOLBAR_HEIGHT)];
163 [[
self view] setBackgroundColor:[UIColor blackColor]];
165 [_session_scrollview setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
166 [_session_scrollview setContentInset:UIEdgeInsetsZero];
167 [_session_scrollview setScrollIndicatorInsets:UIEdgeInsetsZero];
168 [_session_scrollview setShowsHorizontalScrollIndicator:NO];
169 [_session_scrollview setShowsVerticalScrollIndicator:NO];
170 [_session_scrollview setAlwaysBounceHorizontal:NO];
171 [_session_scrollview setAlwaysBounceVertical:NO];
172 [_session_scrollview setBounces:NO];
174 [
self installHingeInteraction];
177- (void)viewDidLayoutSubviews
179 [
super viewDidLayoutSubviews];
181 CGRect viewportFrame = [
self sessionViewportFrame];
182 [_session_scrollview setFrame:viewportFrame];
184 CGSize viewportSize = [_session_scrollview bounds].size;
185 if (!CGSizeEqualToSize(viewportSize, _last_session_viewport_size))
187 [
self fitSessionViewToViewport];
188 [
self scheduleRemoteResize];
191 [
self centerSessionViewInViewport];
194- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
199- (BOOL)prefersStatusBarHidden
204- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
206 return UIStatusBarAnimationSlide;
209- (void)viewWillTransitionToSize:(CGSize)size
210 withTransitionCoordinator:(
id<UIViewControllerTransitionCoordinator>)coordinator
212 [
super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
216 animateAlongsideTransition:nil
217 completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
218 if (!_advanced_keyboard_view)
220 CGRect frame = [_advanced_keyboard_view frame];
221 frame.size.height = [
self advancedKeyboardHeight];
222 [_advanced_keyboard_view setFrame:frame];
223 [_dummy_textfield reloadInputViews];
227- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
229 (void)fromInterfaceOrientation;
230 [
self centerSessionViewInViewport];
233- (void)didReceiveMemoryWarning
236 [
super didReceiveMemoryWarning];
243 [
super viewDidUnload];
248- (void)viewWillAppear:(BOOL)animated
250 [
super viewWillAppear:animated];
253 [
self setNeedsStatusBarAppearanceUpdate];
254 [[
self navigationController] setNeedsStatusBarAppearanceUpdate];
255 [[
self navigationController] setNavigationBarHidden:YES animated:animated];
256 if (@available(iOS 18.0, *))
257 [[
self tabBarController] setTabBarHidden:YES animated:animated];
259 [[[
self tabBarController] tabBar] setHidden:YES];
262 if ([_session isSuspended])
263 [
self sessionBitmapContextWillChange:_session];
266 [[
RDPKeyboard getSharedRDPKeyboard] initWithSession:_session delegate:
self];
269- (void)viewDidAppear:(BOOL)animated
271 [
super viewDidAppear:animated];
273 if (!_session_initilized)
275 if ([_session isSuspended])
278 [
self sessionBitmapContextDidChange:_session];
279 [
self scheduleRemoteResize];
284 _session_initilized = YES;
288- (void)viewWillDisappear:(BOOL)animated
290 [
super viewWillDisappear:animated];
291 if (_mouse_drag_active)
292 [
self sendMouseButtonEvent:GetLeftMouseButtonClickEvent(NO)];
293 _mouse_drag_active = NO;
294 _mouse_pan_active = NO;
295 _long_press_active = NO;
297 [[
self navigationController] setNeedsStatusBarAppearanceUpdate];
298 [[
self navigationController] setNavigationBarHidden:NO animated:animated];
299 if (@available(iOS 18.0, *))
300 [[
self tabBarController] setTabBarHidden:NO animated:animated];
302 [[[
self tabBarController] tabBar] setHidden:NO];
308 [
self showSessionToolbar:NO];
309 [_dummy_textfield resignFirstResponder];
315 [[NSNotificationCenter defaultCenter] removeObserver:
self];
318 [_session setDelegate:nil];
320 [_advanced_keyboard_view release];
321 [_keyboard_toolbar release];
322 [_sent_text release];
328#pragma mark ScrollView delegate methods
330- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
332 return _session_view;
335- (void)scrollViewDidZoom:(UIScrollView *)scrollView
337 [
self centerSessionViewInViewport];
340- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView
341 withView:(UIView *)view
342 atScale:(CGFloat)scale
344 NSLog(
@"New zoom scale: %f", scale);
345 [
self centerSessionViewInViewport];
346 [_session_view setNeedsDisplayInRemoteRect:[_session_view bounds]];
350#pragma mark TextField delegate methods
351- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
356- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
358 [
self destroyAdvancedKeyboard];
362- (void)textFieldDidEndEditing:(UITextField *)textField
364 [
self commitTextInput];
367- (BOOL)textFieldShouldReturn:(UITextField *)textField
369 [
self commitTextInput];
370 [[
RDPKeyboard getSharedRDPKeyboard] sendEnterKeyStroke];
377- (void)textInputChanged:(UITextField *)textField
381 if ([textField markedTextRange] != nil)
386 RDPKeyboard *keyboard = [
RDPKeyboard getSharedRDPKeyboard];
387 BOOL modifierPressed = [keyboard ctrlPressed] || [keyboard altPressed] ||
388 [keyboard winPressed] || [keyboard altGrPressed];
390 NSString *text = [textField text] != nil ? [textField text] :
@"";
391 NSUInteger length = MIN([text length], [_sent_text length]);
392 NSUInteger common = 0;
394 while (common < length)
396 if ([text characterAtIndex:common] != [_sent_text characterAtIndex:common])
404 if (common < [_sent_text length])
405 common = MIN(common, [_sent_text rangeOfComposedCharacterSequenceAtIndex:common].location);
406 if (common < [text length])
407 common = MIN(common, [text rangeOfComposedCharacterSequenceAtIndex:common].location);
409 for (NSUInteger i = common; i < [_sent_text length];)
411 NSRange range = [_sent_text rangeOfComposedCharacterSequenceAtIndex:i];
412 [keyboard sendBackspaceKeyStroke];
413 i = NSMaxRange(range);
416 for (NSUInteger i = common; i < [text length]; i++)
418 [keyboard sendUnicode:[text characterAtIndex:i]];
421 BOOL isLastCharLetter = NO;
422 if ([text length] > 0)
424 isLastCharLetter = [[NSCharacterSet letterCharacterSet]
425 characterIsMember:[text characterAtIndex:[text length] - 1]];
430 if (modifierPressed || !isLastCharLetter)
432 [
self resetTextInput];
436 [_sent_text release];
437 _sent_text = [text copy];
442#pragma mark AdvancedKeyboardDelegate functions
443- (void)advancedKeyPressedVKey:(NSInteger)key
445 [
self commitTextInput];
446 [[
RDPKeyboard getSharedRDPKeyboard] sendVirtualKeyCode:key];
449#pragma mark - RDP keyboard handler
451- (void)modifiersChangedForKeyboard:(RDPKeyboard *)keyboard
453 [_keyboard_toolbar updateModifiersWithKeyboard:keyboard];
457#pragma mark RDPSessionDelegate functions
459- (void)session:(RDPSession *)session didFailToConnect:(
int)reason
461 [
self hideConnectingView];
464 [[
self navigationController] popViewControllerAnimated:YES];
467- (void)sessionWillConnect:(RDPSession *)session
469 [
self showConnectingViewWithText:NSLocalizedString(@"Connecting",
470 @"Connecting progress view - label")];
473- (void)sessionWillReconnect:(RDPSession *)session
476 [
self showConnectingViewWithText:NSLocalizedString(
478 @"Connecting progress view - reconnect label")];
481- (void)sessionDidReconnect:(RDPSession *)session
484 [
self hideConnectingView];
487- (void)sessionDidActivateDisplayControl:(RDPSession *)session
491 _requested_remote_size = CGSizeZero;
492 [
self scheduleRemoteResize];
495- (void)sessionDidConnect:(RDPSession *)session
498 [[NSNotificationCenter defaultCenter] addObserver:
self
499 selector:@selector(keyboardWillShow:)
500 name:UIKeyboardWillShowNotification
502 [[NSNotificationCenter defaultCenter] addObserver:
self
503 selector:@selector(keyboardWillHide:)
504 name:UIKeyboardWillHideNotification
506 [[NSNotificationCenter defaultCenter] addObserver:
self
507 selector:@selector(keyboardDidHide:)
508 name:UIKeyboardDidHideNotification
512 [[NSNotificationCenter defaultCenter] addObserver:
self
513 selector:@selector(hardwareKeyboardChanged:)
514 name:GCKeyboardDidConnectNotification
516 [[NSNotificationCenter defaultCenter] addObserver:
self
517 selector:@selector(hardwareKeyboardChanged:)
518 name:GCKeyboardDidDisconnectNotification
520 [
self hardwareKeyboardChanged:nil];
523 [[NSNotificationCenter defaultCenter] addObserver:
self
524 selector:@selector(localClipboardChanged:)
525 name:UIApplicationDidBecomeActiveNotification
527 [
self localClipboardChanged:nil];
531 [[NSNotificationCenter defaultCenter] addObserver:
self
532 selector:@selector(applicationDidEnterBackground:)
533 name:UIApplicationDidEnterBackgroundNotification
535 [[NSNotificationCenter defaultCenter] addObserver:
self
536 selector:@selector(applicationWillEnterForeground:)
537 name:UIApplicationWillEnterForegroundNotification
540 [
self hideConnectingView];
543 [_session setToolbarVisible:YES];
544 [
self showSessionToolbar:[_session toolbarVisible]];
549 ConnectionParams *orig_params = [session params];
550 rdpSettings *sess_params = [session getSessionParams];
555 if (([orig_params intForKey:
@"width"] != width &&
556 [orig_params intForKey:
@"width"] != (width + 1ul)) ||
557 [orig_params intForKey:
@"height"] != height || [orig_params intForKey:
@"colors"] != depth)
561 [NSString stringWithFormat:NSLocalizedString(
562 @"The server changed the screen settings to %dx%dx%d",
563 @"Screen settings not supported message with width, "
564 @"height and colors parameter"),
565 width, height, depth];
566 [[
self view] makeToast:message duration:ToastDurationNormal position:@"bottom"];
570- (void)sessionWillDisconnect:(RDPSession *)session
574- (void)sessionDidDisconnect:(RDPSession *)session
576 [
self hideConnectingView];
577 [
self endBackgroundTask];
578 [
self cancelRemoteResize];
581 [[
self navigationController] popViewControllerAnimated:YES];
584- (void)sessionBitmapContextWillChange:(RDPSession *)session
586 [_session_view prepareForBitmapContextChange];
589 rdpSettings *sess_params = [session getSessionParams];
595 [_session_scrollview setZoomScale:1.0];
596 [_session_view setFrame:view_rect];
597 [_session_scrollview setContentSize:view_rect.size];
598 _has_cursor_view_position = NO;
599 _has_user_moved_cursor = NO;
600 _last_session_viewport_size = CGSizeZero;
601 _requested_remote_size = CGSizeZero;
602 [
self fitSessionViewToViewport];
605- (void)sessionBitmapContextDidChange:(RDPSession *)session
608 [_session_view setSession:session];
609 [_session_view setDefaultRemoteCursor];
610 if (!_has_cursor_view_position)
611 (void)[
self currentCursorViewPosition];
614 [_session_view setNeedsDisplayInRemoteRect:[_session_view bounds]];
617- (void)session:(RDPSession *)session needsRedrawInRect:(CGRect)rect
619 [_session_view setNeedsDisplayInRemoteRect:rect];
622- (void)session:(RDPSession *)session didSetRemoteCursor:(RDPCursor *)cursor
625 [_session_view setRemoteCursor:cursor];
627 if (!_has_user_moved_cursor &&
628 (!_has_cursor_view_position || CGPointEqualToPoint(_cursor_view_position, CGPointZero)))
630 _has_cursor_view_position = NO;
631 (void)[
self currentCursorViewPosition];
635- (void)session:(RDPSession *)session didMoveRemoteCursor:(CGPoint)position
638 if (_mouse_pan_active || _long_press_active)
640 CGPoint viewPosition = [
self sessionViewPositionForRemotePosition:position];
641 if (!_has_user_moved_cursor && CGPointEqualToPoint(position, CGPointZero) &&
642 _has_cursor_view_position && !CGPointEqualToPoint(_cursor_view_position, CGPointZero))
645 _cursor_view_position = viewPosition;
646 _has_cursor_view_position = YES;
647 [_session_view setRemoteCursorPosition:viewPosition];
650- (void)sessionDidHideRemoteCursor:(RDPSession *)session
653 [_session_view hideRemoteCursor];
656- (void)sessionDidSetDefaultRemoteCursor:(RDPSession *)session
659 [_session_view setDefaultRemoteCursor];
662- (void)session:(RDPSession *)session didChangeRemoteClipboardText:(NSString *)text
665 UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
666 [pasteboard setString:text];
669 _pasteboard_change_count = [pasteboard changeCount];
672- (void)session:(RDPSession *)session requestsClipboardTextWithParams:(NSMutableDictionary *)params
675 NSString *text = [[UIPasteboard generalPasteboard] string];
677 [params setObject:text forKey:@"text"];
680- (void)session:(RDPSession *)session requestsAuthenticationWithParams:(NSMutableDictionary *)params
683 __block UIAlertController *alert = [UIAlertController
684 alertControllerWithTitle:NSLocalizedString(@"Credentials", @"Credentials title")
685 message:NSLocalizedString(@"Please provide the missing user information.",
686 @"Credentials input view message")
687 preferredStyle:UIAlertControllerStyleAlert];
690 [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
692 setPlaceholder:NSLocalizedString(@"Username", @"Credentials Input Username hint")];
693 [textField setText:[params valueForKey:@"username"]];
694 [textField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
695 [textField setAutocorrectionType:UITextAutocorrectionTypeNo];
699 [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
701 setPlaceholder:NSLocalizedString(@"Password", @"Credentials Input Password hint")];
702 [textField setText:[params valueForKey:@"password"]];
703 [textField setSecureTextEntry:YES];
707 [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
708 [textField setPlaceholder:NSLocalizedString(@"Domain", @"Credentials Input Domain hint")];
709 [textField setText:[params valueForKey:@"domain"]];
710 [textField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
711 [textField setAutocorrectionType:UITextAutocorrectionTypeNo];
715 UIAlertAction *cancelAction =
716 [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel Button")
717 style:UIAlertActionStyleCancel
718 handler:^(UIAlertAction *action) {
719 [params setValue:[NSNumber numberWithBool:NO] forKey:@"result"];
720 [[session uiRequestCompleted] signal];
722 [alert addAction:cancelAction];
725 UIAlertAction *loginAction = [UIAlertAction
726 actionWithTitle:NSLocalizedString(@"Login", @"Login Button")
727 style:UIAlertActionStyleDefault
728 handler:^(UIAlertAction *action) {
729 NSArray *fields = [alert textFields];
730 [params setValue:[[fields objectAtIndex:0] text] forKey:@"username"];
731 [params setValue:[[fields objectAtIndex:1] text] forKey:@"password"];
732 [params setValue:[[fields objectAtIndex:2] text] forKey:@"domain"];
733 [params setValue:[NSNumber numberWithBool:YES] forKey:@"result"];
734 [[session uiRequestCompleted] signal];
736 [alert addAction:loginAction];
738 [alert setPreferredAction:loginAction];
740 [
self presentViewController:alert animated:YES completion:nil];
743- (void)session:(RDPSession *)session verifyCertificateWithParams:(NSMutableDictionary *)params
745 NSString *message = [NSString
746 stringWithFormat:@"%@\n\n%@ %@",
747 NSLocalizedString(@"The identity of the remote computer cannot be "
748 @"verified. Do you want to connect anyway?",
749 @"Verify certificate view message"),
750 NSLocalizedString(@"Issuer:", @"Verify certificate view issuer label"),
751 [params valueForKey:@"issuer"]];
752 UIAlertController *alert =
753 [UIAlertController alertControllerWithTitle:nil
755 preferredStyle:UIAlertControllerStyleAlert];
757 [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"No", @"No Button")
758 style:UIAlertActionStyleCancel
759 handler:^(UIAlertAction *action) {
760 [params setValue:[NSNumber numberWithBool:NO]
762 [[session uiRequestCompleted] signal];
765 [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Yes", @"Yes Button")
766 style:UIAlertActionStyleDefault
767 handler:^(UIAlertAction *action) {
768 [params setValue:[NSNumber numberWithBool:YES]
770 [[session uiRequestCompleted] signal];
773 [
self presentViewController:alert animated:YES completion:nil];
776- (CGSize)sizeForFitScreenForSession:(RDPSession *)session
779 CGSize size = [
self sessionViewportFrame].size;
781 UIScreen *screen = [[[[
self view] window] windowScene] screen];
782 CGFloat scale = screen ? [screen nativeScale] : [[
self traitCollection] displayScale];
787 scale *= FitScreenScale([[session params] intForKey:
@"screen_resolution_type"]);
789 size.width = ceilf(size.width * scale);
790 size.height = ceilf(size.height * scale);
792 CGFloat maxDimension = MAX(size.width, size.height);
793 if (maxDimension > 4096.0f)
795 CGFloat downscale = 4096.0f / maxDimension;
796 size.width = floorf(size.width * downscale);
797 size.height = floorf(size.height * downscale);
800 size.width = (UINT32)MAX(200.0f, size.width) & ~1u;
801 size.height = (UINT32)MAX(200.0f, size.height) & ~1u;
806#pragma mark - Keyboard Toolbar Handlers
808- (void)showAdvancedKeyboardAnimated
811 if (_advanced_keyboard_view)
814 CGRect rect = CGRectMake(0, 0, [[
self view] bounds].size.width, [
self advancedKeyboardHeight]);
817 [_dummy_textfield setInputView:_advanced_keyboard_view];
818 [_dummy_textfield reloadInputViews];
819 [_keyboard_toolbar setExtendedKeyboardActive:YES];
822- (void)destroyAdvancedKeyboard
825 if (!_advanced_keyboard_view)
828 [_dummy_textfield setInputView:nil];
829 [_advanced_keyboard_view autorelease];
830 _advanced_keyboard_view = nil;
831 [_keyboard_toolbar setExtendedKeyboardActive:NO];
835- (IBAction)toggleKeyboardWhenOtherVisible:(
id)sender
837 if (!_advanced_keyboard_view)
840 [
self showAdvancedKeyboardAnimated];
845 [
self destroyAdvancedKeyboard];
846 [_dummy_textfield reloadInputViews];
850- (IBAction)toggleWinKey:(
id)sender
855- (IBAction)toggleShiftKey:(
id)sender
857 [[
RDPKeyboard getSharedRDPKeyboard] toggleShiftKey];
860- (IBAction)toggleCtrlKey:(
id)sender
862 [[
RDPKeyboard getSharedRDPKeyboard] toggleCtrlKey];
865- (IBAction)toggleAltKey:(
id)sender
870- (IBAction)toggleAltGrKey:(
id)sender
872 [[
RDPKeyboard getSharedRDPKeyboard] toggleAltGrKey];
875- (IBAction)pressEscKey:(
id)sender
877 [
self commitTextInput];
878 [[
RDPKeyboard getSharedRDPKeyboard] sendEscapeKeyStroke];
881- (IBAction)pressDeleteKey:(
id)sender
883 [
self commitTextInput];
884 [[
RDPKeyboard getSharedRDPKeyboard] sendDeleteKeyStroke];
887- (IBAction)pressTabKey:(
id)sender
889 [
self commitTextInput];
890 [[
RDPKeyboard getSharedRDPKeyboard] sendTabKeyStroke];
894#pragma mark event handlers
896- (IBAction)switchSession:(
id)sender
898 [
self suspendSession];
901- (IBAction)toggleKeyboard:(
id)sender
903 if (![
self isKeyboardActive])
904 [_dummy_textfield becomeFirstResponder];
906 [_dummy_textfield resignFirstResponder];
909- (IBAction)disconnectSession:(
id)sender
911 [_session disconnect];
914- (IBAction)cancelButtonPressed:(
id)sender
916 [_session disconnect];
920#pragma mark iOS Keyboard Notification Handlers
922- (void)keyboardWillShow:(NSNotification *)notification
925 if (!_advanced_keyboard_view)
928 [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
929 CGFloat height = frame.size.height - [_keyboard_toolbar bounds].size.height;
934 if ([
self isLandscape])
935 _keyboard_height_landscape = height;
937 _keyboard_height_portrait = height;
941 [
self centerSessionViewInViewport];
944 CGRect keyboardFrame =
945 [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
946 keyboardFrame = [[
self view] convertRect:keyboardFrame fromView:nil];
948 CGRect coveredArea = CGRectIntersection([_session_scrollview frame], keyboardFrame);
950 [
self setKeyboardOverlap:CGRectGetHeight(coveredArea)];
953- (void)keyboardWillHide:(NSNotification *)notification
956 [
self centerSessionViewInViewport];
957 [
self setKeyboardOverlap:0.0];
960- (void)keyboardDidHide:(NSNotification *)notification
963 if (![
self isKeyboardActive])
964 [
self destroyAdvancedKeyboard];
967 if (![
self isKeyboardActive] && [_session_view hardwareKeyboardActive])
968 [_session_view becomeFirstResponder];
971- (void)hardwareKeyboardChanged:(NSNotification *)notification
973 BOOL connected = (GCKeyboard.coalescedKeyboard != nil);
974 [_session_view setHardwareKeyboardActive:connected];
976 if (connected && ![
self isKeyboardActive])
977 [_session_view becomeFirstResponder];
979 [_session_view resignFirstResponder];
982- (void)localClipboardChanged:(NSNotification *)notification
985 UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
986 if ([pasteboard changeCount] == _pasteboard_change_count)
989 _pasteboard_change_count = [pasteboard changeCount];
990 [_session sendClipboardHasText:[pasteboard hasStrings]];
993- (void)applicationDidEnterBackground:(NSNotification *)notification
997 [
self endBackgroundTask];
999 [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
1000 [
self endBackgroundTask];
1004 [
self cancelRemoteResize];
1007- (void)applicationWillEnterForeground:(NSNotification *)notification
1009 [
self endBackgroundTask];
1012 [
self scheduleRemoteResize];
1016#pragma mark Gesture handlers
1018- (void)handleSingleTap:(UITapGestureRecognizer *)gesture
1020 if (_pointer_is_indirect)
1021 [
self moveCursorToSessionViewPosition:[gesture locationInView:_session_view]];
1022 [
self sendMouseButtonEvent:GetLeftMouseButtonClickEvent(YES)];
1023 [
self sendMouseButtonEvent:GetLeftMouseButtonClickEvent(NO)];
1026- (void)handleSecondaryTap:(UITapGestureRecognizer *)gesture
1028 [
self moveCursorToSessionViewPosition:[gesture locationInView:_session_view]];
1029 [
self sendMouseButtonEvent:GetRightMouseButtonClickEvent(YES)];
1030 [
self sendMouseButtonEvent:GetRightMouseButtonClickEvent(NO)];
1033- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
1035 if ([gesture state] == UIGestureRecognizerStateBegan)
1037 _long_press_active = YES;
1038 _mouse_drag_active = NO;
1040 else if ([gesture state] == UIGestureRecognizerStateEnded ||
1041 [gesture state] == UIGestureRecognizerStateCancelled ||
1042 [gesture state] == UIGestureRecognizerStateFailed)
1044 if (_mouse_drag_active)
1045 [
self sendMouseButtonEvent:GetLeftMouseButtonClickEvent(NO)];
1046 else if ([gesture state] == UIGestureRecognizerStateEnded)
1048 [
self sendMouseButtonEvent:GetRightMouseButtonClickEvent(YES)];
1049 [
self sendMouseButtonEvent:GetRightMouseButtonClickEvent(NO)];
1052 _mouse_drag_active = NO;
1053 _long_press_active = NO;
1057- (void)handleMousePan:(UIPanGestureRecognizer *)gesture
1061 if (_pointer_is_indirect)
1063 [
self moveCursorToSessionViewPosition:[gesture locationInView:_session_view]];
1065 if ([gesture state] == UIGestureRecognizerStateBegan)
1067 [
self sendMouseButtonEvent:GetLeftMouseButtonClickEvent(YES)];
1068 _mouse_drag_active = YES;
1070 else if ([gesture state] == UIGestureRecognizerStateEnded ||
1071 [gesture state] == UIGestureRecognizerStateCancelled ||
1072 [gesture state] == UIGestureRecognizerStateFailed)
1074 if (_mouse_drag_active)
1075 [
self sendMouseButtonEvent:GetLeftMouseButtonClickEvent(NO)];
1076 _mouse_drag_active = NO;
1081 CGPoint location = [gesture locationInView:_session_scrollview];
1083 if ([gesture state] == UIGestureRecognizerStateBegan)
1085 _mouse_pan_active = YES;
1086 _last_mouse_pan_location = location;
1087 if (_long_press_active && !_mouse_drag_active)
1089 [
self sendMouseButtonEvent:GetLeftMouseButtonClickEvent(YES)];
1090 _mouse_drag_active = YES;
1093 else if ([gesture state] == UIGestureRecognizerStateChanged)
1095 if (_long_press_active && !_mouse_drag_active)
1097 [
self sendMouseButtonEvent:GetLeftMouseButtonClickEvent(YES)];
1098 _mouse_drag_active = YES;
1101 CGPoint delta = CGPointMake(location.x - _last_mouse_pan_location.x,
1102 location.y - _last_mouse_pan_location.y);
1103 [
self moveCursorByViewportDelta:delta];
1104 _last_mouse_pan_location = location;
1106 else if ([gesture state] == UIGestureRecognizerStateEnded ||
1107 [gesture state] == UIGestureRecognizerStateCancelled ||
1108 [gesture state] == UIGestureRecognizerStateFailed)
1110 _mouse_pan_active = NO;
1114- (void)handleHover:(UIHoverGestureRecognizer *)gesture
1116 if ([gesture state] != UIGestureRecognizerStateBegan &&
1117 [gesture state] != UIGestureRecognizerStateChanged)
1120 [
self moveCursorToSessionViewPosition:[gesture locationInView:_session_view]];
1123- (void)handleDoubleLongPress:(UILongPressGestureRecognizer *)gesture
1127 CGPoint pos = [gesture locationInView:_session_scrollview];
1128 CGPoint session_view_pos = [
self currentCursorViewPosition];
1130 if ([gesture state] == UIGestureRecognizerStateBegan)
1131 _prev_long_press_position = pos;
1132 else if ([gesture state] == UIGestureRecognizerStateChanged)
1134 int delta = _prev_long_press_position.y - pos.y;
1136 if (delta > GetScrollGestureDelta())
1138 [_session sendInputEvent:[
self eventDescriptorForMouseEvent:GetMouseWheelEvent(YES)
1139 position:session_view_pos]];
1140 _prev_long_press_position = pos;
1142 else if (delta < -GetScrollGestureDelta())
1144 [_session sendInputEvent:[
self eventDescriptorForMouseEvent:GetMouseWheelEvent(NO)
1145 position:session_view_pos]];
1146 _prev_long_press_position = pos;
1151- (void)handleScroll:(UIPanGestureRecognizer *)gesture
1153 CGFloat delta = [gesture translationInView:_session_view].y;
1154 if (fabs(delta) < GetScrollGestureDelta())
1157 CGPoint position = [
self currentCursorViewPosition];
1158 [_session sendInputEvent:[
self eventDescriptorForMouseEvent:GetMouseWheelEvent(delta > 0)
1159 position:position]];
1160 [gesture setTranslation:CGPointZero inView:_session_view];
1163- (void)handleSingle3FingersTap:(UITapGestureRecognizer *)gesture
1165 [_session setToolbarVisible:![_session toolbarVisible]];
1166 [
self showSessionToolbar:[_session toolbarVisible]];
1169- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction
1170 styleForRegion:(UIPointerRegion *)region
1172 return [UIPointerStyle hiddenPointerStyle];
1175- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
1176 shouldReceiveTouch:(UITouch *)touch
1179 if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer
class]] &&
1180 [(UIPanGestureRecognizer *)gestureRecognizer allowedScrollTypesMask] != 0)
1183 _pointer_is_indirect = ([touch type] == UITouchTypeIndirectPointer);
1187 if (_pointer_is_indirect &&
1188 [gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer
class]])
1194- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
1195 shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
1198 ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] &&
1199 [otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) ||
1200 ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer
class]] &&
1201 [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer
class]]);
1207@implementation RDPSessionViewController (Private)
1210#pragma mark Helper functions
1212- (void)showConnectingViewWithText:(NSString *)text
1214 [
self hideConnectingView];
1217 [[NSBundle mainBundle] loadNibNamed:@"RDPConnectingView" owner:
self options:nil];
1220 [_lbl_connecting setText:text];
1221 [_cancel_connect_button setTitle:NSLocalizedString(@"Cancel", @"Cancel Button")
1222 forState:UIControlStateNormal];
1225 [_connecting_view setCenter:[[
self view] center]];
1226 [[_connecting_view layer] setCornerRadius:10];
1229 [[
self view] addSubview:_connecting_view];
1230 [_connecting_indicator_view startAnimating];
1233- (void)hideConnectingView
1235 if (!_connecting_view)
1239 [_connecting_indicator_view stopAnimating];
1240 [_connecting_view removeFromSuperview];
1241 [_connecting_view autorelease];
1242 _connecting_view = nil;
1245- (void)endBackgroundTask
1247 if (_background_task == UIBackgroundTaskInvalid)
1250 [[UIApplication sharedApplication] endBackgroundTask:_background_task];
1251 _background_task = UIBackgroundTaskInvalid;
1254- (void)scheduleRemoteResize
1257 if (!IsFitScreenOption([[_session params] intForKey:
@"screen_resolution_type"]))
1261 [
self cancelRemoteResize];
1262 [
self performSelector:@selector(sendRemoteResize) withObject:nil afterDelay:0.5];
1265- (void)cancelRemoteResize
1267 [
NSObject cancelPreviousPerformRequestsWithTarget:
self
1268 selector:@selector(sendRemoteResize)
1272- (void)sendRemoteResize
1274 UIWindowScene *scene = [[[
self view] window] windowScene];
1275 if (!scene || [scene activationState] == UISceneActivationStateBackground)
1278 CGSize size = [
self sizeForFitScreenForSession:_session];
1281 CGSize current = _requested_remote_size;
1282 if (CGSizeEqualToSize(current, CGSizeZero))
1285 rdpSettings *settings = [_session getSessionParams];
1291 if (CGSizeEqualToSize(size, current))
1294 _requested_remote_size = size;
1295 [_session sendMonitorLayoutWithSize:size];
1298- (CGRect)sessionViewportFrame
1301 if (IsPad() || ![[NSUserDefaults standardUserDefaults] boolForKey:
@"ui.avoid_screen_edges"])
1302 return [[
self view] bounds];
1305 UIEdgeInsets insets = [[
self view] safeAreaInsets];
1306 CGRect bounds = [[
self view] bounds];
1309 if ([
self hasHinge] || bounds.size.width > bounds.size.height)
1310 insets.bottom = 0.0f;
1313 if ([
self isHingeOpen] && insets.right > insets.left)
1314 insets.left = insets.right;
1316 return UIEdgeInsetsInsetRect(bounds, insets);
1319- (void)installHingeInteraction
1321#if defined(__IPHONE_27_1) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_27_1)
1322 if (@available(iOS 27.1, *))
1324 __block RDPSessionViewController *weakSelf =
self;
1325 UIHingeInteraction *interaction = [[UIHingeInteraction alloc]
1326 initWithUpdateHandler:^(UIHingeInteraction *hingeInteraction,
1327 UIHingeInteractionUpdate *update) {
1328 (void)hingeInteraction;
1329 UIHinge *hinge = [update hinge];
1335 weakSelf->_has_hinge = YES;
1337 UIHingeStatus hingeStatus = [hinge status];
1338 BOOL open = (hingeStatus == UIHingeStatusPartiallyOpen ||
1339 hingeStatus == UIHingeStatusFullyOpen);
1340 if (weakSelf->_hinge_open == open)
1343 weakSelf->_hinge_open = open;
1344 [[weakSelf view] setNeedsLayout];
1347 [[
self view] addInteraction:interaction];
1348 [interaction release];
1365- (void)fitSessionViewToViewport
1367 CGSize viewportSize = [_session_scrollview bounds].size;
1368 CGSize remoteSize = [_session_view bounds].size;
1369 if (viewportSize.width <= 0.0f || viewportSize.height <= 0.0f || remoteSize.width <= 0.0f ||
1370 remoteSize.height <= 0.0f)
1374 MIN(viewportSize.width / remoteSize.width, viewportSize.height / remoteSize.height);
1375 [_session_scrollview setMinimumZoomScale:fitScale];
1376 [_session_scrollview setMaximumZoomScale:MAX(2.0f, fitScale)];
1377 [_session_scrollview setZoomScale:fitScale animated:NO];
1378 [_session_scrollview setContentOffset:CGPointZero animated:NO];
1379 _last_session_viewport_size = viewportSize;
1380 [
self centerSessionViewInViewport];
1383- (void)centerSessionViewInViewport
1385 CGSize viewportSize = [_session_scrollview bounds].size;
1386 CGRect sessionFrame = [_session_view frame];
1387 if (viewportSize.width <= 0.0f || viewportSize.height <= 0.0f ||
1388 sessionFrame.size.width <= 0.0f || sessionFrame.size.height <= 0.0f)
1391 sessionFrame.origin.x = MAX((viewportSize.width - sessionFrame.size.width) * 0.5f, 0.0f);
1392 sessionFrame.origin.y = MAX((viewportSize.height - sessionFrame.size.height) * 0.5f, 0.0f);
1393 [_session_view setFrame:sessionFrame];
1395 [_session_scrollview
1396 setContentSize:CGSizeMake(MAX(viewportSize.width, sessionFrame.size.width),
1397 MAX(viewportSize.height, sessionFrame.size.height))];
1400- (void)setKeyboardOverlap:(CGFloat)overlap
1403 UIEdgeInsets inset = [_session_scrollview contentInset];
1404 inset.bottom = overlap;
1405 [_session_scrollview setContentInset:inset];
1407 CGPoint offset = [_session_scrollview contentOffset];
1408 CGFloat viewportHeight = [_session_scrollview bounds].size.height;
1411 if (overlap > 0.0 && _has_cursor_view_position)
1413 CGPoint cursor = [_session_scrollview convertPoint:_cursor_view_position
1414 fromView:_session_view];
1415 CGFloat visibleBottom = offset.y + viewportHeight - overlap;
1416 CGFloat hiddenHeight = cursor.y + KEYBOARD_CURSOR_MARGIN - visibleBottom;
1417 if (hiddenHeight > 0.0)
1418 offset.y += hiddenHeight;
1422 CGFloat maxOffsetY = [_session_scrollview contentSize].height + overlap - viewportHeight;
1423 offset.y = MAX(MIN(offset.y, maxOffsetY), 0.0);
1424 [_session_scrollview setContentOffset:offset animated:YES];
1427- (void)showSessionToolbar:(BOOL)show
1430 if (_session_toolbar_visible == show)
1436 UIEdgeInsets safe = [[
self view] safeAreaInsets];
1439 safe.top = MAX(safe.top, [
self systemMinimumLayoutMargins].leading);
1440 CGFloat toolbarWidth = [[
self view] bounds].size.width - safe.left - safe.right;
1444 [
UIView animateWithDuration:0.4
1446 options:UIViewAnimationOptionCurveLinear
1448 [_session_toolbar setFrame:CGRectMake(safe.left, safe.top,
1449 toolbarWidth, TOOLBAR_HEIGHT)];
1452 _session_toolbar_visible = YES;
1456 [
UIView animateWithDuration:0.4
1458 options:UIViewAnimationOptionCurveLinear
1460 [_session_toolbar setFrame:CGRectMake(safe.left, -TOOLBAR_HEIGHT,
1461 toolbarWidth, TOOLBAR_HEIGHT)];
1464 _session_toolbar_visible = NO;
1468- (void)initGestureRecognizers
1472 UITapGestureRecognizer *singleTapRecognizer =
1473 [[[UITapGestureRecognizer alloc] initWithTarget:
self
1474 action:@selector(handleSingleTap:)] autorelease];
1475 [singleTapRecognizer setNumberOfTouchesRequired:1];
1476 [singleTapRecognizer setNumberOfTapsRequired:1];
1477 [singleTapRecognizer setDelegate:
self];
1480 UILongPressGestureRecognizer *longPressRecognizer = [[[UILongPressGestureRecognizer alloc]
1482 action:@selector(handleLongPress:)] autorelease];
1483 [longPressRecognizer setMinimumPressDuration:0.3];
1484 [longPressRecognizer setAllowableMovement:12.0];
1485 [longPressRecognizer setDelegate:
self];
1488 UIPanGestureRecognizer *mousePanRecognizer =
1489 [[[UIPanGestureRecognizer alloc] initWithTarget:
self
1490 action:@selector(handleMousePan:)] autorelease];
1491 [mousePanRecognizer setMinimumNumberOfTouches:1];
1492 [mousePanRecognizer setMaximumNumberOfTouches:1];
1493 [mousePanRecognizer setDelegate:
self];
1496 UIHoverGestureRecognizer *hoverRecognizer =
1497 [[[UIHoverGestureRecognizer alloc] initWithTarget:
self
1498 action:@selector(handleHover:)] autorelease];
1499 [hoverRecognizer setDelegate:
self];
1503 UITapGestureRecognizer *secondaryTapRecognizer = [[[UITapGestureRecognizer alloc]
1505 action:@selector(handleSecondaryTap:)] autorelease];
1506 [secondaryTapRecognizer setButtonMaskRequired:UIEventButtonMaskSecondary];
1507 [secondaryTapRecognizer setAllowedTouchTypes:@[@(UITouchTypeIndirectPointer)]];
1508 [secondaryTapRecognizer setDelegate:
self];
1512 UIPanGestureRecognizer *scrollRecognizer =
1513 [[[UIPanGestureRecognizer alloc] initWithTarget:
self
1514 action:@selector(handleScroll:)] autorelease];
1515 [scrollRecognizer setAllowedScrollTypesMask:UIScrollTypeMaskAll];
1516 [scrollRecognizer setDelegate:
self];
1519 UILongPressGestureRecognizer *doubleLongPressRecognizer = [[[UILongPressGestureRecognizer alloc]
1521 action:@selector(handleDoubleLongPress:)] autorelease];
1522 [doubleLongPressRecognizer setNumberOfTouchesRequired:2];
1523 [doubleLongPressRecognizer setMinimumPressDuration:0.3];
1526 UITapGestureRecognizer *single3FingersTapRecognizer = [[[UITapGestureRecognizer alloc]
1528 action:@selector(handleSingle3FingersTap:)] autorelease];
1529 [single3FingersTapRecognizer setNumberOfTapsRequired:1];
1530 [single3FingersTapRecognizer setNumberOfTouchesRequired:3];
1531 [singleTapRecognizer requireGestureRecognizerToFail:longPressRecognizer];
1534 [[_session_scrollview panGestureRecognizer] setMinimumNumberOfTouches:2];
1537 [_session_scrollview addGestureRecognizer:singleTapRecognizer];
1538 [_session_scrollview addGestureRecognizer:longPressRecognizer];
1539 [_session_scrollview addGestureRecognizer:mousePanRecognizer];
1540 [_session_scrollview addGestureRecognizer:hoverRecognizer];
1541 [_session_scrollview addGestureRecognizer:secondaryTapRecognizer];
1542 [_session_scrollview addGestureRecognizer:scrollRecognizer];
1543 [_session_scrollview addGestureRecognizer:doubleLongPressRecognizer];
1544 [_session_scrollview addGestureRecognizer:single3FingersTapRecognizer];
1547 UIPointerInteraction *pointerInteraction =
1548 [[[UIPointerInteraction alloc] initWithDelegate:
self] autorelease];
1549 [_session_view addInteraction:pointerInteraction];
1552- (void)suspendSession
1558 [[
self navigationController] popViewControllerAnimated:YES];
1561- (NSDictionary *)eventDescriptorForMouseEvent:(
int)event position:(CGPoint)position
1563 CGPoint remote_position = [
self remotePositionForSessionViewPosition:position];
1564 return [NSDictionary
1565 dictionaryWithObjectsAndKeys:@"mouse", @"type", [NSNumber numberWithUnsignedShort:event],
1567 [NSNumber numberWithUnsignedShort:lrintf(remote_position.x)],
1569 [NSNumber numberWithUnsignedShort:lrintf(remote_position.y)],
1573- (CGPoint)remotePositionForSessionViewPosition:(CGPoint)position
1575 rdpSettings *settings = [_session getSessionParams];
1576 CGSize viewSize = [_session_view bounds].size;
1577 CGFloat desktopWidth =
1579 CGFloat desktopHeight =
1582 if ((viewSize.width > 0.0f) && (desktopWidth > 0.0f))
1583 position.x = position.x * desktopWidth / viewSize.width;
1584 if ((viewSize.height > 0.0f) && (desktopHeight > 0.0f))
1585 position.y = position.y * desktopHeight / viewSize.height;
1587 if (desktopWidth > 0.0f)
1588 position.x = MIN(MAX(position.x, 0.0f), desktopWidth - 1.0f);
1589 if (desktopHeight > 0.0f)
1590 position.y = MIN(MAX(position.y, 0.0f), desktopHeight - 1.0f);
1595- (CGPoint)sessionViewPositionForRemotePosition:(CGPoint)position
1597 rdpSettings *settings = [_session getSessionParams];
1598 CGSize viewSize = [_session_view bounds].size;
1599 CGFloat desktopWidth =
1601 CGFloat desktopHeight =
1604 if ((desktopWidth > 0.0f) && (viewSize.width > 0.0f))
1605 position.x = position.x * viewSize.width / desktopWidth;
1606 if ((desktopHeight > 0.0f) && (viewSize.height > 0.0f))
1607 position.y = position.y * viewSize.height / desktopHeight;
1609 return [
self clampedSessionViewCursorPosition:position];
1612- (CGPoint)clampedSessionViewCursorPosition:(CGPoint)position
1614 CGSize viewSize = [_session_view bounds].size;
1615 if (viewSize.width > 0.0f)
1616 position.x = MIN(MAX(position.x, 0.0f), viewSize.width - 1.0f);
1617 if (viewSize.height > 0.0f)
1618 position.y = MIN(MAX(position.y, 0.0f), viewSize.height - 1.0f);
1622- (CGPoint)currentCursorViewPosition
1624 if (!_has_cursor_view_position)
1626 CGSize viewSize = [_session_view bounds].size;
1627 _cursor_view_position = CGPointMake(MAX(viewSize.width - 1.0, 0.0) * 0.5,
1628 MAX(viewSize.height - 1.0, 0.0) * 0.5);
1629 _has_cursor_view_position = YES;
1630 [_session_view setRemoteCursorPosition:_cursor_view_position];
1632 [_session_view showRemoteCursor];
1634 return _cursor_view_position;
1637- (void)moveCursorByViewportDelta:(CGPoint)delta
1639 CGPoint position = [
self currentCursorViewPosition];
1640 CGFloat zoomScale = [_session_scrollview zoomScale];
1641 if (zoomScale <= 0.0)
1644 position.x += delta.x / zoomScale;
1645 position.y += delta.y / zoomScale;
1646 position = [
self clampedSessionViewCursorPosition:position];
1647 _cursor_view_position = position;
1648 _has_cursor_view_position = YES;
1649 _has_user_moved_cursor = YES;
1652 [_session_view setRemoteCursorPosition:position];
1653 [
self handleMouseMoveForPosition:position];
1656- (void)moveCursorToSessionViewPosition:(CGPoint)position
1658 position = [
self clampedSessionViewCursorPosition:position];
1659 _cursor_view_position = position;
1660 _has_cursor_view_position = YES;
1661 _has_user_moved_cursor = YES;
1664 [_session_view setRemoteCursorPosition:position];
1665 [_session_view showRemoteCursor];
1666 [
self handleMouseMoveForPosition:position];
1669- (void)sendMouseButtonEvent:(
int)event
1672 [
self commitTextInput];
1673 CGPoint position = [
self currentCursorViewPosition];
1674 [_session sendInputEvent:[
self eventDescriptorForMouseEvent:event position:position]];
1677- (void)handleMouseMoveForPosition:(CGPoint)position
1679 [_session sendInputEvent:[
self eventDescriptorForMouseEvent:PTR_FLAGS_MOVE position:position]];
1682- (BOOL)isKeyboardActive
1684 return [_dummy_textfield isFirstResponder];
1687- (void)resetTextInput
1689 [_dummy_textfield setText:@""];
1690 [_sent_text release];
1691 _sent_text = [@"" retain];
1694- (void)commitTextInput
1696 if ([[_dummy_textfield text] length] == 0)
1700 [_dummy_textfield unmarkText];
1701 [
self textInputChanged:_dummy_textfield];
1702 [
self resetTextInput];
1707 CGSize size = [[
self view] bounds].size;
1708 return size.width > size.height;
1711- (CGFloat)advancedKeyboardHeight
1714 if ([
self isLandscape])
1715 return (_keyboard_height_landscape > 0.0) ? _keyboard_height_landscape
1716 : (IsPad() ? 400.0 : 200.0);
1717 return (_keyboard_height_portrait > 0.0) ? _keyboard_height_portrait
1718 : (IsPad() ? 320.0 : 290.0);
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.