From 978c50c271be3956186e00a22b20fae2ff046c86 Mon Sep 17 00:00:00 2001 From: xzzpig Date: Mon, 18 Nov 2024 20:46:44 +0800 Subject: [PATCH 1/3] Add support to change app size --- Limelight/Limelight-Info.plist | 2 -- .../ViewControllers/MainFrameViewController.m | 29 ++++++++++++++----- .../ViewControllers/SettingsViewController.m | 5 ++++ .../StreamFrameViewController.m | 7 +++++ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Limelight/Limelight-Info.plist b/Limelight/Limelight-Info.plist index f29ea4d0..e3f9934d 100644 --- a/Limelight/Limelight-Info.plist +++ b/Limelight/Limelight-Info.plist @@ -73,8 +73,6 @@ armv7 - UIRequiresFullScreen - UIStatusBarHidden UISupportedInterfaceOrientations diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 0588c3ac..10aac83f 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -1151,6 +1151,11 @@ static NSMutableSet* hostList; [self swapResolutionWidthHeightAccordingly]; } +- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { + [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + + [self handleOrientationChange]; +} -(void)handleRealOrientationChange{ @@ -1194,14 +1199,25 @@ static NSMutableSet* hostList; } --(void)swapResolutionWidthHeightAccordingly{ +-(void) swapResolutionWidthHeightAccordingly { DataManager* dataMan = [[DataManager alloc] init]; Settings *currentSettings = [dataMan retrieveSettings]; - CGFloat screenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]); - CGFloat screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]); - bool needSwap = ((currentSettings.width.floatValue - currentSettings.height.floatValue) * (screenWidthInPoints - screenHeightInPoints)) < 0; //update the current resolution accordingly - NSLog(@"need to swap width & height: %d", needSwap); - if(needSwap){ + + UIWindow *window = UIApplication.sharedApplication.windows.firstObject; + CGFloat screenScale = window.screen.scale; + CGFloat screenWidthInPoints = CGRectGetWidth(window.frame); + CGFloat screenHeightInPoints = CGRectGetHeight(window.frame); + CGFloat fullScreenWidth = screenWidthInPoints * screenScale; + CGFloat fullScreenHeight = screenHeightInPoints * screenScale; + + bool needSwap = ((currentSettings.width.floatValue - currentSettings.height.floatValue) * + (fullScreenWidth - fullScreenHeight)) < 0; + + NSLog(@"Current screen size: %.0f x %.0f", fullScreenWidth, fullScreenHeight); + NSLog(@"Current setting size: %.0f x %.0f", currentSettings.width.floatValue, currentSettings.height.floatValue); + NSLog(@"Need to swap width & height: %d", needSwap); + + if(needSwap) { CGFloat tmpLength = currentSettings.width.floatValue; currentSettings.width = @(currentSettings.height.floatValue); currentSettings.height = @(tmpLength); @@ -1209,7 +1225,6 @@ static NSMutableSet* hostList; } } - #if TARGET_OS_TV -(void)handleCollectionViewLongPress:(UILongPressGestureRecognizer *)gestureRecognizer { diff --git a/Limelight/ViewControllers/SettingsViewController.m b/Limelight/ViewControllers/SettingsViewController.m index f3ba2808..cbfc2767 100644 --- a/Limelight/ViewControllers/SettingsViewController.m +++ b/Limelight/ViewControllers/SettingsViewController.m @@ -1073,5 +1073,10 @@ BOOL isCustomResolution(CGSize res) { - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { } +- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { + [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + + [self deviceOrientationDidChange]; +} @end diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 19a19f32..3af3db5b 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -860,4 +860,11 @@ } #endif +- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { + [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + + Log(LOG_I, @"View size changed, terminating stream"); + [self returnToMainFrame]; +} + @end From 7699e47157a8265a6d6dd2aa4dcca179046de170 Mon Sep 17 00:00:00 2001 From: xzzpig Date: Tue, 19 Nov 2024 09:48:23 +0800 Subject: [PATCH 2/3] Modify the logic for saving resolution settings --- Limelight/Database/DataManager.h | 3 +- Limelight/Database/DataManager.m | 4 +- Limelight/Database/TemporarySettings.h | 1 + Limelight/Database/TemporarySettings.m | 1 + .../Limelight.xcdatamodeld/.xccurrentversion | 2 +- .../Moonlight v1.11.xcdatamodel/contents | 57 +++++++++++++++++++ .../ViewControllers/MainFrameViewController.m | 7 +-- .../ViewControllers/SettingsViewController.m | 32 ++++++++--- 8 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 Limelight/Limelight.xcdatamodeld/Moonlight v1.11.xcdatamodel/contents diff --git a/Limelight/Database/DataManager.h b/Limelight/Database/DataManager.h index c6e00979..fd6e03ec 100644 --- a/Limelight/Database/DataManager.h +++ b/Limelight/Database/DataManager.h @@ -42,7 +42,8 @@ // absoluteTouchMode:(BOOL)absoluteTouchMode touchMode:(NSInteger)touchMode statsOverlay:(BOOL)statsOverlay - allowPortrait:(BOOL)allowPortrait; + allowPortrait:(BOOL)allowPortrait + resolutionSelected:(NSInteger)resolutionSelected; - (NSArray*) getHosts; - (void) updateHost:(TemporaryHost*)host; diff --git a/Limelight/Database/DataManager.m b/Limelight/Database/DataManager.m index 407194e9..95be2e2d 100644 --- a/Limelight/Database/DataManager.m +++ b/Limelight/Database/DataManager.m @@ -81,7 +81,8 @@ // absoluteTouchMode:(BOOL)absoluteTouchMode touchMode:(NSInteger)touchMode statsOverlay:(BOOL)statsOverlay - allowPortrait:(BOOL)allowPortrait{ + allowPortrait:(BOOL)allowPortrait + resolutionSelected:(NSInteger)resolutionSelected { [_managedObjectContext performBlockAndWait:^{ Settings* settingsToSave = [self retrieveSettings]; @@ -115,6 +116,7 @@ settingsToSave.touchMode = [NSNumber numberWithInteger:(uint16_t)touchMode]; settingsToSave.statsOverlay = statsOverlay; settingsToSave.allowPortrait = allowPortrait; + settingsToSave.resolutionSelected = [NSNumber numberWithInteger:resolutionSelected]; [self saveData]; }]; diff --git a/Limelight/Database/TemporarySettings.h b/Limelight/Database/TemporarySettings.h index 7e58f722..1c238c05 100644 --- a/Limelight/Database/TemporarySettings.h +++ b/Limelight/Database/TemporarySettings.h @@ -33,6 +33,7 @@ @property (nonatomic, retain) NSNumber * mousePointerVelocityFactor; @property (nonatomic, retain) NSNumber * pointerVelocityModeDivider; @property (nonatomic, retain) NSString * uniqueId; +@property (nonatomic, retain) NSNumber * resolutionSelected; @property (nonatomic) enum { CODEC_PREF_AUTO, CODEC_PREF_H264, diff --git a/Limelight/Database/TemporarySettings.m b/Limelight/Database/TemporarySettings.m index 75d66e23..c3eef3c0 100644 --- a/Limelight/Database/TemporarySettings.m +++ b/Limelight/Database/TemporarySettings.m @@ -99,6 +99,7 @@ self.mousePointerVelocityFactor = settings.mousePointerVelocityFactor; self.pointerVelocityModeDivider = settings.pointerVelocityModeDivider; self.allowPortrait = settings.allowPortrait; + self.resolutionSelected = settings.resolutionSelected; #endif self.uniqueId = settings.uniqueId; diff --git a/Limelight/Limelight.xcdatamodeld/.xccurrentversion b/Limelight/Limelight.xcdatamodeld/.xccurrentversion index b202eb9f..cffa4ac2 100644 --- a/Limelight/Limelight.xcdatamodeld/.xccurrentversion +++ b/Limelight/Limelight.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - Moonlight v1.10.xcdatamodel + Moonlight v1.11.xcdatamodel diff --git a/Limelight/Limelight.xcdatamodeld/Moonlight v1.11.xcdatamodel/contents b/Limelight/Limelight.xcdatamodeld/Moonlight v1.11.xcdatamodel/contents new file mode 100644 index 00000000..16301b49 --- /dev/null +++ b/Limelight/Limelight.xcdatamodeld/Moonlight v1.11.xcdatamodel/contents @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 10aac83f..2c1e63eb 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -1151,12 +1151,6 @@ static NSMutableSet* hostList; [self swapResolutionWidthHeightAccordingly]; } -- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { - [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; - - [self handleOrientationChange]; -} - -(void)handleRealOrientationChange{ } @@ -1200,6 +1194,7 @@ static NSMutableSet* hostList; -(void) swapResolutionWidthHeightAccordingly { + return; DataManager* dataMan = [[DataManager alloc] init]; Settings *currentSettings = [dataMan retrieveSettings]; diff --git a/Limelight/ViewControllers/SettingsViewController.m b/Limelight/ViewControllers/SettingsViewController.m index cbfc2767..587b4df6 100644 --- a/Limelight/ViewControllers/SettingsViewController.m +++ b/Limelight/ViewControllers/SettingsViewController.m @@ -217,6 +217,7 @@ BOOL isCustomResolution(CGSize res) { CGFloat safeAreaWidth = (window.frame.size.width - window.safeAreaInsets.left - window.safeAreaInsets.right) * screenScale; CGFloat fullScreenWidth = window.frame.size.width * screenScale; CGFloat fullScreenHeight = window.frame.size.height * screenScale; + bool isLandscapeNow = fullScreenWidth > fullScreenHeight; resolutionTable[4] = CGSizeMake(safeAreaWidth, fullScreenHeight); resolutionTable[5] = CGSizeMake(fullScreenWidth, fullScreenHeight); @@ -224,13 +225,27 @@ BOOL isCustomResolution(CGSize res) { for(uint8_t i=0;i<7;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([SettingsViewController isLandscapeNow]) resolutionTable[i] = CGSizeMake(longSideLen, shortSideLen); + if(isLandscapeNow) resolutionTable[i] = CGSizeMake(longSideLen, shortSideLen); else resolutionTable[i] = CGSizeMake(shortSideLen, longSideLen); } + [self updateResolutionSettings]; [self updateResolutionDisplayViewText]; } +- (void)updateResolutionSettings{ + DataManager* dataMgr = [[DataManager alloc] init]; + Settings *currentSettings = [dataMgr retrieveSettings]; + int resolution = currentSettings.resolutionSelected.intValue; + + if(resolution==4 || resolution==5){ + currentSettings.width = @(resolutionTable[resolution].width); + currentSettings.height = @(resolutionTable[resolution].height); + NSLog(@"Modify setting width & height: %.0f x %.0f", currentSettings.width.floatValue, currentSettings.height.floatValue); + [dataMgr saveData]; + } +} + - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; [self updateResolutionTable]; @@ -359,13 +374,10 @@ BOOL isCustomResolution(CGSize res) { break; } - NSInteger resolution = 1; - for (int i = 0; i < RESOLUTION_TABLE_SIZE; i++) { - if (((int) resolutionTable[i].height == [currentSettings.height intValue] && (int) resolutionTable[i].width == [currentSettings.width intValue]) || ((int) resolutionTable[i].width == [currentSettings.height intValue] && (int) resolutionTable[i].height == [currentSettings.width intValue])){ - resolution = i; - break; - } - } + NSInteger resolution = currentSettings.resolutionSelected.integerValue; + if(resolution >= RESOLUTION_TABLE_SIZE){ + resolution = 0; + } // Only show the 120 FPS option if we have a > 60-ish Hz display bool enable120Fps = false; @@ -1030,6 +1042,7 @@ BOOL isCustomResolution(CGSize res) { BOOL statsOverlay = [self.statsOverlaySelector selectedSegmentIndex] == 1; BOOL enableHdr = [self.hdrSelector selectedSegmentIndex] == 1; BOOL allowPortrait = [self.allowPortraitSelector selectedSegmentIndex] == 1; + NSInteger resolutionSelected = [self.resolutionSelector selectedSegmentIndex]; [dataMan saveSettingsWithBitrate:_bitrate framerate:framerate height:height @@ -1059,7 +1072,8 @@ BOOL isCustomResolution(CGSize res) { // absoluteTouchMode:absoluteTouchMode touchMode:touchMode statsOverlay:statsOverlay - allowPortrait:allowPortrait]; + allowPortrait:allowPortrait + resolutionSelected:resolutionSelected]; } - (void)didReceiveMemoryWarning { From d7bb9483e4519d6de85b3b552393cca6705404f9 Mon Sep 17 00:00:00 2001 From: xzzpig Date: Tue, 19 Nov 2024 14:56:33 +0800 Subject: [PATCH 3/3] Update resolution table when mainView loaded --- Limelight/ViewControllers/MainFrameViewController.m | 3 +++ Limelight/ViewControllers/SettingsViewController.h | 1 + 2 files changed, 4 insertions(+) diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 2c1e63eb..95137f60 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -1149,6 +1149,9 @@ static NSMutableSet* hostList; //[self simulateSettingsButtonPress]; //force expand setting view if orientation changed since last quit from app. //[self simulateSettingsButtonPress]; //force expand setting view if orientation changed since last quit from app. [self swapResolutionWidthHeightAccordingly]; + + SettingsViewController* settingsViewController = (SettingsViewController*)[self.revealViewController rearViewController]; + [settingsViewController updateResolutionTable]; } -(void)handleRealOrientationChange{ diff --git a/Limelight/ViewControllers/SettingsViewController.h b/Limelight/ViewControllers/SettingsViewController.h index d7c22125..852a5e77 100644 --- a/Limelight/ViewControllers/SettingsViewController.h +++ b/Limelight/ViewControllers/SettingsViewController.h @@ -68,6 +68,7 @@ - (void) saveSettings; + (bool) isLandscapeNow; +- (void)updateResolutionTable; - (void) widget:(UISlider*)widget setEnabled:(bool)enabled; @end