Skip to content

Tabs: Use TabLineFill fg, fix colorscheme w/ transparent/inverse highlights #1557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions runtime/colors/retrobox.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
" Maintainer: Maxim Kim <habamax@gmail.com>, ported from gruvbox8 of Lifepillar <lifepillar@lifepillar.me>
" Website: https://www.github.com/vim/colorschemes
" License: Vim License (see `:help license`)
" Last Change: 2025 Jan 07
" Last Change: 2025 Feb 15

" Generated by Colortemplate v2.2.3

Expand Down Expand Up @@ -150,7 +150,7 @@ else
hi StatusLine guifg=#bdae93 guibg=#3c3836 gui=bold,reverse cterm=bold,reverse
hi StatusLineNC guifg=#ebdbb2 guibg=#3c3836 gui=reverse cterm=reverse
hi TabLine guifg=#665c54 guibg=#ebdbb2 gui=NONE cterm=NONE
hi TabLineFill guifg=#ebdbb2 guibg=#ebdbb2 gui=NONE cterm=NONE
hi TabLineFill guifg=#3c3836 guibg=#ebdbb2 gui=NONE cterm=NONE
hi TabLineSel guifg=#282828 guibg=#fbf1c7 gui=bold cterm=bold
hi ToolbarButton guifg=#282828 guibg=#bdae93 gui=bold cterm=bold
hi ToolbarLine guifg=NONE guibg=NONE gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE
Expand Down Expand Up @@ -332,7 +332,7 @@ if s:t_Co >= 256
hi StatusLine ctermfg=144 ctermbg=237 cterm=bold,reverse
hi StatusLineNC ctermfg=187 ctermbg=237 cterm=reverse
hi TabLine ctermfg=59 ctermbg=187 cterm=NONE
hi TabLineFill ctermfg=187 ctermbg=187 cterm=NONE
hi TabLineFill ctermfg=237 ctermbg=187 cterm=NONE
hi TabLineSel ctermfg=235 ctermbg=230 cterm=bold
hi ToolbarButton ctermfg=235 ctermbg=144 cterm=bold
hi ToolbarLine ctermfg=NONE ctermbg=NONE cterm=NONE
Expand Down
18 changes: 10 additions & 8 deletions src/MacVim/MMTabline/MMTabline.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
@property (nonatomic, readonly) NSInteger numberOfTabs;
@property (nonatomic, retain, readonly) MMHoverButton *addTabButton;

@property (nonatomic, retain) NSColor *tablineBgColor;
@property (nonatomic, retain) NSColor *tablineFgColor;
@property (nonatomic, retain) NSColor *tablineSelBgColor;
@property (nonatomic, retain) NSColor *tablineSelFgColor;
@property (nonatomic, retain) NSColor *tablineFillFgColor;

// Derived colors that cannot be set directly
// Main colors
@property (nonatomic, readonly) NSColor *tablineBgColor;
@property (nonatomic, readonly) NSColor *tablineFgColor;
@property (nonatomic, readonly) NSColor *tablineSelBgColor;
@property (nonatomic, readonly) NSColor *tablineSelFgColor;
@property (nonatomic, readonly) NSColor *tablineFillBgColor;
@property (nonatomic, readonly) NSColor *tablineFillFgColor;

// Derived colors from the main ones
@property (nonatomic, readonly) NSColor *tablineUnfocusedFgColor;
@property (nonatomic, readonly) NSColor *tablineUnfocusedSelFgColor;
@property (nonatomic, readonly) NSColor *tablineStrokeColor;
Expand Down Expand Up @@ -69,7 +71,7 @@
/// colors based on the system light/dark modes.
- (void)setColorsTabBg:(NSColor *)tabBg tabFg:(NSColor *)tabFg
selBg:(NSColor *)selBg selFg:(NSColor *)selFg
fill:(NSColor *)fill;
fillBg:(NSColor *)fill fillFg:(NSColor *)fillFg;

/// Lets the tabline calculate best colors to use based on background and
/// foreground colors of the selected tab. The colors cannot be nil.
Expand Down
54 changes: 12 additions & 42 deletions src/MacVim/MMTabline/MMTabline.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ @implementation MMTabline
@synthesize tablineFgColor = _tablineFgColor;
@synthesize tablineSelBgColor = _tablineSelBgColor;
@synthesize tablineSelFgColor = _tablineSelFgColor;
@synthesize tablineFillFgColor = _tablineFillFgColor;
@synthesize tablineFillBgColor = _tablineFillBgColor;
@synthesize tablineUnfocusedFgColor = _tablineUnfocusedFgColor;
@synthesize tablineUnfocusedSelFgColor = _tablineUnfocusedSelFgColor;

