# st

Unnamed repository; edit this file 'description' to name the repository.

| Log | Files | Refs | README | LICENSE

    commit b9aff90abf534571e577d54cdf154d8f5aa2f18c
    parent 4ec1c1aa1dc08c2e77fdd5ac10580ab26a396b3d
    Author: c0dev0id <sh+github@codevoid.de>
    Date:   Sat, 31 Jul 2021 19:17:03 +0200

    sdk-boxdraw-patch

    Diffstat:
    MMakefile | 3++-
    Mconfig.def.h | 12++++++++++++
    Mconfig.h | 14+++++++++++++-
    Mst.c | 3+++
    Mst.h | 10++++++++++
    Mx.c | 21++++++++++++++++-----

    6 files changed, 56 insertions(+), 7 deletions(-)
    diff --git a/Makefile b/Makefile
    @@ -4,7 +4,7 @@

     include config.mk

    -SRC = st.c x.c
    +SRC = st.c x.c boxdraw.c
     OBJ = $(SRC:.c=.o)

     all: options st
    @@ -23,6 +23,7 @@ config.h:

     st.o: config.h st.h win.h
     x.o: arg.h config.h st.h win.h
    +boxdraw.o: config.h st.h boxdraw_data.h

     $(OBJ): config.h config.mk

    diff --git a/config.def.h b/config.def.h
    @@ -68,6 +68,18 @@ static unsigned int blinktimeout = 800;
     static unsigned int cursorthickness = 2;

     /*
    + * 1: render most of the lines/blocks characters without using the font for
    + *    perfect alignment between cells (U2500 - U259F except dashes/diagonals).
    + *    Bold affects lines thickness if boxdraw_bold is not 0. Italic is ignored.
    + * 0: disable (render all U25XX glyphs normally from the font).
    + */
    +const int boxdraw = 0;
    +const int boxdraw_bold = 0;
    +
    +/* braille (U28XX):  1: render as adjacent "pixels",  0: use font */
    +const int boxdraw_braille = 0;
    +
    +/*
      * bell volume. It must be a value between -100 and 100. Use 0 for disabling
      * it
      */
    diff --git a/config.h b/config.h
    @@ -68,13 +68,25 @@ static unsigned int blinktimeout = 800;
     static unsigned int cursorthickness = 2;

     /*
    + * 1: render most of the lines/blocks characters without using the font for
    + *    perfect alignment between cells (U2500 - U259F except dashes/diagonals).
    + *    Bold affects lines thickness if boxdraw_bold is not 0. Italic is ignored.
    + * 0: disable (render all U25XX glyphs normally from the font).
    + */
    +const int boxdraw = 1;
    +const int boxdraw_bold = 1;
    +
    +/* braille (U28XX):  1: render as adjacent "pixels",  0: use font */
    +const int boxdraw_braille = 1;
    +
    +/*
      * bell volume. It must be a value between -100 and 100. Use 0 for disabling
      * it
      */
     static int bellvolume = 0;

     /* default TERM value */
    -char *termname = "st-256color";
    +char *termname = "xterm-256color";

     /*
      * spaces per tab
    diff --git a/st.c b/st.c
    @@ -1284,6 +1284,9 @@ tsetchar(Rune u, const Glyph *attr, int x, int y)
     	term.dirty[y] = 1;
     	term.line[y][x] = *attr;
     	term.line[y][x].u = u;
    +
    +	if (isboxdraw(u))
    +		term.line[y][x].mode |= ATTR_BOXDRAW;
     }

     void
    diff --git a/st.h b/st.h
    @@ -33,6 +33,7 @@ enum glyph_attribute {
     	ATTR_WRAP       = 1 << 8,
     	ATTR_WIDE       = 1 << 9,
     	ATTR_WDUMMY     = 1 << 10,
    +	ATTR_BOXDRAW    = 1 << 11,
     	ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
     };

    @@ -113,6 +114,14 @@ void *xmalloc(size_t);
     void *xrealloc(void *, size_t);
     char *xstrdup(const char *);

    +int isboxdraw(Rune);
    +ushort boxdrawindex(const Glyph *);
    +#ifdef XFT_VERSION
    +/* only exposed to x.c, otherwise we'll need Xft.h for the types */
    +void boxdraw_xinit(Display *, Colormap, XftDraw *, Visual *);
    +void drawboxes(int, int, int, int, XftColor *, XftColor *, const XftGlyphFontSpec *, int);
    +#endif
    +
     /* config.h globals */
     extern char *utmp;
     extern char *scroll;
    @@ -125,3 +134,4 @@ extern char *termname;
     extern unsigned int tabspaces;
     extern unsigned int defaultfg;
     extern unsigned int defaultbg;
    +extern const int boxdraw, boxdraw_bold, boxdraw_braille;
    diff --git a/x.c b/x.c
    @@ -1208,6 +1208,8 @@ xinit(int cols, int rows)
     	xsel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0);
     	if (xsel.xtarget == None)
     		xsel.xtarget = XA_STRING;
    +
    +	boxdraw_xinit(xw.dpy, xw.cmap, xw.draw, xw.vis);
     }

     int
    @@ -1254,8 +1256,13 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
     			yp = winy + font->ascent;
     		}

    -		/* Lookup character index with default font. */
    -		glyphidx = XftCharIndex(xw.dpy, font->match, rune);
    +		if (mode & ATTR_BOXDRAW) {
    +			/* minor shoehorning: boxdraw uses only this ushort */
    +			glyphidx = boxdrawindex(&glyphs[i]);
    +		} else {
    +			/* Lookup character index with default font. */
    +			glyphidx = XftCharIndex(xw.dpy, font->match, rune);
    +		}
     		if (glyphidx) {
     			specs[numspecs].font = font->match;
     			specs[numspecs].glyph = glyphidx;
    @@ -1459,8 +1466,12 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
     	r.width = width;
     	XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);

    -	/* Render the glyphs. */
    -	XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
    +	if (base.mode & ATTR_BOXDRAW) {
    +		drawboxes(winx, winy, width / len, win.ch, fg, bg, specs, len);
    +	} else {
    +		/* Render the glyphs. */
    +		XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
    +	}

     	/* Render underline and strikethrough. */
     	if (base.mode & ATTR_UNDERLINE) {
    @@ -1503,7 +1514,7 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
     	/*
     	 * Select the right color for the right mode.
     	 */
    -	g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE;
    +	g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE|ATTR_BOXDRAW;

     	if (IS_SET(MODE_REVERSE)) {
     		g.mode |= ATTR_REVERSE;