From df482c4158e3579c8ab41d2851ea4cbb9b0057c7 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Sun, 4 Sep 2022 23:32:23 +0530 Subject: renaming diff files --- .../10th-ligatures-scrollback-20210824-0.8.4.diff | 314 --------------------- patches/10th-oeSQ.diff | 193 +++++++++++++ .../11th-ligatures-scrollback-20210824-0.8.4.diff | 314 +++++++++++++++++++++ patches/11th-st-externalpipe-0.8.4.diff | 92 ------ patches/12th-st-externalpipe-0.8.4.diff | 92 ++++++ 5 files changed, 599 insertions(+), 406 deletions(-) delete mode 100644 patches/10th-ligatures-scrollback-20210824-0.8.4.diff create mode 100644 patches/10th-oeSQ.diff create mode 100644 patches/11th-ligatures-scrollback-20210824-0.8.4.diff delete mode 100644 patches/11th-st-externalpipe-0.8.4.diff create mode 100644 patches/12th-st-externalpipe-0.8.4.diff (limited to 'patches') diff --git a/patches/10th-ligatures-scrollback-20210824-0.8.4.diff b/patches/10th-ligatures-scrollback-20210824-0.8.4.diff deleted file mode 100644 index 94e842a..0000000 --- a/patches/10th-ligatures-scrollback-20210824-0.8.4.diff +++ /dev/null @@ -1,314 +0,0 @@ -diff --git a/Makefile b/Makefile -index 470ac86..38240da 100644 ---- a/Makefile -+++ b/Makefile -@@ -4,7 +4,7 @@ - - include config.mk - --SRC = st.c x.c -+SRC = st.c x.c hb.c - OBJ = $(SRC:.c=.o) - - all: options st -@@ -22,7 +22,8 @@ config.h: - $(CC) $(STCFLAGS) -c $< - - st.o: config.h st.h win.h --x.o: arg.h config.h st.h win.h -+x.o: arg.h config.h st.h win.h hb.h -+hb.o: st.h - - $(OBJ): config.h config.mk - -diff --git a/config.mk b/config.mk -index c070a4a..3d236f0 100644 ---- a/config.mk -+++ b/config.mk -@@ -15,10 +15,12 @@ PKG_CONFIG = pkg-config - # includes and libs - INCS = -I$(X11INC) \ - `$(PKG_CONFIG) --cflags fontconfig` \ -- `$(PKG_CONFIG) --cflags freetype2` -+ `$(PKG_CONFIG) --cflags freetype2` \ -+ `$(PKG_CONFIG) --cflags harfbuzz` - LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \ - `$(PKG_CONFIG) --libs fontconfig` \ -- `$(PKG_CONFIG) --libs freetype2` -+ `$(PKG_CONFIG) --libs freetype2` \ -+ `$(PKG_CONFIG) --libs harfbuzz` - - # flags - STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -diff --git a/hb.c b/hb.c -new file mode 100644 -index 0000000..f9c4f76 ---- /dev/null -+++ b/hb.c -@@ -0,0 +1,144 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#include "st.h" -+ -+#define FEATURE(c1,c2,c3,c4) { .tag = HB_TAG(c1,c2,c3,c4), .value = 1, .start = HB_FEATURE_GLOBAL_START, .end = HB_FEATURE_GLOBAL_END } -+ -+void hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length); -+hb_font_t *hbfindfont(XftFont *match); -+ -+typedef struct { -+ XftFont *match; -+ hb_font_t *font; -+} HbFontMatch; -+ -+static int hbfontslen = 0; -+static HbFontMatch *hbfontcache = NULL; -+ -+/* -+ * Replace 0 with a list of font features, wrapped in FEATURE macro, e.g. -+ * FEATURE('c', 'a', 'l', 't'), FEATURE('d', 'l', 'i', 'g') -+ */ -+hb_feature_t features[] = { 0 }; -+ -+void -+hbunloadfonts() -+{ -+ for (int i = 0; i < hbfontslen; i++) { -+ hb_font_destroy(hbfontcache[i].font); -+ XftUnlockFace(hbfontcache[i].match); -+ } -+ -+ if (hbfontcache != NULL) { -+ free(hbfontcache); -+ hbfontcache = NULL; -+ } -+ hbfontslen = 0; -+} -+ -+hb_font_t * -+hbfindfont(XftFont *match) -+{ -+ for (int i = 0; i < hbfontslen; i++) { -+ if (hbfontcache[i].match == match) -+ return hbfontcache[i].font; -+ } -+ -+ /* Font not found in cache, caching it now. */ -+ hbfontcache = realloc(hbfontcache, sizeof(HbFontMatch) * (hbfontslen + 1)); -+ FT_Face face = XftLockFace(match); -+ hb_font_t *font = hb_ft_font_create(face, NULL); -+ if (font == NULL) -+ die("Failed to load Harfbuzz font."); -+ -+ hbfontcache[hbfontslen].match = match; -+ hbfontcache[hbfontslen].font = font; -+ hbfontslen += 1; -+ -+ return font; -+} -+ -+void -+hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len, int x, int y) -+{ -+ int start = 0, length = 1, gstart = 0; -+ hb_codepoint_t *codepoints = calloc((unsigned int)len, sizeof(hb_codepoint_t)); -+ -+ for (int idx = 1, specidx = 1; idx < len; idx++) { -+ if (glyphs[idx].mode & ATTR_WDUMMY) { -+ length += 1; -+ continue; -+ } -+ -+ if (specs[specidx].font != specs[start].font || ATTRCMP(glyphs[gstart], glyphs[idx]) || selected(x + idx, y) != selected(x + gstart, y)) { -+ hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length); -+ -+ /* Reset the sequence. */ -+ length = 1; -+ start = specidx; -+ gstart = idx; -+ } else { -+ length += 1; -+ } -+ -+ specidx++; -+ } -+ -+ /* EOL. */ -+ hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length); -+ -+ /* Apply the transformation to glyph specs. */ -+ for (int i = 0, specidx = 0; i < len; i++) { -+ if (glyphs[i].mode & ATTR_WDUMMY) -+ continue; -+ -+ if (codepoints[i] != specs[specidx].glyph) -+ ((Glyph *)glyphs)[i].mode |= ATTR_LIGA; -+ -+ specs[specidx++].glyph = codepoints[i]; -+ } -+ -+ free(codepoints); -+} -+ -+void -+hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length) -+{ -+ hb_font_t *font = hbfindfont(xfont); -+ if (font == NULL) -+ return; -+ -+ Rune rune; -+ ushort mode = USHRT_MAX; -+ hb_buffer_t *buffer = hb_buffer_create(); -+ hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); -+ -+ /* Fill buffer with codepoints. */ -+ for (int i = start; i < (start+length); i++) { -+ rune = string[i].u; -+ mode = string[i].mode; -+ if (mode & ATTR_WDUMMY) -+ rune = 0x0020; -+ hb_buffer_add_codepoints(buffer, &rune, 1, 0, 1); -+ } -+ -+ /* Shape the segment. */ -+ hb_shape(font, buffer, features, sizeof(features)); -+ -+ /* Get new glyph info. */ -+ hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, NULL); -+ -+ /* Write new codepoints. */ -+ for (int i = 0; i < length; i++) { -+ hb_codepoint_t gid = info[i].codepoint; -+ codepoints[start+i] = gid; -+ } -+ -+ /* Cleanup. */ -+ hb_buffer_destroy(buffer); -+} -diff --git a/hb.h b/hb.h -new file mode 100644 -index 0000000..07888df ---- /dev/null -+++ b/hb.h -@@ -0,0 +1,6 @@ -+#include -+#include -+#include -+ -+void hbunloadfonts(); -+void hbtransform(XftGlyphFontSpec *, const Glyph *, size_t, int, int); -diff --git a/st.c b/st.c -index edec064..ea13c13 100644 ---- a/st.c -+++ b/st.c -@@ -2652,7 +2652,8 @@ draw(void) - drawregion(0, 0, term.col, term.row); - if (term.scr == 0) - xdrawcursor(cx, term.c.y, term.line[term.c.y][cx], -- term.ocx, term.ocy, term.line[term.ocy][term.ocx]); -+ term.ocx, term.ocy, term.line[term.ocy][term.ocx], -+ term.line[term.ocy], term.col); - term.ocx = cx; - term.ocy = term.c.y; - xfinishdraw(); -diff --git a/st.h b/st.h -index f44e1d3..00c796c 100644 ---- a/st.h -+++ b/st.h -@@ -11,7 +11,8 @@ - #define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d)) - #define DEFAULT(a, b) (a) = (a) ? (a) : (b) - #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) --#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \ -+#define ATTRCMP(a, b) (((a).mode & (~ATTR_WRAP) & (~ATTR_LIGA)) != ((b).mode & (~ATTR_WRAP) & (~ATTR_LIGA)) || \ -+ (a).fg != (b).fg || \ - (a).bg != (b).bg) - #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \ - (t1.tv_nsec-t2.tv_nsec)/1E6) -@@ -33,6 +34,7 @@ enum glyph_attribute { - ATTR_WRAP = 1 << 8, - ATTR_WIDE = 1 << 9, - ATTR_WDUMMY = 1 << 10, -+ ATTR_LIGA = 1 << 11, - ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, - }; - -diff --git a/win.h b/win.h -index a6ef1b9..bc0d180 100644 ---- a/win.h -+++ b/win.h -@@ -25,7 +25,7 @@ enum win_mode { - - void xbell(void); - void xclipcopy(void); --void xdrawcursor(int, int, Glyph, int, int, Glyph); -+void xdrawcursor(int, int, Glyph, int, int, Glyph, Line, int); - void xdrawline(Line, int, int, int); - void xfinishdraw(void); - void xloadcols(void); -diff --git a/x.c b/x.c -index 210f184..f6d67ef 100644 ---- a/x.c -+++ b/x.c -@@ -19,6 +19,7 @@ char *argv0; - #include "arg.h" - #include "st.h" - #include "win.h" -+#include "hb.h" - - /* types used in config.h */ - typedef struct { -@@ -1031,6 +1032,9 @@ xunloadfont(Font *f) - void - xunloadfonts(void) - { -+ /* Clear Harfbuzz font cache. */ -+ hbunloadfonts(); -+ - /* Free the loaded fonts in the font cache. */ - while (frclen > 0) - XftFontClose(xw.dpy, frc[--frclen].font); -@@ -1229,7 +1233,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x - mode = glyphs[i].mode; - - /* Skip dummy wide-character spacing. */ -- if (mode == ATTR_WDUMMY) -+ if (mode & ATTR_WDUMMY) - continue; - - /* Determine font for glyph if different from previous glyph. */ -@@ -1336,6 +1340,9 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x - numspecs++; - } - -+ /* Harfbuzz transformation for ligatures. */ -+ hbtransform(specs, glyphs, len, x, y); -+ - return numspecs; - } - -@@ -1485,14 +1492,17 @@ xdrawglyph(Glyph g, int x, int y) - } - - void --xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) -+xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og, Line line, int len) - { - Color drawcol; - - /* remove the old cursor */ - if (selected(ox, oy)) - og.mode ^= ATTR_REVERSE; -- xdrawglyph(og, ox, oy); -+ -+ /* Redraw the line where cursor was previously. -+ * It will restore the ligatures broken by the cursor. */ -+ xdrawline(line, 0, oy, len); - - if (IS_SET(MODE_HIDE)) - return; diff --git a/patches/10th-oeSQ.diff b/patches/10th-oeSQ.diff new file mode 100644 index 0000000..5e83d03 --- /dev/null +++ b/patches/10th-oeSQ.diff @@ -0,0 +1,193 @@ +diff --git a/st.h b/st.h +index a584b72..7ac4d7c 100644 +--- a/st.h ++++ b/st.h +@@ -37,6 +37,12 @@ enum glyph_attribute { + ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, + }; + ++enum drawing_mode { ++ DRAW_NONE = 0, ++ DRAW_BG = 1 << 0, ++ DRAW_FG = 1 << 1, ++}; ++ + enum selection_mode { + SEL_IDLE = 0, + SEL_EMPTY = 1, +diff --git a/x.c b/x.c +index 1560382..b552e8d 100644 +--- a/x.c ++++ b/x.c +@@ -145,7 +145,7 @@ typedef struct { + + static inline ushort sixd_to_16bit(int); + static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int, int); +-static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int); ++static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int, int); + static void xdrawglyph(Glyph, int, int); + static void xclear(int, int, int, int); + static int xgeommasktogravity(int); +@@ -1488,7 +1488,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x + } + + void +-xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y) ++xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y, int dmode) + { + int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1); + int winx = win.hborderpx + x * win.cw, winy = win.vborderpx + y * win.ch, +@@ -1579,23 +1579,21 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i + if (base.mode & ATTR_INVISIBLE) + fg = bg; + +- /* Intelligent cleaning up of the borders. */ +- if (x == 0) { +- xclear(0, (y == 0)? 0 : winy, win.hborderpx, +- winy + win.ch + +- ((winy + win.ch >= win.vborderpx + win.th)? win.h : 0)); +- } +- if (winx + width >= win.hborderpx + win.tw) { +- xclear(winx + width, (y == 0)? 0 : winy, win.w, +- ((winy + win.ch >= win.vborderpx + win.th)? win.h : (winy + win.ch))); +- } +- if (y == 0) +- xclear(winx, 0, winx + width, win.vborderpx); +- if (winy + win.ch >= win.vborderpx + win.th) +- xclear(winx, winy + win.ch, winx + width, win.h); +- +- /* Clean up the region we want to draw to. */ +- XftDrawRect(xw.draw, bg, winx, winy, width, win.ch); ++ if (dmode & DRAW_BG) { ++ /* Intelligent cleaning up of the borders. */ ++ if (x == 0) { ++ xclear(0, (y == 0)? 0 : winy, win.vborderpx, ++ winy + win.ch + ++ ((winy + win.ch >= win.vborderpx + win.th)? win.h : 0)); ++ } ++ if (winx + width >= win.hborderpx + win.tw) { ++ xclear(winx + width, (y == 0)? 0 : winy, win.w, ++ ((winy + win.ch >= win.vborderpx + win.th)? win.h : (winy + win.ch))); ++ } ++ if (y == 0) ++ xclear(winx, 0, winx + width, win.hborderpx); ++ if (winy + win.ch >= win.vborderpx + win.th) ++ xclear(winx, winy + win.ch, winx + width, win.h); + + /* Set the clip region because Xft is sometimes dirty. */ + r.x = 0; +@@ -1604,22 +1602,29 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i + r.width = width; + XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1); + +- 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); +- } ++ /* Fill the background */ ++ XftDrawRect(xw.draw, bg, winx, winy, width, win.ch); + +- /* Render underline and strikethrough. */ +- if (base.mode & ATTR_UNDERLINE) { +- XftDrawRect(xw.draw, fg, winx, winy + win.cyo + dc.font.ascent + 1, +- width, 1); + } + +- if (base.mode & ATTR_STRUCK) { +- XftDrawRect(xw.draw, fg, winx, winy + win.cyo + 2 * dc.font.ascent / 3, +- width, 1); ++ if (dmode & DRAW_FG) { ++ 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) { ++ XftDrawRect(xw.draw, fg, winx, winy + win.cyo + dc.font.ascent + 1, ++ width, 1); ++ } ++ ++ if (base.mode & ATTR_STRUCK) { ++ XftDrawRect(xw.draw, fg, winx, winy + win.cyo + 2 * dc.font.ascent / 3, ++ width, 1); ++ } + } + + /* Reset clip to none. */ +@@ -1633,7 +1638,7 @@ xdrawglyph(Glyph g, int x, int y) + XftGlyphFontSpec spec; + + numspecs = xmakeglyphfontspecs(&spec, &g, 1, x, y); +- xdrawglyphfontspecs(&spec, g, numspecs, x, y); ++ xdrawglyphfontspecs(&spec, g, numspecs, x, y, DRAW_BG | DRAW_FG); + } + + void +@@ -1768,32 +1773,39 @@ xstartdraw(void) + void + xdrawline(Line line, int x1, int y1, int x2) + { +- int i, x, ox, numspecs; ++ int i, x, ox, numspecs, numspecs_cached; + Glyph base, new; +- XftGlyphFontSpec *specs = xw.specbuf; +- +- numspecs = xmakeglyphfontspecs(specs, &line[x1], x2 - x1, x1, y1); +- i = ox = 0; +- for (x = x1; x < x2 && i < numspecs; x++) { +- new = line[x]; +- if (new.mode == ATTR_WDUMMY) +- continue; +- if (selected(x, y1)) +- new.mode ^= ATTR_REVERSE; +- if (i > 0 && ATTRCMP(base, new)) { +- xdrawglyphfontspecs(specs, base, i, ox, y1); +- specs += i; +- numspecs -= i; +- i = 0; +- } +- if (i == 0) { +- ox = x; +- base = new; ++ XftGlyphFontSpec *specs; ++ ++ numspecs_cached = xmakeglyphfontspecs(xw.specbuf, &line[x1], x2 - x1, x1, y1); ++ ++ /* Draw line in 2 passes: background and foreground. This way wide glyphs ++ won't get truncated (#223) */ ++ for (int dmode = DRAW_BG; dmode <= DRAW_FG; dmode <<= 1) { ++ specs = xw.specbuf; ++ numspecs = numspecs_cached; ++ i = ox = 0; ++ for (x = x1; x < x2 && i < numspecs; x++) { ++ new = line[x]; ++ if (new.mode == ATTR_WDUMMY) ++ continue; ++ if (selected(x, y1)) ++ new.mode ^= ATTR_REVERSE; ++ if (i > 0 && ATTRCMP(base, new)) { ++ xdrawglyphfontspecs(specs, base, i, ox, y1, dmode); ++ specs += i; ++ numspecs -= i; ++ i = 0; ++ } ++ if (i == 0) { ++ ox = x; ++ base = new; ++ } ++ i++; + } +- i++; ++ if (i > 0) ++ xdrawglyphfontspecs(specs, base, i, ox, y1, dmode); + } +- if (i > 0) +- xdrawglyphfontspecs(specs, base, i, ox, y1); + } + + void diff --git a/patches/11th-ligatures-scrollback-20210824-0.8.4.diff b/patches/11th-ligatures-scrollback-20210824-0.8.4.diff new file mode 100644 index 0000000..94e842a --- /dev/null +++ b/patches/11th-ligatures-scrollback-20210824-0.8.4.diff @@ -0,0 +1,314 @@ +diff --git a/Makefile b/Makefile +index 470ac86..38240da 100644 +--- a/Makefile ++++ b/Makefile +@@ -4,7 +4,7 @@ + + include config.mk + +-SRC = st.c x.c ++SRC = st.c x.c hb.c + OBJ = $(SRC:.c=.o) + + all: options st +@@ -22,7 +22,8 @@ config.h: + $(CC) $(STCFLAGS) -c $< + + st.o: config.h st.h win.h +-x.o: arg.h config.h st.h win.h ++x.o: arg.h config.h st.h win.h hb.h ++hb.o: st.h + + $(OBJ): config.h config.mk + +diff --git a/config.mk b/config.mk +index c070a4a..3d236f0 100644 +--- a/config.mk ++++ b/config.mk +@@ -15,10 +15,12 @@ PKG_CONFIG = pkg-config + # includes and libs + INCS = -I$(X11INC) \ + `$(PKG_CONFIG) --cflags fontconfig` \ +- `$(PKG_CONFIG) --cflags freetype2` ++ `$(PKG_CONFIG) --cflags freetype2` \ ++ `$(PKG_CONFIG) --cflags harfbuzz` + LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \ + `$(PKG_CONFIG) --libs fontconfig` \ +- `$(PKG_CONFIG) --libs freetype2` ++ `$(PKG_CONFIG) --libs freetype2` \ ++ `$(PKG_CONFIG) --libs harfbuzz` + + # flags + STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 +diff --git a/hb.c b/hb.c +new file mode 100644 +index 0000000..f9c4f76 +--- /dev/null ++++ b/hb.c +@@ -0,0 +1,144 @@ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "st.h" ++ ++#define FEATURE(c1,c2,c3,c4) { .tag = HB_TAG(c1,c2,c3,c4), .value = 1, .start = HB_FEATURE_GLOBAL_START, .end = HB_FEATURE_GLOBAL_END } ++ ++void hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length); ++hb_font_t *hbfindfont(XftFont *match); ++ ++typedef struct { ++ XftFont *match; ++ hb_font_t *font; ++} HbFontMatch; ++ ++static int hbfontslen = 0; ++static HbFontMatch *hbfontcache = NULL; ++ ++/* ++ * Replace 0 with a list of font features, wrapped in FEATURE macro, e.g. ++ * FEATURE('c', 'a', 'l', 't'), FEATURE('d', 'l', 'i', 'g') ++ */ ++hb_feature_t features[] = { 0 }; ++ ++void ++hbunloadfonts() ++{ ++ for (int i = 0; i < hbfontslen; i++) { ++ hb_font_destroy(hbfontcache[i].font); ++ XftUnlockFace(hbfontcache[i].match); ++ } ++ ++ if (hbfontcache != NULL) { ++ free(hbfontcache); ++ hbfontcache = NULL; ++ } ++ hbfontslen = 0; ++} ++ ++hb_font_t * ++hbfindfont(XftFont *match) ++{ ++ for (int i = 0; i < hbfontslen; i++) { ++ if (hbfontcache[i].match == match) ++ return hbfontcache[i].font; ++ } ++ ++ /* Font not found in cache, caching it now. */ ++ hbfontcache = realloc(hbfontcache, sizeof(HbFontMatch) * (hbfontslen + 1)); ++ FT_Face face = XftLockFace(match); ++ hb_font_t *font = hb_ft_font_create(face, NULL); ++ if (font == NULL) ++ die("Failed to load Harfbuzz font."); ++ ++ hbfontcache[hbfontslen].match = match; ++ hbfontcache[hbfontslen].font = font; ++ hbfontslen += 1; ++ ++ return font; ++} ++ ++void ++hbtransform(XftGlyphFontSpec *specs, const Glyph *glyphs, size_t len, int x, int y) ++{ ++ int start = 0, length = 1, gstart = 0; ++ hb_codepoint_t *codepoints = calloc((unsigned int)len, sizeof(hb_codepoint_t)); ++ ++ for (int idx = 1, specidx = 1; idx < len; idx++) { ++ if (glyphs[idx].mode & ATTR_WDUMMY) { ++ length += 1; ++ continue; ++ } ++ ++ if (specs[specidx].font != specs[start].font || ATTRCMP(glyphs[gstart], glyphs[idx]) || selected(x + idx, y) != selected(x + gstart, y)) { ++ hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length); ++ ++ /* Reset the sequence. */ ++ length = 1; ++ start = specidx; ++ gstart = idx; ++ } else { ++ length += 1; ++ } ++ ++ specidx++; ++ } ++ ++ /* EOL. */ ++ hbtransformsegment(specs[start].font, glyphs, codepoints, gstart, length); ++ ++ /* Apply the transformation to glyph specs. */ ++ for (int i = 0, specidx = 0; i < len; i++) { ++ if (glyphs[i].mode & ATTR_WDUMMY) ++ continue; ++ ++ if (codepoints[i] != specs[specidx].glyph) ++ ((Glyph *)glyphs)[i].mode |= ATTR_LIGA; ++ ++ specs[specidx++].glyph = codepoints[i]; ++ } ++ ++ free(codepoints); ++} ++ ++void ++hbtransformsegment(XftFont *xfont, const Glyph *string, hb_codepoint_t *codepoints, int start, int length) ++{ ++ hb_font_t *font = hbfindfont(xfont); ++ if (font == NULL) ++ return; ++ ++ Rune rune; ++ ushort mode = USHRT_MAX; ++ hb_buffer_t *buffer = hb_buffer_create(); ++ hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); ++ ++ /* Fill buffer with codepoints. */ ++ for (int i = start; i < (start+length); i++) { ++ rune = string[i].u; ++ mode = string[i].mode; ++ if (mode & ATTR_WDUMMY) ++ rune = 0x0020; ++ hb_buffer_add_codepoints(buffer, &rune, 1, 0, 1); ++ } ++ ++ /* Shape the segment. */ ++ hb_shape(font, buffer, features, sizeof(features)); ++ ++ /* Get new glyph info. */ ++ hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, NULL); ++ ++ /* Write new codepoints. */ ++ for (int i = 0; i < length; i++) { ++ hb_codepoint_t gid = info[i].codepoint; ++ codepoints[start+i] = gid; ++ } ++ ++ /* Cleanup. */ ++ hb_buffer_destroy(buffer); ++} +diff --git a/hb.h b/hb.h +new file mode 100644 +index 0000000..07888df +--- /dev/null ++++ b/hb.h +@@ -0,0 +1,6 @@ ++#include ++#include ++#include ++ ++void hbunloadfonts(); ++void hbtransform(XftGlyphFontSpec *, const Glyph *, size_t, int, int); +diff --git a/st.c b/st.c +index edec064..ea13c13 100644 +--- a/st.c ++++ b/st.c +@@ -2652,7 +2652,8 @@ draw(void) + drawregion(0, 0, term.col, term.row); + if (term.scr == 0) + xdrawcursor(cx, term.c.y, term.line[term.c.y][cx], +- term.ocx, term.ocy, term.line[term.ocy][term.ocx]); ++ term.ocx, term.ocy, term.line[term.ocy][term.ocx], ++ term.line[term.ocy], term.col); + term.ocx = cx; + term.ocy = term.c.y; + xfinishdraw(); +diff --git a/st.h b/st.h +index f44e1d3..00c796c 100644 +--- a/st.h ++++ b/st.h +@@ -11,7 +11,8 @@ + #define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d)) + #define DEFAULT(a, b) (a) = (a) ? (a) : (b) + #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) +-#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \ ++#define ATTRCMP(a, b) (((a).mode & (~ATTR_WRAP) & (~ATTR_LIGA)) != ((b).mode & (~ATTR_WRAP) & (~ATTR_LIGA)) || \ ++ (a).fg != (b).fg || \ + (a).bg != (b).bg) + #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \ + (t1.tv_nsec-t2.tv_nsec)/1E6) +@@ -33,6 +34,7 @@ enum glyph_attribute { + ATTR_WRAP = 1 << 8, + ATTR_WIDE = 1 << 9, + ATTR_WDUMMY = 1 << 10, ++ ATTR_LIGA = 1 << 11, + ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, + }; + +diff --git a/win.h b/win.h +index a6ef1b9..bc0d180 100644 +--- a/win.h ++++ b/win.h +@@ -25,7 +25,7 @@ enum win_mode { + + void xbell(void); + void xclipcopy(void); +-void xdrawcursor(int, int, Glyph, int, int, Glyph); ++void xdrawcursor(int, int, Glyph, int, int, Glyph, Line, int); + void xdrawline(Line, int, int, int); + void xfinishdraw(void); + void xloadcols(void); +diff --git a/x.c b/x.c +index 210f184..f6d67ef 100644 +--- a/x.c ++++ b/x.c +@@ -19,6 +19,7 @@ char *argv0; + #include "arg.h" + #include "st.h" + #include "win.h" ++#include "hb.h" + + /* types used in config.h */ + typedef struct { +@@ -1031,6 +1032,9 @@ xunloadfont(Font *f) + void + xunloadfonts(void) + { ++ /* Clear Harfbuzz font cache. */ ++ hbunloadfonts(); ++ + /* Free the loaded fonts in the font cache. */ + while (frclen > 0) + XftFontClose(xw.dpy, frc[--frclen].font); +@@ -1229,7 +1233,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x + mode = glyphs[i].mode; + + /* Skip dummy wide-character spacing. */ +- if (mode == ATTR_WDUMMY) ++ if (mode & ATTR_WDUMMY) + continue; + + /* Determine font for glyph if different from previous glyph. */ +@@ -1336,6 +1340,9 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x + numspecs++; + } + ++ /* Harfbuzz transformation for ligatures. */ ++ hbtransform(specs, glyphs, len, x, y); ++ + return numspecs; + } + +@@ -1485,14 +1492,17 @@ xdrawglyph(Glyph g, int x, int y) + } + + void +-xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) ++xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og, Line line, int len) + { + Color drawcol; + + /* remove the old cursor */ + if (selected(ox, oy)) + og.mode ^= ATTR_REVERSE; +- xdrawglyph(og, ox, oy); ++ ++ /* Redraw the line where cursor was previously. ++ * It will restore the ligatures broken by the cursor. */ ++ xdrawline(line, 0, oy, len); + + if (IS_SET(MODE_HIDE)) + return; diff --git a/patches/11th-st-externalpipe-0.8.4.diff b/patches/11th-st-externalpipe-0.8.4.diff deleted file mode 100644 index 297d746..0000000 --- a/patches/11th-st-externalpipe-0.8.4.diff +++ /dev/null @@ -1,92 +0,0 @@ -diff --git a/st.c b/st.c -index 76b7e0d..0e9a614 100644 ---- a/st.c -+++ b/st.c -@@ -723,8 +723,14 @@ sigchld(int a) - if ((p = waitpid(pid, &stat, WNOHANG)) < 0) - die("waiting for pid %hd failed: %s\n", pid, strerror(errno)); - -- if (pid != p) -+ if (pid != p) { -+ if (p == 0 && wait(&stat) < 0) -+ die("wait: %s\n", strerror(errno)); -+ -+ /* reinstall sigchld handler */ -+ signal(SIGCHLD, sigchld); - return; -+ } - - if (WIFEXITED(stat) && WEXITSTATUS(stat)) - die("child exited with status %d\n", WEXITSTATUS(stat)); -@@ -1926,6 +1932,59 @@ strparse(void) - } - } - -+void -+externalpipe(const Arg *arg) -+{ -+ int to[2]; -+ char buf[UTF_SIZ]; -+ void (*oldsigpipe)(int); -+ Glyph *bp, *end; -+ int lastpos, n, newline; -+ -+ if (pipe(to) == -1) -+ return; -+ -+ switch (fork()) { -+ case -1: -+ close(to[0]); -+ close(to[1]); -+ return; -+ case 0: -+ dup2(to[0], STDIN_FILENO); -+ close(to[0]); -+ close(to[1]); -+ execvp(((char **)arg->v)[0], (char **)arg->v); -+ fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]); -+ perror("failed"); -+ exit(0); -+ } -+ -+ close(to[0]); -+ /* ignore sigpipe for now, in case child exists early */ -+ oldsigpipe = signal(SIGPIPE, SIG_IGN); -+ newline = 0; -+ for (n = 0; n < term.row; n++) { -+ bp = term.line[n]; -+ lastpos = MIN(tlinelen(n) + 1, term.col) - 1; -+ if (lastpos < 0) -+ break; -+ end = &bp[lastpos + 1]; -+ for (; bp < end; ++bp) -+ if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0) -+ break; -+ if ((newline = term.line[n][lastpos].mode & ATTR_WRAP)) -+ continue; -+ if (xwrite(to[1], "\n", 1) < 0) -+ break; -+ newline = 0; -+ } -+ if (newline) -+ (void)xwrite(to[1], "\n", 1); -+ close(to[1]); -+ /* restore */ -+ signal(SIGPIPE, oldsigpipe); -+} -+ - void - strdump(void) - { -diff --git a/st.h b/st.h -index 3d351b6..392b64e 100644 ---- a/st.h -+++ b/st.h -@@ -81,6 +81,7 @@ void die(const char *, ...); - void redraw(void); - void draw(void); - -+void externalpipe(const Arg *); - void printscreen(const Arg *); - void printsel(const Arg *); - void sendbreak(const Arg *); diff --git a/patches/12th-st-externalpipe-0.8.4.diff b/patches/12th-st-externalpipe-0.8.4.diff new file mode 100644 index 0000000..297d746 --- /dev/null +++ b/patches/12th-st-externalpipe-0.8.4.diff @@ -0,0 +1,92 @@ +diff --git a/st.c b/st.c +index 76b7e0d..0e9a614 100644 +--- a/st.c ++++ b/st.c +@@ -723,8 +723,14 @@ sigchld(int a) + if ((p = waitpid(pid, &stat, WNOHANG)) < 0) + die("waiting for pid %hd failed: %s\n", pid, strerror(errno)); + +- if (pid != p) ++ if (pid != p) { ++ if (p == 0 && wait(&stat) < 0) ++ die("wait: %s\n", strerror(errno)); ++ ++ /* reinstall sigchld handler */ ++ signal(SIGCHLD, sigchld); + return; ++ } + + if (WIFEXITED(stat) && WEXITSTATUS(stat)) + die("child exited with status %d\n", WEXITSTATUS(stat)); +@@ -1926,6 +1932,59 @@ strparse(void) + } + } + ++void ++externalpipe(const Arg *arg) ++{ ++ int to[2]; ++ char buf[UTF_SIZ]; ++ void (*oldsigpipe)(int); ++ Glyph *bp, *end; ++ int lastpos, n, newline; ++ ++ if (pipe(to) == -1) ++ return; ++ ++ switch (fork()) { ++ case -1: ++ close(to[0]); ++ close(to[1]); ++ return; ++ case 0: ++ dup2(to[0], STDIN_FILENO); ++ close(to[0]); ++ close(to[1]); ++ execvp(((char **)arg->v)[0], (char **)arg->v); ++ fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]); ++ perror("failed"); ++ exit(0); ++ } ++ ++ close(to[0]); ++ /* ignore sigpipe for now, in case child exists early */ ++ oldsigpipe = signal(SIGPIPE, SIG_IGN); ++ newline = 0; ++ for (n = 0; n < term.row; n++) { ++ bp = term.line[n]; ++ lastpos = MIN(tlinelen(n) + 1, term.col) - 1; ++ if (lastpos < 0) ++ break; ++ end = &bp[lastpos + 1]; ++ for (; bp < end; ++bp) ++ if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0) ++ break; ++ if ((newline = term.line[n][lastpos].mode & ATTR_WRAP)) ++ continue; ++ if (xwrite(to[1], "\n", 1) < 0) ++ break; ++ newline = 0; ++ } ++ if (newline) ++ (void)xwrite(to[1], "\n", 1); ++ close(to[1]); ++ /* restore */ ++ signal(SIGPIPE, oldsigpipe); ++} ++ + void + strdump(void) + { +diff --git a/st.h b/st.h +index 3d351b6..392b64e 100644 +--- a/st.h ++++ b/st.h +@@ -81,6 +81,7 @@ void die(const char *, ...); + void redraw(void); + void draw(void); + ++void externalpipe(const Arg *); + void printscreen(const Arg *); + void printsel(const Arg *); + void sendbreak(const Arg *); -- cgit v1.2.3