Skip to content

Commit eeeb43b

Browse files
committed
Set tab colors in MMTabline, not MMVimView
1 parent 9bbd6b5 commit eeeb43b

3 files changed

Lines changed: 35 additions & 34 deletions

File tree

src/MacVim/MMTabline/MMTabline.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- (void)selectTabAtIndex:(NSUInteger)index;
3232
- (MMTab *)tabAtIndex:(NSUInteger)index;
3333
- (void)scrollTabToVisibleAtIndex:(NSUInteger)index;
34+
- (void)setTablineSelBackground:(NSColor *)back foreground:(NSColor *)fore;
3435

3536
@end
3637

src/MacVim/MMTabline/MMTabline.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,39 @@ - (MMTab *)tabAtIndex:(NSUInteger)index
251251
return _tabs[index];
252252
}
253253

254+
- (void)setTablineSelBackground:(NSColor *)back foreground:(NSColor *)fore
255+
{
256+
// Reset to default tabline colors if user doesn't want auto-generated ones.
257+
if ([NSUserDefaults.standardUserDefaults boolForKey:@"MMDefaultTablineColors"]) {
258+
self.tablineBgColor = nil;
259+
self.tablineFgColor = nil;
260+
self.tablineSelBgColor = nil;
261+
self.tablineSelFgColor = nil;
262+
self.tablineFillFgColor = nil;
263+
return;
264+
}
265+
266+
self.tablineSelBgColor = back;
267+
self.tablineSelFgColor = fore;
268+
269+
// Set the colors for the tabline based on the default background and
270+
// foreground colors. We get the brightness component of back and fore
271+
// and then adjust up or down depending on whether the color is more
272+
// or less than 50% bright.
273+
CGFloat h, s, b, b2, b3, b4, a;
274+
275+
[back getHue:&h saturation:&s brightness:&b alpha:&a];
276+
b3 = (b > 0.5) ? b - 0.25 : b + 0.35;
277+
self.tablineFillFgColor = [NSColor colorWithHue:h saturation:s brightness:b3 alpha:a];
278+
279+
b2 = (b3 + b) / 2.;
280+
self.tablineBgColor = [NSColor colorWithHue:h saturation:s brightness:b2 alpha:a];
281+
282+
[fore getHue:&h saturation:&s brightness:&b alpha:&a];
283+
b4 = (b2 > 0.5) ? b2 - 0.25 : b2 + 0.25;
284+
self.tablineFgColor = [NSColor colorWithHue:h saturation:s brightness:b4 alpha:a];
285+
}
286+
254287
#pragma mark - Helpers
255288

256289
NSComparisonResult SortTabsForZOrder(MMTab *tab1, MMTab *tab2, void *draggedTab)

src/MacVim/MMVimView.m

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -454,44 +454,11 @@ - (void)finishPlaceScrollbars
454454
}
455455
}
456456

457-
- (void)setTablineColorsBasedOnBackground:(NSColor *)back foreground:(NSColor *)fore
458-
{
459-
// Reset to default tabline colors if user doesn't want auto-generated ones.
460-
if ([NSUserDefaults.standardUserDefaults boolForKey:@"MMDefaultTablineColors"]) {
461-
tabline.tablineBgColor = nil;
462-
tabline.tablineFgColor = nil;
463-
tabline.tablineSelBgColor = nil;
464-
tabline.tablineSelFgColor = nil;
465-
tabline.tablineFillFgColor = nil;
466-
return;
467-
}
468-
469-
tabline.tablineSelBgColor = back;
470-
tabline.tablineSelFgColor = fore;
471-
472-
// This is a naïve way of setting colors for the tabline based on the
473-
// default background and foreground colors. We get the brightness
474-
// component of back and fore and then adjust up or down depending on
475-
// whether the color is more or less than 50% bright.
476-
CGFloat h, s, b, b2, b3, b4, a;
477-
478-
[back getHue:&h saturation:&s brightness:&b alpha:&a];
479-
b2 = (b > 0.5) ? b - 0.15 : b + 0.15;
480-
tabline.tablineBgColor = [NSColor colorWithHue:h saturation:s brightness:b2 alpha:a];
481-
482-
b3 = (b > 0.5) ? b - 0.30 : b + 0.30;
483-
tabline.tablineFillFgColor = [NSColor colorWithHue:h saturation:s brightness:b3 alpha:a];
484-
485-
[fore getHue:&h saturation:&s brightness:&b alpha:&a];
486-
b4 = (b2 > 0.5) ? b2 - 0.25 : b2 + 0.25;
487-
tabline.tablineFgColor = [NSColor colorWithHue:h saturation:s brightness:b4 alpha:a];
488-
}
489-
490457
- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore
491458
{
492459
[textView setDefaultColorsBackground:back foreground:fore];
493460

494-
[self setTablineColorsBasedOnBackground:back foreground:fore];
461+
[tabline setTablineSelBackground:back foreground:fore];
495462

496463
CALayer *backedLayer = [self layer];
497464
if (backedLayer) {

0 commit comments

Comments
 (0)