st

my st build
Log | Files | Refs | README | LICENSE

commit 6971b078bb82bed45e8ee3664b55fa626da05450
parent 6cc852b5bc6bbfe36ac03ba6e4dea92bccafa2e2
Author: ssnf <ssnf@ssnf.xyz>
Date:   Thu, 24 Apr 2025 14:07:37 +0000

add glow to glyphs

Diffstat:
Mx.c | 38++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/x.c b/x.c @@ -1395,9 +1395,11 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1); int winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, width = charlen * win.cw; - Color *fg, *bg, *temp, revfg, revbg, truefg, truebg; - XRenderColor colfg, colbg; + Color *fg, *bg, *temp, revfg, revbg, truefg, truebg, glow; + XRenderColor colfg, colbg, colglow; XRectangle r; + int dx, dy, i; + ushort fgluma, bgluma; /* Fallback on color display for attributes not supported by the font */ if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) { @@ -1507,6 +1509,38 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1); /* Render the glyphs. */ + fgluma = fg->color.red * 0.299 + + fg->color.green * 0.587 + + fg->color.blue * 0.114 + ; + bgluma = bg->color.red * 0.299 + + bg->color.green * 0.587 + + bg->color.blue * 0.114 + ; + if (fgluma <= bgluma) + goto draw; + colglow.red = fg->color.red / 8; + colglow.green = fg->color.green / 8; + colglow.blue = fg->color.blue / 8; + colglow.alpha = 0xffff * (fgluma - bgluma); + if (!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colglow, &glow)) + goto draw; + for (dx = -1; dx <= 1; ++dx) { + for (dy = -1; dy <= 1; ++dy) { + if (dx == 0 && dy == 0) + continue; + for (i = 0; i < len; ++i) { + ((XftGlyphFontSpec*)specs)[i].x += dx; + ((XftGlyphFontSpec*)specs)[i].y += dy; + } + XftDrawGlyphFontSpec(xw.draw, &glow, specs, len); + for (i = 0; i < len; ++i) { + ((XftGlyphFontSpec*)specs)[i].x -= dx; + ((XftGlyphFontSpec*)specs)[i].y -= dy; + } + } + } +draw: XftDrawGlyphFontSpec(xw.draw, fg, specs, len); /* Render underline and strikethrough. */