From 7699e47157a8265a6d6dd2aa4dcca179046de170 Mon Sep 17 00:00:00 2001 From: xzzpig Date: Tue, 19 Nov 2024 09:48:23 +0800 Subject: [PATCH] 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 {