diff --git a/VoidLink/ViewControllers/CustomEdgeSlideGestureRecognizer.m b/VoidLink/ViewControllers/CustomEdgeSlideGestureRecognizer.m index 858c0486..ba353afc 100644 --- a/VoidLink/ViewControllers/CustomEdgeSlideGestureRecognizer.m +++ b/VoidLink/ViewControllers/CustomEdgeSlideGestureRecognizer.m @@ -14,11 +14,11 @@ @implementation CustomEdgeSlideGestureRecognizer UITouch* capturedUITouch; CGFloat startPointX; -static CGFloat screenWidthInPoints; +//static CGFloat screenWidthInPoints; - (instancetype)initWithTarget:(nullable id)target action:(nullable SEL)action { self = [super initWithTarget:target action:action]; - screenWidthInPoints = CGRectGetWidth([UIApplication.sharedApplication.windows.firstObject.screen bounds]); // Get the screen's bounds (in points) +// screenWidthInPoints = CGRectGetWidth([UIApplication.sharedApplication.windows.firstObject.screen bounds]); // Get the screen's bounds (in points) _immediateTriggering = false; _EDGE_TOLERANCE = 10.0f; return self; @@ -29,6 +29,7 @@ static CGFloat screenWidthInPoints; UITouch *touch = [touches anyObject]; capturedUITouch = touch; startPointX = [capturedUITouch locationInView:self.view].x; + CGFloat screenWidthInPoints = self.view.frame.size.width; if(_immediateTriggering){ if(self.edges & UIRectEdgeLeft){ @@ -52,6 +53,7 @@ static CGFloat screenWidthInPoints; if([touches containsObject:capturedUITouch]){ CGFloat _endPointX = [capturedUITouch locationInView:self.view].x; + CGFloat screenWidthInPoints = self.view.frame.size.width; CGFloat normalizedGestureDistance = fabs(_endPointX - startPointX)/screenWidthInPoints; if(self.edges & UIRectEdgeLeft){ diff --git a/VoidLink/ViewControllers/MainFrameViewController.h b/VoidLink/ViewControllers/MainFrameViewController.h index 8d978cd8..1f11da5a 100644 --- a/VoidLink/ViewControllers/MainFrameViewController.h +++ b/VoidLink/ViewControllers/MainFrameViewController.h @@ -34,5 +34,6 @@ -(void)reloadStreamConfig; -(bool)isIPhonePortrait; #endif +- (void)fillResolutionTable:(CGSize*)resolutionTable externalDisplayMode:(NSInteger)externalDisplayMode; @end diff --git a/VoidLink/ViewControllers/MainFrameViewController.m b/VoidLink/ViewControllers/MainFrameViewController.m index 3f067a41..f43765fe 100644 --- a/VoidLink/ViewControllers/MainFrameViewController.m +++ b/VoidLink/ViewControllers/MainFrameViewController.m @@ -1602,50 +1602,56 @@ static NSMutableSet* hostList; // }); //} --(void) updateResolutionAccordingly { - DataManager* dataMan = [[DataManager alloc] init]; - Settings *currentSettings = [dataMan retrieveSettings]; - UIWindow *window = UIApplication.sharedApplication.windows.firstObject; +-(void) fillResolutionTable:(CGSize*)resolutionTable externalDisplayMode:(NSInteger)externalDisplayMode{ + UIWindow *window = self.view.window; + NSLog(@" window %@", window); + CGFloat screenScale = window.screen.scale; - CGFloat appWindowWidth = CGRectGetWidth(window.frame) * screenScale; - CGFloat appWindowHeight = CGRectGetHeight(window.frame) * screenScale; - CGFloat screenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]); - CGFloat screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]); - - if(currentSettings.externalDisplayMode.intValue == 1 && UIScreen.screens.count > 1){ + CGFloat safeAreaWidth = (window.frame.size.width - window.safeAreaInsets.left - window.safeAreaInsets.right) * screenScale; + CGFloat appWindowWidth = window.frame.size.width * screenScale; + CGFloat appWindowHeight = window.frame.size.height * screenScale; + + if(externalDisplayMode == 1 && UIScreen.screens.count > 1){ CGRect bounds = [UIScreen.screens.lastObject bounds]; screenScale = [UIScreen.screens.lastObject scale]; appWindowWidth = bounds.size.width * screenScale; appWindowHeight = bounds.size.height * screenScale; } - - bool needSwap = false; - if([self isFullScreenRequired]){ // if force fullscreen is enabled in app bundle, we use screen bounds to tell if a swap between width & height is needed - needSwap = (currentSettings.width.floatValue - currentSettings.height.floatValue) * (screenWidthInPoints - screenHeightInPoints) < 0; //update the current resolution accordingly - NSLog(@"need to swap width & height (non-app window mode): %d", needSwap); - if(needSwap){ - CGFloat tmpLength = currentSettings.width.floatValue; - currentSettings.width = @(currentSettings.height.floatValue); - currentSettings.height = @(tmpLength); - } + bool needSwapWidthAndHeight = appWindowWidth < appWindowHeight; + + resolutionTable[0] = CGSizeMake(1280, 720); + resolutionTable[1] = CGSizeMake(1920, 1080); + resolutionTable[2] = CGSizeMake(3840, 2160); + + for(uint8_t i=0;i<6;i++){ + CGFloat longSideLen = resolutionTable[i].height > resolutionTable[i].width ? resolutionTable[i].height : resolutionTable[i].width; + CGFloat shortSideLen = resolutionTable[i].height < resolutionTable[i].width ? resolutionTable[i].height : resolutionTable[i].width; + if(needSwapWidthAndHeight) resolutionTable[i] = CGSizeMake(shortSideLen, longSideLen); + else resolutionTable[i] = CGSizeMake(longSideLen, shortSideLen); } - else{// if force fullscreen is disabled in app bundle, we use appWindowSize to directly update or to get if we need a swap - if(currentSettings.resolutionSelected.intValue == 5){ // app window res, previous fullscreen, update resolution directly - currentSettings.width = @(appWindowWidth); - currentSettings.height = @(appWindowHeight); - NSLog(@"Directly Update app window resolution: %f, %f", appWindowWidth, appWindowHeight); - } - else if(currentSettings.resolutionSelected.intValue){ - needSwap = (currentSettings.width.floatValue - currentSettings.height.floatValue) * (appWindowWidth - appWindowHeight) < 0; - if(needSwap){ - CGFloat tmpLength = currentSettings.width.floatValue; - currentSettings.width = @(currentSettings.height.floatValue); - currentSettings.height = @(tmpLength); - NSLog(@"Swap resolution width & height"); - } - } + + // add app window resolution and not swap width and height + resolutionTable[3] = CGSizeMake(safeAreaWidth, appWindowHeight); + resolutionTable[4] = CGSizeMake(appWindowWidth, appWindowHeight); +} + +-(void) updateResolutionAccordingly { + DataManager* dataMan = [[DataManager alloc] init]; + Settings *currentSettings = [dataMan retrieveSettings]; + + CGSize tempResolutionTable[6] = {0}; + tempResolutionTable[5] = CGSizeMake(currentSettings.width.intValue, currentSettings.height.intValue); + [self fillResolutionTable:tempResolutionTable externalDisplayMode:currentSettings.externalDisplayMode.intValue]; + + int selectedIndex = currentSettings.resolutionSelected.intValue; + if (selectedIndex >= 0 && selectedIndex < 6) { + CGSize selectedSize = tempResolutionTable[selectedIndex]; + currentSettings.width = @(selectedSize.width); + currentSettings.height = @(selectedSize.height); + NSLog(@"Updated resolution to: %@ x %@", currentSettings.width, currentSettings.height); } + [dataMan saveData]; } diff --git a/VoidLink/ViewControllers/SettingsViewController.m b/VoidLink/ViewControllers/SettingsViewController.m index bdf40f51..5dd4c0d9 100644 --- a/VoidLink/ViewControllers/SettingsViewController.m +++ b/VoidLink/ViewControllers/SettingsViewController.m @@ -240,19 +240,8 @@ CGSize resolutionTable[RESOLUTION_TABLE_SIZE]; [super viewSafeAreaInsetsDidChange]; } -BOOL isCustomResolution(CGSize res) { - if (res.width == 0 && res.height == 0) { - return NO; - } - - for (int i = 0; i < RESOLUTION_TABLE_CUSTOM_INDEX; i++) { - NSLog(@"customRes: %f, %f, isrl: %f, %f", res.width, res.height, resolutionTable[i].width, resolutionTable[i].height); - if ((res.width == resolutionTable[i].width && res.height == resolutionTable[i].height) || (res.height == resolutionTable[i].width && res.width == resolutionTable[i].height)) { - return NO; - } - } - - return YES; +BOOL isCustomResolution(int resolutionSelected) { + return resolutionSelected == RESOLUTION_TABLE_CUSTOM_INDEX; } + (bool)isLandscapeNow { @@ -276,32 +265,10 @@ BOOL isCustomResolution(CGSize res) { - (void)updateResolutionTable{ if(self.mainFrameViewController.settingsExpandedInStreamView) return; - - UIWindow *window = self.view.window; - NSLog(@" window %@", window); - CGFloat screenScale = window.screen.scale; - CGFloat safeAreaWidth = (window.frame.size.width - window.safeAreaInsets.left - window.safeAreaInsets.right) * screenScale; - CGFloat appWindowWidth = window.frame.size.width * screenScale; - CGFloat appWindowHeight = window.frame.size.height * screenScale; - if([self isAirPlayEnabled] && UIScreen.screens.count > 1){ - CGRect bounds = [UIScreen.screens.lastObject bounds]; - screenScale = [UIScreen.screens.lastObject scale]; - appWindowWidth = bounds.size.width * screenScale; - appWindowHeight = bounds.size.height * screenScale; - } - - bool needSwapWidthAndHeight = appWindowWidth < appWindowHeight; - - for(uint8_t i=0;i<6;i++){ - CGFloat longSideLen = resolutionTable[i].height > resolutionTable[i].width ? resolutionTable[i].height : resolutionTable[i].width; - CGFloat shortSideLen = resolutionTable[i].height < resolutionTable[i].width ? resolutionTable[i].height : resolutionTable[i].width; - if(needSwapWidthAndHeight) resolutionTable[i] = CGSizeMake(shortSideLen, longSideLen); - else resolutionTable[i] = CGSizeMake(longSideLen, shortSideLen); - } - - resolutionTable[3] = CGSizeMake(safeAreaWidth, appWindowHeight); - resolutionTable[4] = CGSizeMake(appWindowWidth, appWindowHeight); + NSInteger externalDisplayMode = [self.externalDisplayModeSelector selectedSegmentIndex]; + // 调用主界面方法统一填充 resolutionTable + [self.mainFrameViewController fillResolutionTable:resolutionTable externalDisplayMode:externalDisplayMode]; [self updateResolutionDisplayLabel]; } @@ -335,8 +302,8 @@ BOOL isCustomResolution(CGSize res) { DataManager* dataMan = [[DataManager alloc] init]; TemporarySettings *currentSettings = [dataMan getSettings]; - CGSize currentResolution = CGSizeMake(currentSettings.width.intValue, currentSettings.height.intValue); - [self.customResolutionSwitch setOn: isCustomResolution(currentResolution)]; + //CGSize currentResolution = CGSizeMake(currentSettings.width.intValue, currentSettings.height.intValue); + [self.customResolutionSwitch setOn: isCustomResolution(currentSettings.resolutionSelected.intValue)]; [self.resolutionSelector setEnabled:!self.customResolutionSwitch.isOn]; } @@ -1326,12 +1293,8 @@ BOOL isCustomResolution(CGSize res) { [self.resolutionSelector removeSegmentAtIndex:0 animated:NO]; // remove 360p [self.resolutionSelector removeSegmentAtIndex:5 animated:NO]; // remove custom segment - resolutionTable[0] = CGSizeMake(1280, 720); - resolutionTable[1] = CGSizeMake(1920, 1080); - resolutionTable[2] = CGSizeMake(3840, 2160); - resolutionTable[3] = CGSizeMake(safeAreaWidth, fullScreenHeight); - resolutionTable[4] = CGSizeMake(fullScreenWidth, fullScreenHeight); resolutionTable[5] = CGSizeMake([currentSettings.width integerValue], [currentSettings.height integerValue]); // custom initial value + [self updateResolutionTable]; NSInteger framerate; @@ -2171,6 +2134,9 @@ BOOL isCustomResolution(CGSize res) { BOOL enableHdr = self.hdrSwitch.isOn; BOOL unlockDisplayOrientation = [self.unlockDisplayOrientationSelector selectedSegmentIndex] == 1; NSInteger resolutionSelected = [self.resolutionSelector selectedSegmentIndex]; + if (self.customResolutionSwitch.isOn) { + resolutionSelected = RESOLUTION_TABLE_CUSTOM_INDEX; + } NSInteger externalDisplayMode = [self.externalDisplayModeSelector selectedSegmentIndex]; NSInteger localMousePointerMode = [self.localMousePointerModeSelector selectedSegmentIndex]; NSInteger backgroundSessionTimer = self.backgroundSessionTimerSlider.value == self.backgroundSessionTimerSlider.maximumValue ? (uint32_t) INT16_MAX : (uint32_t)self.backgroundSessionTimerSlider.value;