Skip to content

Commit 3d73af4

Browse files
committed
Fix macOS 14 Sonoma non-native full screen background color
Non-native full screen's configured background color (default to black) stopped working when building using macOS 14 SDK, because the main CoreText view was now drawing over it in drawRect, due to the new clipToBounds property defaulting to false in macOS 14 SDK. We could just fix this issue by setting clipToBounds to true on the text view, but we would lose the benefits of the new behavior which allows us to show tall texts (e.g. Tibetan texts or other characters with composing chars) on the first line and not have it be clipped at the top. Currently with the unclipped behavior, the character can be drawn and poke up into the window frame or the notch area. To properly fix this, just clip the background color fill in drawRect, and allow texts etc to still draw outside the rect.
1 parent 784b26c commit 3d73af4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/MacVim/MMCoreTextView.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,17 @@ - (void)drawRect:(NSRect)rect
760760
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
761761
const BOOL clipTextToRow = [ud boolForKey:MMRendererClipToRowKey]; // Specify whether to clip tall characters by the row boundary.
762762

763+
764+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_14_0
765+
// On macOS 14+ by default views don't clip their content, which is good as it allows tall texts
766+
// on first line to be drawn fully without getting clipped. However, in this case we should make
767+
// sure the background color fill is clipped properly, as otherwise it will interfere with
768+
// non-native fullscreen's background color setting.
769+
const BOOL clipBackground = !self.clipsToBounds;
770+
#else
771+
const BOOL clipBackground = NO;
772+
#endif
773+
763774
NSGraphicsContext *context = [NSGraphicsContext currentContext];
764775
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
765776
CGContextRef ctx = context.CGContext;
@@ -791,7 +802,14 @@ - (void)drawRect:(NSRect)rect
791802
const unsigned defaultBg = defaultBackgroundColor.argbInt;
792803
CGContextSetFillColor(ctx, COMPONENTS(defaultBg));
793804

805+
if (clipBackground) {
806+
CGContextSaveGState(ctx);
807+
CGContextClipToRect(ctx, self.bounds);
808+
}
794809
CGContextFillRect(ctx, rect);
810+
if (clipBackground) {
811+
CGContextRestoreGState(ctx);
812+
}
795813

796814
// Function to draw all rows
797815
void (^drawAllRows)(void (^)(CGContextRef,CGRect,int)) = ^(void (^drawFunc)(CGContextRef,CGRect,int)){

src/MacVim/MacVim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
#ifndef MAC_OS_VERSION_13_0
5353
# define MAC_OS_VERSION_13_0 130000
5454
#endif
55+
#ifndef MAC_OS_VERSION_14_0
56+
# define MAC_OS_VERSION_14_0 140000
57+
#endif
5558

5659
#ifndef NSAppKitVersionNumber10_10
5760
# define NSAppKitVersionNumber10_10 1343

0 commit comments

Comments
 (0)