Skip to content

Commit 4ba02a8

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 4ba02a8

1 file changed

Lines changed: 47 additions & 4 deletions

File tree

src/MacVim/MMVimView.m

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,23 @@ - (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+
CALayer *backedLayer = [self layer];
499+
if (backedLayer) {
500+
// This would only trigger in 10.14 where all views are layer-backed.
501+
//
502+
// Note: This doesn't do much now. Should fix this class to use
503+
// updateLayer: instead of drawRect: at a later time, which would draw
504+
// the background color automatically. When we do that we can remove the
505+
// hack at drawKnobSlotInRect: since it would overlay properly without
506+
// needing to manually draw the background color itself.
507+
[backedLayer setBackgroundColor:[back CGColor]];
508+
}
509+
510+
for (NSUInteger i = 0, count = [scrollbars count]; i < count; ++i) {
511+
MMScroller *sb = [scrollbars objectAtIndex:i];
512+
[sb setNeedsDisplay:YES];
513+
}
497514
}
498515

499516

@@ -801,10 +818,15 @@ - (void)placeScrollbars
801818
}
802819
}
803820

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)];
821+
if (NSAppKitVersionNumber < NSAppKitVersionNumber10_7) {
822+
// HACK: If there is no bottom or right scrollbar the resize indicator will
823+
// cover the bottom-right corner of the text view so tell NSWindow not to
824+
// draw it in this situation.
825+
//
826+
// Note: This API is ignored from 10.7 onward and is now deprecated. This
827+
// should be removed if we want to drop support for 10.6.
828+
[[self window] setShowsResizeIndicator:(rightSbVisible||botSbVisible)];
829+
}
808830
}
809831

810832
- (NSUInteger)representedIndexOfTabViewItem:(NSTabViewItem *)tvi
@@ -973,6 +995,27 @@ - (id)initWithIdentifier:(int32_t)ident type:(int)theType
973995
return self;
974996
}
975997

998+
- (void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag
999+
{
1000+
// Dark mode scrollbars draw a translucent knob slot overlaid on top of
1001+
// whatever background the view has, even when we are using legacy
1002+
// scrollbars with a dedicated space. This means we need to draw the
1003+
// background with some colors first, or else it would look really black, or
1004+
// show through rendering artifacts (e.g. if guioption 'k' is on, and you
1005+
// turn off the bar bar, the artiacts will show through in the overlay).
1006+
//
1007+
// Note: This should ideally be done on MMVimView itself by setting a background
1008+
// color. This would be fixed at a later time by telling the view to just
1009+
// use the background color form the backed CALayer (mandated since Mojave
1010+
// 10.14).
1011+
MMVimView *vimView = [self target];
1012+
NSColor *defaultBackgroundColor = [[vimView textView] defaultBackgroundColor];
1013+
[defaultBackgroundColor setFill];
1014+
NSRectFill(slotRect);
1015+
1016+
[super drawKnobSlotInRect:slotRect highlight:flag];
1017+
}
1018+
9761019
- (int32_t)scrollerId
9771020
{
9781021
return identifier;

0 commit comments

Comments
 (0)