refactor app window resolution update to mainFrameView

This commit is contained in:
TrueZhuangjia committed 2024-11-19 23:12:26 +08:00
1 parent ea89d0a822
commit be13295096
2 files changed
+52 -47

No files matched your search

@@ -912,7 +912,7 @@ static NSMutableSet* hostList;
dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
// Perform some task after the delay // Perform some task after the delay
dispatch_after(delayTime, dispatch_get_main_queue(), ^{// Code to execute after the delay dispatch_after(delayTime, dispatch_get_main_queue(), ^{// Code to execute after the delay
[self swapResolutionWidthHeightAccordingly]; // [self updateResolutionAccordingly];
[self.settingsButton setEnabled:![self isIPhonePortrait]]; //make sure settings button is disabled in iphone portrait mode. [self.settingsButton setEnabled:![self isIPhonePortrait]]; //make sure settings button is disabled in iphone portrait mode.
if([self->_upButton title] == nil) [self reloadScrollHostView]; // title of the _upButton is a good flag for judging if we're on the Host selection view if([self->_upButton title] == nil) [self reloadScrollHostView]; // title of the _upButton is a good flag for judging if we're on the Host selection view
//self->recordedScreenWidth = screenWidthInPoints; // kind of obselete, but i keep this in the code. //self->recordedScreenWidth = screenWidthInPoints; // kind of obselete, but i keep this in the code.
@@ -1148,10 +1148,10 @@ static NSMutableSet* hostList;
//if([SettingsViewController isLandscapeNow] != _streamConfig.width > _streamConfig.height) //if([SettingsViewController isLandscapeNow] != _streamConfig.width > _streamConfig.height)
//[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 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]; [self updateResolutionAccordingly];
SettingsViewController* settingsViewController = (SettingsViewController*)[self.revealViewController rearViewController]; // SettingsViewController* settingsViewController = (SettingsViewController*)[self.revealViewController rearViewController];
[settingsViewController updateResolutionTable]; // [settingsViewController updateResolutionTable];
} }
-(void)handleRealOrientationChange{ -(void)handleRealOrientationChange{
@@ -1195,33 +1195,44 @@ static NSMutableSet* hostList;
[self.view addSubview:hostScrollView]; [self.view addSubview:hostScrollView];
} }
// this will also be called back when device orientation changes
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
-(void) swapResolutionWidthHeightAccordingly { double delayInSeconds = 0.7;
return; // Convert the delay into a dispatch_time_t value
dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
// Perform some task after the delay
dispatch_after(delayTime, dispatch_get_main_queue(), ^{// Code to execute after the delay
[self updateResolutionAccordingly];
});
}
-(void) updateResolutionAccordingly {
DataManager* dataMan = [[DataManager alloc] init]; DataManager* dataMan = [[DataManager alloc] init];
Settings *currentSettings = [dataMan retrieveSettings]; Settings *currentSettings = [dataMan retrieveSettings];
UIWindow *window = UIApplication.sharedApplication.windows.firstObject; UIWindow *window = UIApplication.sharedApplication.windows.firstObject;
CGFloat screenScale = window.screen.scale; CGFloat screenScale = window.screen.scale;
CGFloat screenWidthInPoints = CGRectGetWidth(window.frame); CGFloat appWindowWidth = CGRectGetWidth(window.frame) * screenScale;
CGFloat screenHeightInPoints = CGRectGetHeight(window.frame); CGFloat appWindowHeight = CGRectGetHeight(window.frame) * screenScale;
CGFloat fullScreenWidth = screenWidthInPoints * screenScale;
CGFloat fullScreenHeight = screenHeightInPoints * screenScale;
bool needSwap = ((currentSettings.width.floatValue - currentSettings.height.floatValue) * if(currentSettings.resolutionSelected.intValue == 5){ // app window res, previous fullscreen, update resolution directly
(fullScreenWidth - fullScreenHeight)) < 0; currentSettings.width = @(appWindowWidth);
currentSettings.height = @(appWindowHeight);
NSLog(@"Current screen size: %.0f x %.0f", fullScreenWidth, fullScreenHeight); NSLog(@"Directly Update app window resolution: %f, %f", appWindowWidth, appWindowHeight);
NSLog(@"Current setting size: %.0f x %.0f", currentSettings.width.floatValue, currentSettings.height.floatValue); }
NSLog(@"Need to swap width & height: %d", needSwap);
else if(currentSettings.resolutionSelected.intValue){
bool needSwap = (appWindowWidth - appWindowHeight) * (currentSettings.width.floatValue - currentSettings.height.floatValue);
if(needSwap){ if(needSwap){
CGFloat tmpLength = currentSettings.width.floatValue; CGFloat tmpLength = currentSettings.width.floatValue;
currentSettings.width = @(currentSettings.height.floatValue); currentSettings.width = @(currentSettings.height.floatValue);
currentSettings.height = @(tmpLength); currentSettings.height = @(tmpLength);
[dataMan saveData]; NSLog(@"Swap resolution width & height (non-app window)");
} }
} }
[dataMan saveData];
}
#if TARGET_OS_TV #if TARGET_OS_TV
-(void)handleCollectionViewLongPress:(UILongPressGestureRecognizer *)gestureRecognizer -(void)handleCollectionViewLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
@@ -1347,7 +1358,7 @@ static NSMutableSet* hostList;
object: nil]; object: nil];
//[self simulateSettingsButtonPress]; //force reload resolution table in the setting //[self simulateSettingsButtonPress]; //force reload resolution table in the setting
//[self simulateSettingsButtonPress]; //[self simulateSettingsButtonPress];
[self swapResolutionWidthHeightAccordingly]; [self updateResolutionAccordingly];
} }
@@ -215,44 +215,43 @@ BOOL isCustomResolution(CGSize res) {
UIWindow *window = UIApplication.sharedApplication.windows.firstObject; UIWindow *window = UIApplication.sharedApplication.windows.firstObject;
CGFloat screenScale = window.screen.scale; CGFloat screenScale = window.screen.scale;
CGFloat safeAreaWidth = (window.frame.size.width - window.safeAreaInsets.left - window.safeAreaInsets.right) * screenScale; CGFloat safeAreaWidth = (window.frame.size.width - window.safeAreaInsets.left - window.safeAreaInsets.right) * screenScale;
CGFloat fullScreenWidth = window.frame.size.width * screenScale; CGFloat appWindowWidth = window.frame.size.width * screenScale;
CGFloat fullScreenHeight = window.frame.size.height * screenScale; CGFloat appWindowHeight = window.frame.size.height * screenScale;
bool isLandscapeNow = fullScreenWidth > fullScreenHeight; bool needSwapWidthAndHeight = appWindowWidth > appWindowHeight;
resolutionTable[4] = CGSizeMake(safeAreaWidth, fullScreenHeight); resolutionTable[4] = CGSizeMake(safeAreaWidth, appWindowHeight);
resolutionTable[5] = CGSizeMake(fullScreenWidth, fullScreenHeight);
for(uint8_t i=0;i<7;i++){ for(uint8_t i=0;i<7;i++){
CGFloat longSideLen = resolutionTable[i].height > resolutionTable[i].width ? resolutionTable[i].height : resolutionTable[i].width; 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; CGFloat shortSideLen = resolutionTable[i].height < resolutionTable[i].width ? resolutionTable[i].height : resolutionTable[i].width;
if(isLandscapeNow) resolutionTable[i] = CGSizeMake(longSideLen, shortSideLen); if(needSwapWidthAndHeight) resolutionTable[i] = CGSizeMake(longSideLen, shortSideLen);
else resolutionTable[i] = CGSizeMake(shortSideLen, longSideLen); else resolutionTable[i] = CGSizeMake(shortSideLen, longSideLen);
} }
[self updateResolutionSettings]; resolutionTable[5] = CGSizeMake(appWindowWidth, appWindowHeight);
[self updateResolutionDisplayViewText]; [self updateResolutionDisplayViewText];
} }
- (void)updateResolutionSettings{ // this will also be called back when device orientation changes
DataManager* dataMgr = [[DataManager alloc] init]; - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
Settings *currentSettings = [dataMgr retrieveSettings]; [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
int resolution = currentSettings.resolutionSelected.intValue; double delayInSeconds = 1.0;
// Convert the delay into a dispatch_time_t value
if(resolution==4 || resolution==5){ dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
currentSettings.width = @(resolutionTable[resolution].width); // Perform some task after the delay
currentSettings.height = @(resolutionTable[resolution].height); dispatch_after(delayTime, dispatch_get_main_queue(), ^{// Code to execute after the delay
NSLog(@"Modify setting width & height: %.0f x %.0f", currentSettings.width.floatValue, currentSettings.height.floatValue); [self updateResolutionTable];
[dataMgr saveData]; });
}
} }
- (void)viewDidAppear:(BOOL)animated{ - (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated]; [super viewDidAppear:animated];
[self updateResolutionTable]; [self updateResolutionTable];
//NSLog(@"osc tool fingers setting test: %d", currentSettings.oscLayoutToolFingers.intValue); NSLog(@"Resolution table updated");
} }
- (void)deviceOrientationDidChange{ - (void)deviceOrientationDidChange{
double delayInSeconds = 1.0; double delayInSeconds = 1.0;
// Convert the delay into a dispatch_time_t value // Convert the delay into a dispatch_time_t value
@@ -260,11 +259,12 @@ BOOL isCustomResolution(CGSize res) {
// Perform some task after the delay // Perform some task after the delay
dispatch_after(delayTime, dispatch_get_main_queue(), ^{ dispatch_after(delayTime, dispatch_get_main_queue(), ^{
// Code to execute after the delay // Code to execute after the delay
NSLog(@"Resolution table to be updated"); // [self updateResolutionTable];
[self updateResolutionTable]; // since we have viewWillTransitionToSize being called back both when orientation changed & app window size changed, resoltion update is dprecated here
}); });
} }
- (void)simulateSettingsButtonPress{ - (void)simulateSettingsButtonPress{
[self.mainFrameViewController simulateSettingsButtonPress]; [self.mainFrameViewController simulateSettingsButtonPress];
} }
@@ -1087,10 +1087,4 @@ BOOL isCustomResolution(CGSize res) {
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
} }
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[self deviceOrientationDidChange];
}
@end @end