Skip to content

Commit 713b64f

Browse files
committed
Add Mojave-style tabs, which also supports Dark Mode
Add a new tab style "Mojave". The files were copied from Yosemite-style tabs but with additional improvements. It now reads the colors from an asset catalog with colors for both dark and light modes. The colors and style are also retuned to look more like native Mojave tabs. Reason for cloning PSMYosemiteTabStyle is to avoid having too many special cases in a single file and to avoid breaking its behaviors on older systems. Also, PSMTabBarControl is mostly a dead project, so it's wise to modify existing code as little as possible. MacVim will only use this style if it's compiled with Mojave SDKs and it's actually being run in Mojave (10.14) or higher. Fix macvim-dev#775
1 parent e5d1176 commit 713b64f

File tree

15 files changed

+809
-2
lines changed

15 files changed

+809
-2
lines changed

src/MacVim/MMVimView.m

+4-2
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,18 @@ - (MMVimView *)initWithFrame:(NSRect)frame
125125
[tabBarControl setDelegate:self];
126126
[tabBarControl setHidden:YES];
127127

128-
if (shouldUseYosemiteTabBarStyle()) {
128+
if (shouldUseYosemiteTabBarStyle() || shouldUseMojaveTabBarStyle()) {
129129
CGFloat screenWidth = [[NSScreen mainScreen] frame].size.width;
130130
int tabMaxWidth = [ud integerForKey:MMTabMaxWidthKey];
131131
if (tabMaxWidth == 0)
132132
tabMaxWidth = screenWidth;
133133
int tabOptimumWidth = [ud integerForKey:MMTabOptimumWidthKey];
134134
if (tabOptimumWidth == 0)
135135
tabOptimumWidth = screenWidth;
136+
137+
NSString* tabStyleName = shouldUseMojaveTabBarStyle() ? @"Mojave" : @"Yosemite";
136138

137-
[tabBarControl setStyleNamed:@"Yosemite"];
139+
[tabBarControl setStyleNamed:tabStyleName];
138140
[tabBarControl setCellMinWidth:[ud integerForKey:MMTabMinWidthKey]];
139141
[tabBarControl setCellMaxWidth:tabMaxWidth];
140142
[tabBarControl setCellOptimumWidth:tabOptimumWidth];

src/MacVim/MacVim.h

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#ifndef MAC_OS_X_VERSION_10_12_2
3333
# define MAC_OS_X_VERSION_10_12_2 101202
3434
#endif
35+
#ifndef MAC_OS_X_VERSION_10_14
36+
# define MAC_OS_X_VERSION_10_14 101400
37+
#endif
3538

3639
#ifndef NSAppKitVersionNumber10_10
3740
# define NSAppKitVersionNumber10_10 1343

src/MacVim/Miscellaneous.h

+1
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,4 @@ NSArray *normalizeFilenames(NSArray *filenames);
155155

156156

157157
BOOL shouldUseYosemiteTabBarStyle();
158+
BOOL shouldUseMojaveTabBarStyle();

src/MacVim/Miscellaneous.m

+10
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,14 @@ - (NSInteger)tag
305305
shouldUseYosemiteTabBarStyle()
306306
{
307307
return floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_10;
308+
}
309+
BOOL
310+
shouldUseMojaveTabBarStyle()
311+
{
312+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
313+
if (@available(macos 10.14, *)) {
314+
return true;
315+
}
316+
#endif
317+
return false;
308318
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
},
6+
"colors" : [
7+
{
8+
"idiom" : "universal",
9+
"color" : {
10+
"color-space" : "srgb",
11+
"components" : {
12+
"red" : "189",
13+
"alpha" : "1.000",
14+
"blue" : "188",
15+
"green" : "189"
16+
}
17+
}
18+
},
19+
{
20+
"idiom" : "universal",
21+
"appearances" : [
22+
{
23+
"appearance" : "luminosity",
24+
"value" : "dark"
25+
}
26+
],
27+
"color" : {
28+
"color-space" : "srgb",
29+
"components" : {
30+
"red" : "37",
31+
"alpha" : "1.000",
32+
"blue" : "40",
33+
"green" : "38"
34+
}
35+
}
36+
}
37+
]
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
},
6+
"colors" : [
7+
{
8+
"idiom" : "universal",
9+
"color" : {
10+
"color-space" : "srgb",
11+
"components" : {
12+
"red" : "221",
13+
"alpha" : "1.000",
14+
"blue" : "221",
15+
"green" : "221"
16+
}
17+
}
18+
},
19+
{
20+
"idiom" : "universal",
21+
"appearances" : [
22+
{
23+
"appearance" : "luminosity",
24+
"value" : "dark"
25+
}
26+
],
27+
"color" : {
28+
"color-space" : "srgb",
29+
"components" : {
30+
"red" : "30",
31+
"alpha" : "1.000",
32+
"blue" : "33",
33+
"green" : "31"
34+
}
35+
}
36+
}
37+
]
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
},
6+
"colors" : [
7+
{
8+
"idiom" : "universal",
9+
"color" : {
10+
"color-space" : "srgb",
11+
"components" : {
12+
"red" : "209",
13+
"alpha" : "1.000",
14+
"blue" : "208",
15+
"green" : "209"
16+
}
17+
}
18+
},
19+
{
20+
"idiom" : "universal",
21+
"appearances" : [
22+
{
23+
"appearance" : "luminosity",
24+
"value" : "dark"
25+
}
26+
],
27+
"color" : {
28+
"color-space" : "srgb",
29+
"components" : {
30+
"red" : "54",
31+
"alpha" : "1.000",
32+
"blue" : "57",
33+
"green" : "55"
34+
}
35+
}
36+
}
37+
]
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
},
6+
"colors" : [
7+
{
8+
"idiom" : "universal",
9+
"color" : {
10+
"color-space" : "srgb",
11+
"components" : {
12+
"red" : "246",
13+
"alpha" : "1.000",
14+
"blue" : "246",
15+
"green" : "246"
16+
}
17+
}
18+
},
19+
{
20+
"idiom" : "universal",
21+
"appearances" : [
22+
{
23+
"appearance" : "luminosity",
24+
"value" : "dark"
25+
}
26+
],
27+
"color" : {
28+
"color-space" : "srgb",
29+
"components" : {
30+
"red" : "43",
31+
"alpha" : "1.000",
32+
"blue" : "47",
33+
"green" : "45"
34+
}
35+
}
36+
}
37+
]
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
},
6+
"colors" : [
7+
{
8+
"idiom" : "universal",
9+
"color" : {
10+
"color-space" : "srgb",
11+
"components" : {
12+
"red" : "169",
13+
"alpha" : "1.000",
14+
"blue" : "169",
15+
"green" : "169"
16+
}
17+
}
18+
},
19+
{
20+
"idiom" : "universal",
21+
"appearances" : [
22+
{
23+
"appearance" : "luminosity",
24+
"value" : "dark"
25+
}
26+
],
27+
"color" : {
28+
"color-space" : "srgb",
29+
"components" : {
30+
"red" : "96",
31+
"alpha" : "1.000",
32+
"blue" : "99",
33+
"green" : "97"
34+
}
35+
}
36+
}
37+
]
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
},
6+
"colors" : [
7+
{
8+
"idiom" : "universal",
9+
"color" : {
10+
"color-space" : "srgb",
11+
"components" : {
12+
"red" : "210",
13+
"alpha" : "1.000",
14+
"blue" : "210",
15+
"green" : "210"
16+
}
17+
}
18+
},
19+
{
20+
"idiom" : "universal",
21+
"appearances" : [
22+
{
23+
"appearance" : "luminosity",
24+
"value" : "dark"
25+
}
26+
],
27+
"color" : {
28+
"color-space" : "srgb",
29+
"components" : {
30+
"red" : "73",
31+
"alpha" : "1.000",
32+
"blue" : "77",
33+
"green" : "74"
34+
}
35+
}
36+
}
37+
]
38+
}

