From bde477558f370d4b31e780fa58237916749e352e Mon Sep 17 00:00:00 2001 From: TrueZhuangjia Date: Sun, 24 Nov 2024 22:27:18 +0800 Subject: [PATCH] - changes on background resolution update. - disable allowPortrait setting option is force fullscreen is disabled in app bundle --- .../ViewControllers/MainFrameViewController.m | 35 ++++++++++++++----- .../ViewControllers/SettingsViewController.m | 22 +++++++++--- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index fcd616b3..9a3dd723 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -944,7 +944,7 @@ static NSMutableSet* hostList; [settingsViewController.framePacingSelector setEnabled:!self.settingsExpandedInStreamView]; [settingsViewController.btMouseSelector setEnabled:!self.settingsExpandedInStreamView]; [settingsViewController.goBackToStreamViewButton setEnabled:self.settingsExpandedInStreamView]; - [settingsViewController.allowPortraitSelector setEnabled:!self.settingsExpandedInStreamView]; + [settingsViewController.allowPortraitSelector setEnabled:!self.settingsExpandedInStreamView && [self isFullScreenRequired]];//need "requires fullscreen" enabled in the app bunddle to make runtime orientation limitation woring if (position == FrontViewPositionLeft) { [settingsViewController saveSettings]; @@ -1238,22 +1238,39 @@ static NSMutableSet* hostList; 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.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); - } + bool needSwap = false; - else if(currentSettings.resolutionSelected.intValue){ - bool needSwap = (appWindowWidth - appWindowHeight) * (currentSettings.width.floatValue - currentSettings.height.floatValue); + 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); - NSLog(@"Swap resolution width & height (non-app window)"); } } + 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"); + } + } + } + + + [dataMan saveData]; } diff --git a/Limelight/ViewControllers/SettingsViewController.m b/Limelight/ViewControllers/SettingsViewController.m index 4dd907c6..02a3a5a3 100644 --- a/Limelight/ViewControllers/SettingsViewController.m +++ b/Limelight/ViewControllers/SettingsViewController.m @@ -211,6 +211,18 @@ BOOL isCustomResolution(CGSize res) { return CGRectGetWidth([[UIScreen mainScreen]bounds]) > CGRectGetHeight([[UIScreen mainScreen]bounds]); } +- (bool)isFullScreenRequired { + NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; + NSNumber *requiresFullScreen = infoDictionary[@"UIRequiresFullScreen"]; + + if (requiresFullScreen != nil) { + return [requiresFullScreen boolValue]; + } + // Default behavior if the key is not set + return true; +} + + - (void)updateResolutionTable{ UIWindow *window = UIApplication.sharedApplication.windows.firstObject; CGFloat screenScale = window.screen.scale; @@ -451,11 +463,11 @@ BOOL isCustomResolution(CGSize res) { [self updateResolutionDisplayViewText]; // allow portrait setting - bool allowPortraitSelectorEnabled; - if (@available(iOS 16.0, *)) allowPortraitSelectorEnabled = true; //probably need iOS 16.0 to make runtime orientation limitation woring - else allowPortraitSelectorEnabled = false; - // [self.allowPortraitSelector setEnabled:allowPortraitSelectorEnabled]; //temporally enable this selector for test - [self.allowPortraitSelector setSelectedSegmentIndex:currentSettings.allowPortrait ? 1 : 0]; + bool allowPortraitSelectorEnabled = [self isFullScreenRequired];//need "requires fullscreen" enabled in the app bunddle to make runtime orientation limitation woring + if(allowPortraitSelectorEnabled) [self.allowPortraitSelector setSelectedSegmentIndex:currentSettings.allowPortrait ? 1 : 0]; + else [self.allowPortraitSelector setSelectedSegmentIndex:1]; // can't lock screen orientation in this mode = always allow portrait mode + [self.allowPortraitSelector setEnabled:allowPortraitSelectorEnabled]; + // lift streamview setting [self.liftStreamViewForKeyboardSelector setSelectedSegmentIndex:currentSettings.liftStreamViewForKeyboard ? 1 : 0];// Load old setting