From 549f754be277e443a9def4ac0ac022a7a2b5f394 Mon Sep 17 00:00:00 2001 From: rogerman Date: Fri, 12 Feb 2016 08:50:35 +0000 Subject: [PATCH] Cocoa Port: - Fix bug where restoring full screen windows on startup would fail. (Regression from r5349.) - Fix bug where the dock would fail to reappear when the last window exited full screen mode. (Regression from r5349.) --- .../userinterface/DisplayWindowController.h | 7 +++- .../userinterface/DisplayWindowController.mm | 40 +++++++++++++++---- .../src/cocoa/userinterface/appDelegate.mm | 8 ++-- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/desmume/src/cocoa/userinterface/DisplayWindowController.h b/desmume/src/cocoa/userinterface/DisplayWindowController.h index 5eb5366ab..9354314e3 100644 --- a/desmume/src/cocoa/userinterface/DisplayWindowController.h +++ b/desmume/src/cocoa/userinterface/DisplayWindowController.h @@ -113,7 +113,9 @@ class OGLVideoOutput; NSUInteger _statusBarHeight; BOOL _isUpdatingDisplayScaleValueOnly; BOOL _useMavericksFullScreen; - BOOL _willRestoreStatusBarFromFullScreen; + BOOL _masterStatusBarState; + NSRect _masterWindowFrame; + double _masterWindowScale; OSSpinLock spinlockScale; OSSpinLock spinlockRotation; @@ -161,6 +163,9 @@ class OGLVideoOutput; - (double) maxScalarForContentBoundsWidth:(double)contentBoundsWidth height:(double)contentBoundsHeight; - (void) enterFullScreen; - (void) exitFullScreen; +- (BOOL) masterStatusBarState; +- (NSRect) masterWindowFrame; +- (double) masterWindowScale; - (IBAction) copy:(id)sender; - (IBAction) changeHardwareMicGain:(id)sender; diff --git a/desmume/src/cocoa/userinterface/DisplayWindowController.mm b/desmume/src/cocoa/userinterface/DisplayWindowController.mm index 98b5efe9c..d7132d569 100644 --- a/desmume/src/cocoa/userinterface/DisplayWindowController.mm +++ b/desmume/src/cocoa/userinterface/DisplayWindowController.mm @@ -110,12 +110,14 @@ static std::unordered_map _screenMap; // _displayMode = DS_DISPLAY_TYPE_DUAL; _displayOrientation = DS_DISPLAY_ORIENTATION_VERTICAL; - _minDisplayViewSize = NSMakeSize(GPU_DISPLAY_WIDTH, GPU_DISPLAY_HEIGHT*2.0 + (DS_DISPLAY_UNSCALED_GAP*_displayGap)); + _minDisplayViewSize = NSMakeSize(GPU_DISPLAY_WIDTH, (GPU_DISPLAY_HEIGHT*2.0) + (DS_DISPLAY_UNSCALED_GAP*_displayGap)); _isMinSizeNormal = YES; _statusBarHeight = WINDOW_STATUS_BAR_HEIGHT; _isUpdatingDisplayScaleValueOnly = NO; _useMavericksFullScreen = IsOSXVersionSupported(10, 9, 0); - _willRestoreStatusBarFromFullScreen = NO; + _masterWindowScale = 1.0; + _masterWindowFrame = NSMakeRect(0.0, 0.0, GPU_DISPLAY_WIDTH, (GPU_DISPLAY_HEIGHT*2.0) + (DS_DISPLAY_UNSCALED_GAP*_displayGap)); + _masterStatusBarState = NO; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveScreenshotAsFinish:) @@ -1420,7 +1422,7 @@ static std::unordered_map _screenMap; // - (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions { - [[NSApplication sharedApplication] setPresentationOptions:(NSApplicationPresentationHideDock)]; + [[NSApplication sharedApplication] setPresentationOptions:NSApplicationPresentationHideDock]; NSApplicationPresentationOptions options = (NSApplicationPresentationHideDock | NSApplicationPresentationAutoHideMenuBar | @@ -1436,19 +1438,44 @@ static std::unordered_map _screenMap; // - (void)windowWillEnterFullScreen:(NSNotification *)notification { - _willRestoreStatusBarFromFullScreen = [self isShowingStatusBar]; + _masterWindowScale = [self displayScale]; + _masterWindowFrame = [masterWindow frame]; + _masterStatusBarState = [self isShowingStatusBar]; [self setIsShowingStatusBar:NO]; } - (void)windowDidEnterFullScreen:(NSNotification *)notification { - [self setAssignedScreen:[masterWindow screen]]; + NSScreen *targetScreen = [masterWindow screen]; + [self setAssignedScreen:targetScreen]; + _screenMap[targetScreen] = self; } - (void)windowWillExitFullScreen:(NSNotification *)notification { + _screenMap.erase([self assignedScreen]); [self setAssignedScreen:nil]; - [self setIsShowingStatusBar:_willRestoreStatusBarFromFullScreen]; + [self setIsShowingStatusBar:_masterStatusBarState]; + + if (_screenMap.size() == 0) + { + [[NSApplication sharedApplication] setPresentationOptions:NSApplicationPresentationDefault]; + } +} + +- (BOOL) masterStatusBarState +{ + return ([self assignedScreen] == nil) ? [self isShowingStatusBar] : _masterStatusBarState; +} + +- (NSRect) masterWindowFrame +{ + return ([self assignedScreen] == nil) ? [masterWindow frame] : _masterWindowFrame; +} + +- (double) masterWindowScale +{ + return ([self assignedScreen] == nil) ? [self displayScale] : _masterWindowScale; } #endif @@ -1529,7 +1556,6 @@ static std::unordered_map _screenMap; // { [theItem setLabel:NSSTRING_TITLE_ENABLE_HUD]; } - } return enable; diff --git a/desmume/src/cocoa/userinterface/appDelegate.mm b/desmume/src/cocoa/userinterface/appDelegate.mm index 43da8aa52..0bd1a5732 100644 --- a/desmume/src/cocoa/userinterface/appDelegate.mm +++ b/desmume/src/cocoa/userinterface/appDelegate.mm @@ -699,7 +699,7 @@ if (isInFullScreenMode && ([[NSScreen screens] indexOfObject:[[windowController window] screen]] == screenIndex)) { - [windowController enterFullScreen]; + [windowController toggleFullScreenDisplay:self]; [[windowController window] makeKeyAndOrderFront:self]; [[windowController window] makeMainWindow]; } @@ -722,13 +722,13 @@ const BOOL isInFullScreenMode = ([windowController assignedScreen] != nil); const NSUInteger screenIndex = [[NSScreen screens] indexOfObject:[[windowController masterWindow] screen]]; - const NSRect windowFrame = [[windowController masterWindow] frame]; + const NSRect windowFrame = [windowController masterWindowFrame]; NSString *windowFrameStr = [NSString stringWithFormat:@"%i %i %i %i", (int)windowFrame.origin.x, (int)windowFrame.origin.y, (int)windowFrame.size.width, (int)windowFrame.size.height]; NSDictionary *windowProperties = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInteger:[windowController displayMode]], @"displayMode", - [NSNumber numberWithDouble:[windowController displayScale]], @"displayScale", + [NSNumber numberWithDouble:[windowController masterWindowScale]], @"displayScale", [NSNumber numberWithDouble:[windowController displayRotation]], @"displayRotation", [NSNumber numberWithInteger:[windowController displayOrientation]], @"displayOrientation", [NSNumber numberWithInteger:[windowController displayOrder]], @"displayOrder", @@ -747,7 +747,7 @@ [NSNumber numberWithBool:[[windowController view] isHUDCPULoadAverageVisible]], @"hudShowCPULoadAverage", [NSNumber numberWithBool:[[windowController view] isHUDRealTimeClockVisible]], @"hudShowRTC", [NSNumber numberWithBool:[windowController isMinSizeNormal]], @"isMinSizeNormal", - [NSNumber numberWithBool:[windowController isShowingStatusBar]], @"isShowingStatusBar", + [NSNumber numberWithBool:[windowController masterStatusBarState]], @"isShowingStatusBar", [NSNumber numberWithBool:isInFullScreenMode], @"isInFullScreenMode", [NSNumber numberWithUnsignedInteger:screenIndex], @"screenIndex", windowFrameStr, @"windowFrame",