src/MacVim/PSMTabBarControl/PSMTabBarControl.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
52FAFCD41C30F4DF00C6E613 /* PSMYosemiteTabStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 52FAFCD21C30F4DF00C6E613 /* PSMYosemiteTabStyle.m */; };
4242
546DEAF1067F63070098DCC4 /* PSMTabBarControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 0259C576FE90428111CA0C5A /* PSMTabBarControl.m */; };
4343
546DEAF2067F630E0098DCC4 /* PSMTabBarControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 0259C57AFE90428111CA0C5A /* PSMTabBarControl.h */; settings = {ATTRIBUTES = (Public, ); }; };
44+
90AD234F21A969C100CEF036 /* PSMMojaveTabStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 90AD234D21A969C100CEF036 /* PSMMojaveTabStyle.h */; };
45+
90AD235021A969C100CEF036 /* PSMMojaveTabStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 90AD234E21A969C100CEF036 /* PSMMojaveTabStyle.m */; };
46+
90DE16CC21A955EE004F0124 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 90DE16CB21A955EE004F0124 /* Media.xcassets */; };
4447
A2082A9009EAEB34009AC8BE /* PSMTabDragAssistant.h in Headers */ = {isa = PBXBuildFile; fileRef = A2082A8D09EAEB33009AC8BE /* PSMTabDragAssistant.h */; };
4548
A2082A9109EAEB34009AC8BE /* PSMTabDragAssistant.m in Sources */ = {isa = PBXBuildFile; fileRef = A2082A8E09EAEB33009AC8BE /* PSMTabDragAssistant.m */; };
4649
A2129BB209AEB58F00724E6C /* PSMProgressIndicator.h in Headers */ = {isa = PBXBuildFile; fileRef = A2129BAF09AEB58F00724E6C /* PSMProgressIndicator.h */; };
@@ -124,6 +127,9 @@
124127
54D33B2806778E3300C9C163 /* PSMTabBarControl.ibclassdescription */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PSMTabBarControl.ibclassdescription; sourceTree = "<group>"; };
125128
8D1AC9730486D14A00FE50C9 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
126129
8D1AC97B0486D23100FE50C9 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
130+
90AD234D21A969C100CEF036 /* PSMMojaveTabStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PSMMojaveTabStyle.h; path = source/PSMMojaveTabStyle.h; sourceTree = "<group>"; };
131+
90AD234E21A969C100CEF036 /* PSMMojaveTabStyle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PSMMojaveTabStyle.m; path = source/PSMMojaveTabStyle.m; sourceTree = "<group>"; };
132+
90DE16CB21A955EE004F0124 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = "<group>"; };
127133
A2072A2409ABD88600304BCB /* Folder.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = Folder.tif; path = images/Folder.tif; sourceTree = "<group>"; };
128134
A2072A2509ABD88600304BCB /* Globe.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = Globe.tiff; path = images/Globe.tiff; sourceTree = "<group>"; };
129135
A2072B5C09AC1FA500304BCB /* Warning.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Warning.png; path = images/Warning.png; sourceTree = "<group>"; };
@@ -209,6 +215,7 @@
209215
0259C582FE90428111CA0C5A /* Resources */ = {
210216
isa = PBXGroup;
211217
children = (
218+
90DE16CB21A955EE004F0124 /* Media.xcassets */,
212219
A251BEC20959BC0E0058BC7F /* MainMenu.nib */,
213220
A251BE8E0959A21A0058BC7F /* Images */,
214221
8D1AC9730486D14A00FE50C9 /* Info.plist */,
@@ -308,6 +315,8 @@
308315
54D33B2C06778E4400C9C163 /* Framework */ = {
309316
isa = PBXGroup;
310317
children = (
318+
90AD234D21A969C100CEF036 /* PSMMojaveTabStyle.h */,
319+
90AD234E21A969C100CEF036 /* PSMMojaveTabStyle.m */,
311320
0259C57AFE90428111CA0C5A /* PSMTabBarControl.h */,
312321
0259C576FE90428111CA0C5A /* PSMTabBarControl.m */,
313322
A251BE830959A1B90058BC7F /* PSMTabBarCell.h */,
@@ -416,6 +425,7 @@
416425
A2082A9009EAEB34009AC8BE /* PSMTabDragAssistant.h in Headers */,
417426
A2D98B0A0A2B432C0064C6F8 /* PSMUnifiedTabStyle.h in Headers */,
418427
A2D98B120A2B43FA0064C6F8 /* NSBezierPath_AMShading.h in Headers */,
428+
90AD234F21A969C100CEF036 /* PSMMojaveTabStyle.h in Headers */,
419429
);
420430
runOnlyForDeploymentPostprocessing = 0;
421431
};
@@ -490,6 +500,7 @@
490500
A27E47880A28EE7C007BA395 /* TabControlRep.tif in Resources */,
491501
52A57C0F15BBA230003EC59C /* TabClose_Front.png in Resources */,
492502
52A57C1015BBA230003EC59C /* TabClose_Front_Pressed.png in Resources */,
503+
90DE16CC21A955EE004F0124 /* Media.xcassets in Resources */,
493504
52A57C1115BBA230003EC59C /* TabClose_Front_Rollover.png in Resources */,
494505
52FAFCCF1C30F4B500C6E613 /* TabNewYosemite.png in Resources */,
495506
523897F415BDA9AC00498A53 /* [email protected] in Resources */,
@@ -519,6 +530,7 @@
519530
A2D32F0109A63D7A00EC8662 /* PSMMetalTabStyle.m in Sources */,
520531
A268EA6309A9831800E082AA /* PSMRolloverButton.m in Sources */,
521532
A2129BB309AEB58F00724E6C /* PSMProgressIndicator.m in Sources */,
533+
90AD235021A969C100CEF036 /* PSMMojaveTabStyle.m in Sources */,
522534
A2082A9109EAEB34009AC8BE /* PSMTabDragAssistant.m in Sources */,
523535
52FAFCD41C30F4DF00C6E613 /* PSMYosemiteTabStyle.m in Sources */,
524536
A2D98B0B0A2B432C0064C6F8 /* PSMUnifiedTabStyle.m in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// PSMMojaveTabStyle.h
3+
// PSMTabBarControl
4+
//
5+
// This file is copied from PSMYosemiteTabStyle to allow for modifications to
6+
// adapt to Mojave-specific functionality such as Dark Mode without needing to
7+
// pollute the implementation of Yosemite tab style.
8+
//
9+
//
10+
11+
#import <Cocoa/Cocoa.h>
12+
#import "PSMTabStyle.h"
13+
14+
@interface PSMMojaveTabStyle : NSObject <PSMTabStyle> {
15+
NSImage *closeButton;
16+
NSImage *closeButtonDown;
17+
NSImage *closeButtonOver;
18+
NSImage *_addTabButtonImage;
19+
NSImage *_addTabButtonPressedImage;
20+
NSImage *_addTabButtonRolloverImage;
21+
NSMutableParagraphStyle *truncatingTailParagraphStyle;
22+
NSMutableParagraphStyle *centeredParagraphStyle;
23+
}
24+
25+
- (void)drawInteriorWithTabCell:(PSMTabBarCell *)cell inView:(NSView*)controlView;
26+
27+
- (void)encodeWithCoder:(NSCoder *)aCoder;
28+
- (id)initWithCoder:(NSCoder *)aDecoder;
29+
30+
@end

0 commit comments

Comments
 (0)