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%.
This commit is contained in:
Andros Fenollosa 2026-06-03 17:04:18 +02:00
parent 1aff29efde
commit 84354c2696

View file

@ -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;