Skip to content

Commit 63dbd58

Browse files
authored
Merge pull request #793 from ychin/scrollbar_dark_mode_fix
Fix scrollbars in Mojave dark mode not rendering properly
2 parents dabe5a2 + 4ba02a8 commit 63dbd58

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

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)