Expand Down Expand Up @@ -150,7 +150,7 @@ - (BOOL)wantsUpdateLayer { return YES; }

- (void)updateLayer
{
self.layer.backgroundColor = self.tablineFillFgColor.CGColor;
self.layer.backgroundColor = self.tablineFillBgColor.CGColor;
}

- (void)viewDidChangeEffectiveAppearance
Expand Down Expand Up @@ -253,63 +253,33 @@ - (NSColor *)tablineBgColor
}
}

- (void)setTablineBgColor:(NSColor *)color
{
_tablineBgColor = color;
[self updateTabStates];
}

- (NSColor *)tablineFgColor
{
return _tablineFgColor ?: NSColor.secondaryLabelColor;
}

- (void)setTablineFgColor:(NSColor *)color
{
_tablineFgColor = color;
_tablineUnfocusedFgColor = nil;
[self updateTabStates];
}

- (NSColor *)tablineSelBgColor
{
return _tablineSelBgColor ?: (_appearance == AppearanceLight || _appearance == AppearanceLightHighContrast)
? [NSColor colorWithWhite:0.95 alpha:1]
: [NSColor colorWithWhite:0.4 alpha:1];
}

- (void)setTablineSelBgColor:(NSColor *)color
{
_tablineSelBgColor = color;
[self updateTabStates];
}

- (NSColor *)tablineSelFgColor
{
return _tablineSelFgColor ?: NSColor.controlTextColor;
}

- (void)setTablineSelFgColor:(NSColor *)color
{
_tablineSelFgColor = color;
_tablineUnfocusedSelFgColor = nil;
_addTabButton.fgColor = color;
_backwardScrollButton.fgColor = color;
_forwardScrollButton.fgColor = color;
[self updateTabStates];
}

- (NSColor *)tablineFillFgColor
- (NSColor *)tablineFillBgColor
{
return _tablineFillFgColor ?: (_appearance == AppearanceLight || _appearance == AppearanceLightHighContrast)
return _tablineFillBgColor ?: (_appearance == AppearanceLight || _appearance == AppearanceLightHighContrast)
? [NSColor colorWithWhite:0.85 alpha:1]
: [NSColor colorWithWhite:0.23 alpha:1];
}

- (void)setTablineFillFgColor:(NSColor *)color
- (NSColor *)tablineFillFgColor
{
_tablineFillFgColor = color;
self.needsDisplay = YES;
return _addTabButton.fgColor;
}

- (NSColor *)tablineUnfocusedFgColor
Expand Down Expand Up @@ -570,22 +540,22 @@ - (MMTab *)tabAtIndex:(NSInteger)index

- (void)setColorsTabBg:(NSColor *)tabBg tabFg:(NSColor *)tabFg
selBg:(NSColor *)selBg selFg:(NSColor *)selFg
fill:(NSColor *)fill
fillBg:(NSColor *)fillBg fillFg:(NSColor *)fillFg
{
// Don't use the property mutators as we just want to update the states in
// one go at the end.
_tablineSelBgColor = selBg;
_tablineSelFgColor = selFg;
_tablineBgColor = tabBg;
_tablineFgColor = tabFg;
_tablineFillFgColor = fill;
_tablineFillBgColor = fillBg;

_tablineUnfocusedFgColor = [_tablineFgColor blendedColorWithFraction:0.4 ofColor:_tablineBgColor];
_tablineUnfocusedSelFgColor = [_tablineSelFgColor blendedColorWithFraction:0.38 ofColor:_tablineSelBgColor];

_addTabButton.fgColor = _tablineSelFgColor;
_backwardScrollButton.fgColor = _tablineSelFgColor;
_forwardScrollButton.fgColor = _tablineSelFgColor;
_addTabButton.fgColor = fillFg;
_backwardScrollButton.fgColor = fillFg;
_forwardScrollButton.fgColor = fillFg;

[self updateTabStates];
self.needsDisplay = YES;
Expand Down Expand Up @@ -615,7 +585,7 @@ - (void)setAutoColorsSelBg:(NSColor *)back fg:(NSColor *)fore;
_tablineUnfocusedFgColor = [_tablineFgColor blendedColorWithFraction:0.4 ofColor:_tablineBgColor];
_tablineUnfocusedSelFgColor = [_tablineSelFgColor blendedColorWithFraction:0.38 ofColor:_tablineSelBgColor];

_tablineFillFgColor = (brightness > 0.5)
_tablineFillBgColor = (brightness > 0.5)
? [back blendedColorWithFraction:0.25 ofColor:NSColor.blackColor]
: [back blendedColorWithFraction:0.18 ofColor:NSColor.whiteColor];

Expand Down
33 changes: 22 additions & 11 deletions src/MacVim/MMVimView.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
MMTabColorTypeTabFg,
MMTabColorTypeSelBg,
MMTabColorTypeSelFg,
MMTabColorTypeFill,
MMTabColorTypeFillBg,
MMTabColorTypeFillFg,
MMTabColorTypeCount
} MMTabColorType;

