Skip to content

Commit ee8bc6c

Browse files
authored
Merge pull request #346 from macvim-dev/fix/yosemite-tabbar-style
Fix Yosemite tabbar style check code
2 parents 226311a + c7c0902 commit ee8bc6c

File tree

6 files changed

+49
-30
lines changed

6 files changed

+49
-30
lines changed

src/MacVim/MMFullScreenWindow.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,8 @@ - (void)enterFullScreen
164164

165165
oldTabBarStyle = [[view tabBarControl] styleName];
166166

167-
NSString *style;
168-
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
169-
style = @"Yosemite";
170-
#else
171-
style = @"Unified";
172-
#endif
167+
NSString *style =
168+
shouldUseYosemiteTabBarStyle() ? @"Yosemite" : @"Unified";
173169
[[view tabBarControl] setStyleNamed:style];
174170

175171
// add text view

src/MacVim/MMVimView.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,18 @@ - (MMVimView *)initWithFrame:(NSRect)frame
125125
[tabBarControl setDelegate:self];
126126
[tabBarControl setHidden:YES];
127127

128-
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
129-
CGFloat screenWidth = [[NSScreen mainScreen] frame].size.width;
130-
[tabBarControl setStyleNamed:@"Yosemite"];
131-
[tabBarControl setCellMinWidth:120];
132-
[tabBarControl setCellMaxWidth:screenWidth];
133-
[tabBarControl setCellOptimumWidth:screenWidth];
134-
#else
135-
[tabBarControl setCellMinWidth:[ud integerForKey:MMTabMinWidthKey]];
136-
[tabBarControl setCellMaxWidth:[ud integerForKey:MMTabMaxWidthKey]];
137-
[tabBarControl setCellOptimumWidth:
128+
if (shouldUseYosemiteTabBarStyle()) {
129+
CGFloat screenWidth = [[NSScreen mainScreen] frame].size.width;
130+
[tabBarControl setStyleNamed:@"Yosemite"];
131+
[tabBarControl setCellMinWidth:120];
132+
[tabBarControl setCellMaxWidth:screenWidth];
133+
[tabBarControl setCellOptimumWidth:screenWidth];
134+
} else {
135+
[tabBarControl setCellMinWidth:[ud integerForKey:MMTabMinWidthKey]];
136+
[tabBarControl setCellMaxWidth:[ud integerForKey:MMTabMaxWidthKey]];
137+
[tabBarControl setCellOptimumWidth:
138138
[ud integerForKey:MMTabOptimumWidthKey]];
139-
#endif
139+
}
140140

141141
[tabBarControl setShowAddTabButton:[ud boolForKey:MMShowAddTabButtonKey]];
142142
[[tabBarControl addTabButton] setTarget:self];

src/MacVim/MMWindowController.m

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,6 @@
8080
#define FUOPT_BGCOLOR_HLGROUP 0x004
8181

8282

83-
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
84-
# define TABBAR_STYLE_UNIFIED @"Yosemite"
85-
# define TABBAR_STYLE_METAL @"Yosemite"
86-
#else
87-
# define TABBAR_STYLE_UNIFIED @"Unified"
88-
# define TABBAR_STYLE_METAL @"Metal"
89-
#endif
90-
91-
9283
@interface MMWindowController (Private)
9384
- (NSSize)contentSize;
9485
- (void)resizeWindowToFitContentSize:(NSSize)contentSize
@@ -106,6 +97,8 @@ - (BOOL)maximizeWindow:(int)options;
10697
- (void)applicationDidChangeScreenParameters:(NSNotification *)notification;
10798
- (void)enterNativeFullScreen;
10899
- (void)processAfterWindowPresentedQueue;
100+
+ (NSString *)tabBarStyleForUnified;
101+
+ (NSString *)tabBarStyleForMetal;
109102
@end
110103

111104

@@ -1187,7 +1180,8 @@ - (void)window:(NSWindow *)window
11871180
[[window animator] setAlphaValue:0];
11881181
} completionHandler:^{
11891182
[window setStyleMask:([window styleMask] | NSFullScreenWindowMask)];
1190-
[[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_UNIFIED];
1183+
NSString *tabBarStyle = [[self class] tabBarStyleForUnified];
1184+
[[vimView tabBarControl] setStyleNamed:tabBarStyle];
11911185
[self updateTablineSeparator];
11921186

11931187
// Stay dark for some time to wait for things to sync, then do the full screen operation
@@ -1251,7 +1245,8 @@ - (void)windowDidFailToEnterFullScreen:(NSWindow *)window
12511245
fullScreenEnabled = NO;
12521246
[window setAlphaValue:1];
12531247
[window setStyleMask:([window styleMask] & ~NSFullScreenWindowMask)];
1254-
[[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_METAL];
1248+
NSString *tabBarStyle = [[self class] tabBarStyleForMetal];
1249+
[[vimView tabBarControl] setStyleNamed:tabBarStyle];
12551250
[self updateTablineSeparator];
12561251
[window setFrame:preFullScreenFrame display:YES];
12571252
}
@@ -1281,7 +1276,8 @@ - (void)window:(NSWindow *)window
12811276
[[window animator] setAlphaValue:0];
12821277
} completionHandler:^{
12831278
[window setStyleMask:([window styleMask] & ~NSFullScreenWindowMask)];
1284-
[[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_METAL];
1279+
NSString *tabBarStyle = [[self class] tabBarStyleForMetal];
1280+
[[vimView tabBarControl] setStyleNamed:tabBarStyle];
12851281
[self updateTablineSeparator];
12861282
[window setFrame:preFullScreenFrame display:YES];
12871283

@@ -1328,7 +1324,8 @@ - (void)windowDidFailToExitFullScreen:(NSWindow *)window
13281324
fullScreenEnabled = YES;
13291325
[window setAlphaValue:1];
13301326
[window setStyleMask:([window styleMask] | NSFullScreenWindowMask)];
1331-
[[vimView tabBarControl] setStyleNamed:TABBAR_STYLE_UNIFIED];
1327+
NSString *tabBarStyle = [[self class] tabBarStyleForUnified];
1328+
[[vimView tabBarControl] setStyleNamed:tabBarStyle];
13321329
[self updateTablineSeparator];
13331330
[self maximizeWindow:fullScreenOptions];
13341331
}
@@ -1691,5 +1688,16 @@ - (void)processAfterWindowPresentedQueue
16911688

16921689
[afterWindowPresentedQueue release]; afterWindowPresentedQueue = nil;
16931690
}
1691+
1692+
+ (NSString *)tabBarStyleForUnified
1693+
{
1694+
return shouldUseYosemiteTabBarStyle() ? @"Yosemite" : @"Unified";
1695+
}
1696+
1697+
+ (NSString *)tabBarStyleForMetal
1698+
{
1699+
return shouldUseYosemiteTabBarStyle() ? @"Yosemite" : @"Metal";
1700+
}
1701+
16941702
@end // MMWindowController (Private)
16951703

src/MacVim/MacVim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#endif
3131

3232
// Needed for pre-10.11 SDK
33+
#ifndef NSAppKitVersionNumber10_10
34+
# define NSAppKitVersionNumber10_10 1343
35+
#endif
3336
#ifndef NSAppKitVersionNumber10_10_Max
3437
# define NSAppKitVersionNumber10_10_Max 1349
3538
#endif

src/MacVim/Miscellaneous.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,6 @@ NSView *showHiddenFilesView();
151151
// http://www.unicode.org/reports/tr15/
152152
NSString *normalizeFilename(NSString *filename);
153153
NSArray *normalizeFilenames(NSArray *filenames);
154+
155+
156+
BOOL shouldUseYosemiteTabBarStyle();

src/MacVim/Miscellaneous.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,12 @@ - (NSInteger)tag
296296

297297
return outnames;
298298
}
299+
300+
301+
302+
303+
BOOL
304+
shouldUseYosemiteTabBarStyle()
305+
{
306+
return floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_10;
307+
}

0 commit comments

Comments
 (0)