Skip to content

Commit e732895

Browse files
committed
Fix scrollbars in Mojave dark mode not rendering properly
Dark mode scrollbars's background are rendered in a translucent color so that it would overlay on top of the background nearly, even though we are using legacy scrollbars with a dedicated space. This is unlike light mode scrollbars which render with a concrete color. This means if the background has uncleared rendering it would result in some oddities. Just fix it by making sure we first render the scroll track with the current background color before drawing the system overlay. Known issues: - The scroll knob will look quite light and hard to see if the background color is bright. Consider this OK for now as users who use dark mode will likely have a dark-ish background color in Vim. - If both vertical and horizontal scrollbars are enabled, the corners will look black or sometimes filled with rendering artifacts. Will fix this later. One way to fix is to always fill the Vim view with a background color but that seems to slow things down a little bit because setNeedsDisplay seems to be called too much without a rect, so need to fix that first. - Vertical scrollbars' positions are sometimes set incorrectly. That's a separate bug and will be addressed later. - MacVim currently doesn't support overlay scrollbars which have been introduced in macOS since 10.7. Investigate that option too.
1 parent dabe5a2 commit e732895

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/MacVim/MMVimView.m

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ - (void)setScrollbarPosition:(int)pos length:(int)len identifier:(int32_t)ident
494494
- (void)setDefaultColorsBackground:(NSColor *)back foreground:(NSColor *)fore
495495
{
496496
[textView setDefaultColorsBackground:back foreground:fore];
497+
498+
for (NSUInteger i = 0, count = [scrollbars count]; i < count; ++i) {
499+
MMScroller *sb = [scrollbars objectAtIndex:i];
500+
[sb setNeedsDisplay:YES];
501+
}
497502
}
498503

499504

@@ -801,10 +806,15 @@ - (void)placeScrollbars
801806
}
802807
}
803808

804-
// HACK: If there is no bottom or right scrollbar the resize indicator will
805-
// cover the bottom-right corner of the text view so tell NSWindow not to
806-
// draw it in this situation.
807-
[[self window] setShowsResizeIndicator:(rightSbVisible||botSbVisible)];
809+
if (NSAppKitVersionNumber < NSAppKitVersionNumber10_7) {
810+
// HACK: If there is no bottom or right scrollbar the resize indicator will
811+
// cover the bottom-right corner of the text view so tell NSWindow not to
812+
// draw it in this situation.
813+
//
814+
// Note: This API is ignored from 10.7 onward and is now deprecated. This
815+
// should be removed if we want to drop support for 10.6.
816+
[[self window] setShowsResizeIndicator:(rightSbVisible||botSbVisible)];
817+
}
808818
}
809819

810820
- (NSUInteger)representedIndexOfTabViewItem:(NSTabViewItem *)tvi
@@ -973,6 +983,22 @@ - (id)initWithIdentifier:(int32_t)ident type:(int)theType
973983
return self;
974984
}
975985

986+
- (void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag
987+
{
988+
// Dark mode scrollbars draw a translucent knob slot overlaid on top of
989+
// whatever background the view has, even when we are using legacy
990+
// scrollbars with a dedicated space. This means we need to draw the
991+
// background with some colors first, or else it would look really black, or
992+
// show through rendering artifacts (e.g. if guioption 'k' is on, and you
993+
// turn off the bar bar, the artiacts will show through in the overlay).
994+
MMVimView *vimView = [self target];
995+
NSColor *defaultBackgroundColor = [[vimView textView] defaultBackgroundColor];
996+
[defaultBackgroundColor setFill];
997+
NSRectFill(slotRect);
998+
999+
[super drawKnobSlotInRect:slotRect highlight:flag];
1000+
}
1001+
9761002
- (int32_t)scrollerId
9771003
{
9781004
return identifier;

0 commit comments

Comments
 (0)