From 84354c2696e6927b8b630279fe3405d06a25fdce Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Wed, 3 Jun 2026 17:04:18 +0200 Subject: [PATCH] Metal: use NSColor highlight/shadow for box relief colors ns_setup_relief_colors derives the relief edges via NSColor highlightWithLevel:/shadowWithLevel:, which are appearance-dynamic (in dark mode the system highlight is not a blend toward pure white), so the manual mtl_shade_color blend did not match what NS renders: the mode-line top edge came out 211 vs NS's 177. Use the same NSColor APIs, falling back to the manual shade if they return nil. Mode-line relief now matches NS exactly; sparse-baseline AE drops from 0.33% to 0.068%. --- src/mtlterm.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/mtlterm.m b/src/mtlterm.m index ea5ca6fdf30..4ae9096f1b5 100644 --- a/src/mtlterm.m +++ b/src/mtlterm.m @@ -1971,8 +1971,17 @@ mtl_draw_glyph_string_box (struct glyph_string *s, MtlFrameData *fd) ? face->box_color : face->background; if (s->hl == DRAW_CURSOR) base = ns_color_to_pixel (FRAME_CURSOR_COLOR (s->f)); - unsigned long light = mtl_shade_color (base, 0.4, true); - unsigned long dark = mtl_shade_color (base, 0.4, false); + /* Use the same NSColor highlight/shadow used by ns_setup_relief_colors: + these are appearance-dynamic (dark mode shifts the highlight), so a + plain blend toward pure white/black does not match what NS renders + (e.g. the mode-line top edge: NS ~177 vs blend-to-white 211). */ + NSColor *bc = [NSColor colorWithUnsignedLong:base]; + NSColor *lc = [bc highlightWithLevel:0.4]; + NSColor *dc = [bc shadowWithLevel:0.4]; + unsigned long light = lc ? ns_color_to_pixel (lc) + : mtl_shade_color (base, 0.4, true); + unsigned long dark = dc ? ns_color_to_pixel (dc) + : mtl_shade_color (base, 0.4, false); bool raised = (face->box == FACE_RAISED_BOX); tl = raised ? light : dark; br = raised ? dark : light;