From c7c0902a53ddad9493f0f8cef47eb02c2e35f95c Mon Sep 17 00:00:00 2001 From: Kazuki Sakamoto Date: Mon, 12 Sep 2016 21:55:00 -0700 Subject: [PATCH] Fix Yosemite tabbar style check code Use NSAppKitVersionNumber instead of MAC_OS_X_VERSION_MIN_REQUIRED --- src/MacVim/MMFullScreenWindow.m | 8 ++------ src/MacVim/MMVimView.m | 22 ++++++++++----------- src/MacVim/MMWindowController.m | 34 ++++++++++++++++++++------------- src/MacVim/MacVim.h | 3 +++ src/MacVim/Miscellaneous.h | 3 +++ src/MacVim/Miscellaneous.m | 9 +++++++++ 6 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/MacVim/MMFullScreenWindow.m b/src/MacVim/MMFullScreenWindow.m index 001db49d06..521016599b 100644 --- a/src/MacVim/MMFullScreenWindow.m +++ b/src/MacVim/MMFullScreenWindow.m @@ -164,12 +164,8 @@ enum { oldTabBarStyle = [[view tabBarControl] styleName]; - NSString *style; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 - style = @"Yosemite"; -#else - style = @"Unified"; -#endif + NSString *style = + shouldUseYosemiteTabBarStyle() ? @"Yosemite" : @"Unified"; [[view tabBarControl] setStyleNamed:style]; // add text view diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m index 693723eb74..f62e2aec36 100644 --- a/src/MacVim/MMVimView.m +++ b/src/MacVim/MMVimView.m @@ -125,18 +125,18 @@ enum { [tabBarControl setDelegate:self]; [tabBarControl setHidden:YES]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 - CGFloat screenWidth = [[NSScreen mainScreen] frame].size.width; - [tabBarControl setStyleNamed:@"Yosemite"]; - [tabBarControl setCellMinWidth:120]; - [tabBarControl setCellMaxWidth:screenWidth]; - [tabBarControl setCellOptimumWidth:screenWidth]; -#else - [tabBarControl setCellMinWidth:[ud integerForKey:MMTabMinWidthKey]]; - [tabBarControl setCellMaxWidth:[ud integerForKey:MMTabMaxWidthKey]]; - [tabBarControl setCellOptimumWidth: + if (shouldUseYosemiteTabBarStyle()) { + CGFloat screenWidth = [[NSScreen mainScreen] frame].size.width; + [tabBarControl setStyleNamed:@"Yosemite"]; + [tabBarControl setCellMinWidth:120]; + [tabBarControl setCellMaxWidth:screenWidth]; + [tabBarControl setCellOptimumWidth:screenWidth]; + } else { + [tabBarControl setCellMinWidth:[ud integerForKey:MMTabMinWidthKey]]; + [tabBarControl setCellMaxWidth:[ud integerForKey:MMTabMaxWidthKey]]; + [tabBarControl setCellOptimumWidth: [ud integerForKey:MMTabOptimumWidthKey]]; -#endif + } [tabBarControl setShowAddTabButton:[ud boolForKey:MMShowAddTabButtonKey]]; [[tabBarControl addTabButton] setTarget:self]; diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index d838afbb73..ca9db5e592 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -80,15 +80,6 @@ #define FUOPT_BGCOLOR_HLGROUP 0x004 -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 -# define TABBAR_STYLE_UNIFIED @"Yosemite" -# define TABBAR_STYLE_METAL @"Yosemite" -#else -# define TABBAR_STYLE_UNIFIED @"Unified" -# define TABBAR_STYLE_METAL @"Metal" -#endif - - @interface MMWindowController (Private) - (NSSize)contentSize; - (void)resizeWindowToFitContentSize:(NSSize)contentSize @@ -106,6 +97,8 @@ - (void)applicationDidChangeScreenParameters:(NSNotification *)notification; - (void)enterNativeFullScreen; - (void)processAfterWindowPresentedQueue; ++ (NSString *)tabBarStyleForUnified; ++ (NSString *)tabBarStyleForMetal; @end @@ -1187,7 +1180,8 @@ [[window animator] setAlphaValue:0]; } completionHandler:^{ [window setStyleMask:([window styleMask] | NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_UNIFIED]; + NSString *tabBarStyle = [[self class] tabBarStyleForUnified]; + [[vimView tabBarControl] setStyleNamed:tabBarStyle]; [self updateTablineSeparator]; // Stay dark for some time to wait for things to sync, then do the full screen operation @@ -1251,7 +1245,8 @@ fullScreenEnabled = NO; [window setAlphaValue:1]; [window setStyleMask:([window styleMask] & ~NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_METAL]; + NSString *tabBarStyle = [[self class] tabBarStyleForMetal]; + [[vimView tabBarControl] setStyleNamed:tabBarStyle]; [self updateTablineSeparator]; [window setFrame:preFullScreenFrame display:YES]; } @@ -1281,7 +1276,8 @@ [[window animator] setAlphaValue:0]; } completionHandler:^{ [window setStyleMask:([window styleMask] & ~NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_METAL]; + NSString *tabBarStyle = [[self class] tabBarStyleForMetal]; + [[vimView tabBarControl] setStyleNamed:tabBarStyle]; [self updateTablineSeparator]; [window setFrame:preFullScreenFrame display:YES]; @@ -1328,7 +1324,8 @@ fullScreenEnabled = YES; [window setAlphaValue:1]; [window setStyleMask:([window styleMask] | NSFullScreenWindowMask)]; - [[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_UNIFIED]; + NSString *tabBarStyle = [[self class] tabBarStyleForUnified]; + [[vimView tabBarControl] setStyleNamed:tabBarStyle]; [self updateTablineSeparator]; [self maximizeWindow:fullScreenOptions]; } @@ -1691,5 +1688,16 @@ [afterWindowPresentedQueue release]; afterWindowPresentedQueue = nil; } + ++ (NSString *)tabBarStyleForUnified +{ + return shouldUseYosemiteTabBarStyle() ? @"Yosemite" : @"Unified"; +} + ++ (NSString *)tabBarStyleForMetal +{ + return shouldUseYosemiteTabBarStyle() ? @"Yosemite" : @"Metal"; +} + @end // MMWindowController (Private) diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 570ee79554..48db665d31 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -30,6 +30,9 @@ #endif // Needed for pre-10.11 SDK +#ifndef NSAppKitVersionNumber10_10 +# define NSAppKitVersionNumber10_10 1343 +#endif #ifndef NSAppKitVersionNumber10_10_Max # define NSAppKitVersionNumber10_10_Max 1349 #endif diff --git a/src/MacVim/Miscellaneous.h b/src/MacVim/Miscellaneous.h index 263917eea8..909484daec 100644 --- a/src/MacVim/Miscellaneous.h +++ b/src/MacVim/Miscellaneous.h @@ -151,3 +151,6 @@ NSView *showHiddenFilesView(); // http://www.unicode.org/reports/tr15/ NSString *normalizeFilename(NSString *filename); NSArray *normalizeFilenames(NSArray *filenames); + + +BOOL shouldUseYosemiteTabBarStyle(); diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m index bba9d280cf..8cb83ea84c 100644 --- a/src/MacVim/Miscellaneous.m +++ b/src/MacVim/Miscellaneous.m @@ -296,3 +296,12 @@ normalizeFilenames(NSArray *filenames) return outnames; } + + + + + BOOL +shouldUseYosemiteTabBarStyle() +{ + return floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_10; +}