Expand Down Expand Up @@ -377,7 +378,7 @@ - (void)refreshTabProperties
{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
tabline.showsTabScrollButtons = [ud boolForKey:MMShowTabScrollButtonsKey];
[self updateTablineColors];
[self updateTablineColors:MMTabColorsModeCount];
}

- (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type
Expand Down Expand Up @@ -469,25 +470,35 @@ - (void)finishPlaceScrollbars
}
}

- (void)updateTablineColors
- (void)updateTablineColors:(MMTabColorsMode)mode
{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
MMTabColorsMode tabColorsMode = [ud integerForKey:MMTabColorsModeKey];
if (tabColorsMode >= MMTabColorsModeCount || tabColorsMode < 0) {
// Catch-all for invalid values, which could be useful if we add new
// modes and a user goes back and uses an old version of MacVim.
tabColorsMode = MMTabColorsModeAutomatic;
}
if (mode != MMTabColorsModeCount && mode != tabColorsMode) {
// Early out to avoid unnecessary updates if this is not relevant.
return;
}
if (tabColorsMode == MMTabColorsModeDefaultColors) {
[tabline setColorsTabBg:nil
tabFg:nil
selBg:nil
selFg:nil
fill:nil];
fillBg:nil
fillFg:nil];
} else if (tabColorsMode == MMTabColorsModeVimColorscheme) {
[tabline setColorsTabBg:tabColors[MMTabColorTypeTabBg]
tabFg:tabColors[MMTabColorTypeTabFg]
selBg:tabColors[MMTabColorTypeSelBg]
selFg:tabColors[MMTabColorTypeSelFg]
fill:tabColors[MMTabColorTypeFill]];
fillBg:tabColors[MMTabColorTypeFillBg]
fillFg:tabColors[MMTabColorTypeFillFg]];
} else {
// tabColorsMode == MMTabColorsModeAutomatic, but catch-all in case it's
// set to an out-of-range number.
// tabColorsMode == MMTabColorsModeAutomatic
NSColor *back = [[self textView] defaultBackgroundColor];
NSColor *fore = [[self textView] defaultForegroundColor];
[tabline setAutoColorsSelBg:back fg:fore];
Expand All @@ -498,7 +509,7 @@ - (void)updateTablineColors
- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore
{
[textView setDefaultColorsBackground:back foreground:fore];
[self updateTablineColors];
[self updateTablineColors:MMTabColorsModeAutomatic];

CALayer *backedLayer = [self layer];
if (backedLayer) {
Expand Down Expand Up @@ -527,9 +538,9 @@ - (void)setTablineColorsTabBg:(NSColor *)tabBg tabFg:(NSColor *)tabFg
tabColors[MMTabColorTypeTabFg] = [tabFg retain];
tabColors[MMTabColorTypeSelBg] = [selBg retain];
tabColors[MMTabColorTypeSelFg] = [selFg retain];
tabColors[MMTabColorTypeFill] = [fillBg retain];
(void)fillFg; // We don't use fillFg as we don't draw anything in the empty area
[self updateTablineColors];
tabColors[MMTabColorTypeFillBg] = [fillBg retain];
tabColors[MMTabColorTypeFillFg] = [fillFg retain];
[self updateTablineColors:MMTabColorsModeVimColorscheme];
}


Expand Down
2 changes: 1 addition & 1 deletion src/MacVim/MMWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ - (void)setTablineColorsTabBg:(NSColor *)tabBg tabFg:(NSColor *)tabFg
- (void)setWindowColorToTablineColor
{
NSColor *defaultBg = vimView.textView.defaultBackgroundColor;
NSColor *tablineColor = vimView.tabline.tablineFillFgColor;
NSColor *tablineColor = vimView.tabline.tablineFillBgColor;
if (defaultBg.alphaComponent == 1.0) {
[self setWindowBackgroundColor:tablineColor];
} else {
Expand Down
61 changes: 61 additions & 0 deletions src/MacVim/MacVimTests/MacVimTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ @interface MMVimController (Private)
- (void)handleMessage:(int)msgid data:(NSData *)data;
@end

@interface MMVimView (Tests)
- (void)updateTablineColors:(MMTabColorsMode)mode;
@end

// Test harness
@implementation MMAppController (Tests)
- (NSMutableArray*)vimControllers {
Expand Down Expand Up @@ -954,6 +958,63 @@ - (void) testResizeVimView {
XCTAssertFalse(win.isRenderBlocked);
}

#pragma mark Tabs tests

- (void)testTabColors {
[self createTestVimWindow];

MMAppController *app = MMAppController.sharedInstance;
MMVimView *vimView = [[[app keyVimController] windowController] vimView];
MMTabline *tabline = [vimView tabline];

// Test Vim colorscheme mode
[self setDefault:MMTabColorsModeKey toValue:@(MMTabColorsModeVimColorscheme)];

[self sendStringToVim:@":hi Normal guifg=#ff0000 guibg=#00ff00\n" withMods:0];
[self waitForVimProcess];
[self sendStringToVim:@":hi TabLineSel guifg=#010203 guibg=#040506\n" withMods:0];
[self sendStringToVim:@":hi clear TabLineFill\n" withMods:0];
[self sendStringToVim:@":hi TabLine guifg=#111213 guibg=NONE gui=inverse\n" withMods:0];
[self waitForEventHandlingAndVimProcess];

// Normal highlight groups
XCTAssertEqualObjects(tabline.tablineSelBgColor, [NSColor colorWithRgbInt:0x040506]);
XCTAssertEqualObjects(tabline.tablineSelFgColor, [NSColor colorWithRgbInt:0x010203]);
// Cleared highlight group should be transparent and fall through to Normal group
XCTAssertEqualObjects(tabline.tablineFillBgColor, [NSColor colorWithRgbInt:0x00ff00]);
XCTAssertEqualObjects(tabline.tablineFillFgColor, [NSColor colorWithRgbInt:0xff0000]);
// One color is transparent, and inversed fg/bg
XCTAssertEqualObjects(tabline.tablineBgColor, [NSColor colorWithRgbInt:0x111213]);
XCTAssertEqualObjects(tabline.tablineFgColor, [NSColor colorWithRgbInt:0x00ff00]);

// Cleared highlight group with inversed fg/bg
[self sendStringToVim:@":hi TabLineFill gui=inverse\n" withMods:0];
[self waitForEventHandlingAndVimProcess];
XCTAssertEqualObjects(tabline.tablineFillBgColor, [NSColor colorWithRgbInt:0xff0000]);
XCTAssertEqualObjects(tabline.tablineFillFgColor, [NSColor colorWithRgbInt:0x00ff00]);

// Test automatic colors mode
// Selected tab should have the exact same background as Normal colors
[self setDefault:MMTabColorsModeKey toValue:@(MMTabColorsModeAutomatic)];
[vimView updateTablineColors:MMTabColorsModeAutomatic];
XCTAssertEqualObjects(tabline.tablineSelBgColor, [NSColor colorWithRgbInt:0x00ff00]);

// Test default colors mode
// We just verify that the colors changed, rather than asserting the exact
// colors to make it easy to update tuning on them in the future.
[self setDefault:MMTabColorsModeKey toValue:@(MMTabColorsModeDefaultColors)];
[vimView updateTablineColors:MMTabColorsModeDefaultColors];

vimView.window.appearance = [NSAppearance appearanceNamed: NSAppearanceNameAqua];
[self waitForEventHandling];
XCTAssertEqual(tabline.tablineFillBgColor.colorSpace.colorSpaceModel, NSColorSpaceModelGray);
XCTAssertGreaterThan(tabline.tablineFillBgColor.whiteComponent, 0.5);

vimView.window.appearance = [NSAppearance appearanceNamed: NSAppearanceNameDarkAqua];
[self waitForEventHandling];
XCTAssertLessThan(tabline.tablineFillBgColor.whiteComponent, 0.5);
}

#pragma mark Full screen tests

- (void)waitForNativeFullscreenEnter {
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/Miscellaneous.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ typedef enum : NSInteger {
MMTabColorsModeDefaultColors = 0, ///< Use default colors based on macOS light/dark modes
MMTabColorsModeAutomatic, ///< Automatically derive tab colors based on foreground/background colors
MMTabColorsModeVimColorscheme, ///< Use Vim colorscheme TabLine/TabLineSel/TabLineFill colors
MMTabColorsModeCount
} MMTabColorsMode;

enum {
Expand Down
Loading