commit 0fe2471420df3fb81eac8ffde2711a5676a5d5d1
parent fa253f077f19b3220c7655b81bd91e52f4367803
Author: q <qwolkensperg@gmail.com>
Date: Fri, 26 Jun 2020 22:01:36 -0400
hell yeah
Diffstat:
14 files changed, 1116 insertions(+), 12 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -93,6 +93,9 @@ char *termname = "st-256color";
*/
unsigned int tabspaces = 8;
+/* bg opacity */
+float alpha = 0.8;
+
/* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = {
/* 8 normal colors */
@@ -120,6 +123,7 @@ static const char *colorname[] = {
/* more colors can be added after 255 to use with DefaultXX */
"#cccccc",
"#555555",
+ "black",
};
@@ -128,7 +132,7 @@ static const char *colorname[] = {
* foreground, background, cursor, reverse cursor
*/
unsigned int defaultfg = 7;
-unsigned int defaultbg = 0;
+unsigned int defaultbg = 258;
static unsigned int defaultcs = 256;
static unsigned int defaultrcs = 257;
diff --git a/config.def.h b/config.def.h.orig
diff --git a/config.mk b/config.mk
@@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
INCS = -I$(X11INC) \
`$(PKG_CONFIG) --cflags fontconfig` \
`$(PKG_CONFIG) --cflags freetype2`
-LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
+LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
`$(PKG_CONFIG) --libs fontconfig` \
`$(PKG_CONFIG) --libs freetype2`
diff --git a/st-alpha-0.8.2.diff b/st-alpha-0.8.2.diff
@@ -0,0 +1,163 @@
+diff --git a/config.def.h b/config.def.h
+index 0e01717..e116631 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -82,6 +82,9 @@ char *termname = "st-256color";
+ */
+ unsigned int tabspaces = 8;
+
++/* bg opacity */
++float alpha = 0.8;
++
+ /* Terminal colors (16 first used in escape sequence) */
+ static const char *colorname[] = {
+ /* 8 normal colors */
+@@ -109,6 +112,7 @@ static const char *colorname[] = {
+ /* more colors can be added after 255 to use with DefaultXX */
+ "#cccccc",
+ "#555555",
++ "black",
+ };
+
+
+@@ -117,7 +121,7 @@ static const char *colorname[] = {
+ * foreground, background, cursor, reverse cursor
+ */
+ unsigned int defaultfg = 7;
+-unsigned int defaultbg = 0;
++unsigned int defaultbg = 258;
+ static unsigned int defaultcs = 256;
+ static unsigned int defaultrcs = 257;
+
+diff --git a/config.mk b/config.mk
+index 0cbb002..1d2f0e2 100644
+--- a/config.mk
++++ b/config.mk
+@@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
+ INCS = -I$(X11INC) \
+ `$(PKG_CONFIG) --cflags fontconfig` \
+ `$(PKG_CONFIG) --cflags freetype2`
+-LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
++LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
+ `$(PKG_CONFIG) --libs fontconfig` \
+ `$(PKG_CONFIG) --libs freetype2`
+
+diff --git a/st.h b/st.h
+index 38c61c4..b7634ab 100644
+--- a/st.h
++++ b/st.h
+@@ -120,3 +120,4 @@ extern char *termname;
+ extern unsigned int tabspaces;
+ extern unsigned int defaultfg;
+ extern unsigned int defaultbg;
++extern float alpha;
+diff --git a/x.c b/x.c
+index 0422421..588dec3 100644
+--- a/x.c
++++ b/x.c
+@@ -98,6 +98,7 @@ typedef struct {
+ XSetWindowAttributes attrs;
+ int scr;
+ int isfixed; /* is fixed geometry? */
++ int depth; /* bit depth */
+ int l, t; /* left and top offset */
+ int gm; /* geometry mask */
+ } XWindow;
+@@ -229,6 +230,7 @@ static char *usedfont = NULL;
+ static double usedfontsize = 0;
+ static double defaultfontsize = 0;
+
++static char *opt_alpha = NULL;
+ static char *opt_class = NULL;
+ static char **opt_cmd = NULL;
+ static char *opt_embed = NULL;
+@@ -688,7 +690,7 @@ xresize(int col, int row)
+
+ XFreePixmap(xw.dpy, xw.buf);
+ xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
+- DefaultDepth(xw.dpy, xw.scr));
++ xw.depth);
+ XftDrawChange(xw.draw, xw.buf);
+ xclear(0, 0, win.w, win.h);
+
+@@ -748,6 +750,13 @@ xloadcols(void)
+ else
+ die("could not allocate color %d\n", i);
+ }
++
++ /* set alpha value of bg color */
++ if (opt_alpha)
++ alpha = strtof(opt_alpha, NULL);
++ dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
++ dc.col[defaultbg].pixel &= 0x00FFFFFF;
++ dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
+ loaded = 1;
+ }
+
+@@ -1004,11 +1013,23 @@ xinit(int cols, int rows)
+ Window parent;
+ pid_t thispid = getpid();
+ XColor xmousefg, xmousebg;
++ XWindowAttributes attr;
++ XVisualInfo vis;
+
+ if (!(xw.dpy = XOpenDisplay(NULL)))
+ die("can't open display\n");
+ xw.scr = XDefaultScreen(xw.dpy);
+- xw.vis = XDefaultVisual(xw.dpy, xw.scr);
++
++ if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
++ parent = XRootWindow(xw.dpy, xw.scr);
++ xw.depth = 32;
++ } else {
++ XGetWindowAttributes(xw.dpy, parent, &attr);
++ xw.depth = attr.depth;
++ }
++
++ XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
++ xw.vis = vis.visual;
+
+ /* font */
+ if (!FcInit())
+@@ -1018,7 +1039,7 @@ xinit(int cols, int rows)
+ xloadfonts(usedfont, 0);
+
+ /* colors */
+- xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
++ xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
+ xloadcols();
+
+ /* adjust fixed window geometry */
+@@ -1038,19 +1059,15 @@ xinit(int cols, int rows)
+ | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
+ xw.attrs.colormap = xw.cmap;
+
+- if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
+- parent = XRootWindow(xw.dpy, xw.scr);
+ xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
+- win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
++ win.w, win.h, 0, xw.depth, InputOutput,
+ xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
+ | CWEventMask | CWColormap, &xw.attrs);
+
+ memset(&gcvalues, 0, sizeof(gcvalues));
+ gcvalues.graphics_exposures = False;
+- dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
+- &gcvalues);
+- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
+- DefaultDepth(xw.dpy, xw.scr));
++ xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
++ dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
+ XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
+ XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
+
+@@ -1894,6 +1911,9 @@ main(int argc, char *argv[])
+ case 'a':
+ allowaltscreen = 0;
+ break;
++ case 'A':
++ opt_alpha = EARGF(usage());
++ break;
+ case 'c':
+ opt_class = EARGF(usage());
+ break;
diff --git a/st-blinking_cursor-20200531-a2a7044.diff b/st-blinking_cursor-20200531-a2a7044.diff
@@ -0,0 +1,150 @@
+From bff176133618854676bbdc74c0099f184d3da365 Mon Sep 17 00:00:00 2001
+From: Steve Ward <planet36@gmail.com>
+Date: Sun, 31 May 2020 22:48:25 -0400
+Subject: [PATCH] Allow blinking cursor
+
+---
+ config.def.h | 19 +++++++++++++------
+ x.c | 42 ++++++++++++++++++++++++++++++++----------
+ 2 files changed, 45 insertions(+), 16 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 6f05dce..3dbe915 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -133,13 +133,20 @@ static unsigned int defaultcs = 256;
+ static unsigned int defaultrcs = 257;
+
+ /*
+- * Default shape of cursor
+- * 2: Block ("█")
+- * 4: Underline ("_")
+- * 6: Bar ("|")
+- * 7: Snowman ("☃")
++ * https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81
++ * Default style of cursor
++ * 0: Blinking block
++ * 1: Blinking block (default)
++ * 2: Steady block ("█")
++ * 3: Blinking underline
++ * 4: Steady underline ("_")
++ * 5: Blinking bar
++ * 6: Steady bar ("|")
++ * 7: Blinking st cursor
++ * 8: Steady st cursor
+ */
+-static unsigned int cursorshape = 2;
++static unsigned int cursorstyle = 1;
++static Rune stcursor = 0x2603; /* snowman (U+2603) */
+
+ /*
+ * Default columns and rows numbers
+diff --git a/x.c b/x.c
+index 210f184..bd80a5e 100644
+--- a/x.c
++++ b/x.c
+@@ -253,6 +253,7 @@ static char *opt_name = NULL;
+ static char *opt_title = NULL;
+
+ static int oldbutton = 3; /* button event on startup: 3 = release */
++static int cursorblinks = 0;
+
+ void
+ clipcopy(const Arg *dummy)
+@@ -1526,16 +1527,19 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
+ /* draw the new one */
+ if (IS_SET(MODE_FOCUSED)) {
+ switch (win.cursor) {
+- case 7: /* st extension */
+- g.u = 0x2603; /* snowman (U+2603) */
++ case 0: /* Blinking block */
++ case 1: /* Blinking block (default) */
++ if (IS_SET(MODE_BLINK))
++ break;
+ /* FALLTHROUGH */
+- case 0: /* Blinking Block */
+- case 1: /* Blinking Block (Default) */
+- case 2: /* Steady Block */
++ case 2: /* Steady block */
+ xdrawglyph(g, cx, cy);
+ break;
+- case 3: /* Blinking Underline */
+- case 4: /* Steady Underline */
++ case 3: /* Blinking underline */
++ if (IS_SET(MODE_BLINK))
++ break;
++ /* FALLTHROUGH */
++ case 4: /* Steady underline */
+ XftDrawRect(xw.draw, &drawcol,
+ borderpx + cx * win.cw,
+ borderpx + (cy + 1) * win.ch - \
+@@ -1543,12 +1547,23 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
+ win.cw, cursorthickness);
+ break;
+ case 5: /* Blinking bar */
++ if (IS_SET(MODE_BLINK))
++ break;
++ /* FALLTHROUGH */
+ case 6: /* Steady bar */
+ XftDrawRect(xw.draw, &drawcol,
+ borderpx + cx * win.cw,
+ borderpx + cy * win.ch,
+ cursorthickness, win.ch);
+ break;
++ case 7: /* Blinking st cursor */
++ if (IS_SET(MODE_BLINK))
++ break;
++ /* FALLTHROUGH */
++ case 8: /* Steady st cursor */
++ g.u = stcursor;
++ xdrawglyph(g, cx, cy);
++ break;
+ }
+ } else {
+ XftDrawRect(xw.draw, &drawcol,
+@@ -1690,9 +1705,12 @@ xsetmode(int set, unsigned int flags)
+ int
+ xsetcursor(int cursor)
+ {
+- if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */
++ if (!BETWEEN(cursor, 0, 8)) /* 7-8: st extensions */
+ return 1;
+ win.cursor = cursor;
++ cursorblinks = win.cursor == 0 || win.cursor == 1 ||
++ win.cursor == 3 || win.cursor == 5 ||
++ win.cursor == 7;
+ return 0;
+ }
+
+@@ -1936,6 +1954,10 @@ run(void)
+ if (FD_ISSET(ttyfd, &rfd) || xev) {
+ if (!drawing) {
+ trigger = now;
++ if (IS_SET(MODE_BLINK)) {
++ win.mode ^= MODE_BLINK;
++ }
++ lastblink = now;
+ drawing = 1;
+ }
+ timeout = (maxlatency - TIMEDIFF(now, trigger)) \
+@@ -1946,7 +1968,7 @@ run(void)
+
+ /* idle detected or maxlatency exhausted -> draw */
+ timeout = -1;
+- if (blinktimeout && tattrset(ATTR_BLINK)) {
++ if (blinktimeout && (cursorblinks || tattrset(ATTR_BLINK))) {
+ timeout = blinktimeout - TIMEDIFF(now, lastblink);
+ if (timeout <= 0) {
+ if (-timeout > blinktimeout) /* start visible */
+@@ -1982,7 +2004,7 @@ main(int argc, char *argv[])
+ {
+ xw.l = xw.t = 0;
+ xw.isfixed = False;
+- xsetcursor(cursorshape);
++ xsetcursor(cursorstyle);
+
+ ARGBEGIN {
+ case 'a':
+--
+2.20.1
+
diff --git a/st-font2-20190416-ba72400.diff b/st-font2-20190416-ba72400.diff
@@ -0,0 +1,167 @@
+From ba724004c6a368e452114f7dc147a9978fe0f3b4 Mon Sep 17 00:00:00 2001
+From: Kirill Bugaev <kirill.bugaev87@gmail.com>
+Date: Tue, 16 Apr 2019 04:31:30 +0800
+Subject: [PATCH] This patch allows to add spare font besides default. Some
+ glyphs can be not present in default font. For this glyphs st uses
+ font-config and try to find them in font cache first. This patch append fonts
+ defined in font2 variable to the beginning of font cache. So they will be
+ used first for glyphs that absent in default font.
+
+---
+ config.def.h | 6 +++
+ x.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 107 insertions(+)
+
+diff --git a/config.def.h b/config.def.h
+index 482901e..676719e 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -6,6 +6,12 @@
+ * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
+ */
+ static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
++/* Spare fonts */
++static char *font2[] = {
++/* "Inconsolata for Powerline:pixelsize=12:antialias=true:autohint=true", */
++/* "Hack Nerd Font Mono:pixelsize=11:antialias=true:autohint=true", */
++};
++
+ static int borderpx = 2;
+
+ /*
+diff --git a/x.c b/x.c
+index 5828a3b..d37e59d 100644
+--- a/x.c
++++ b/x.c
+@@ -149,6 +149,8 @@ static void xhints(void);
+ static int xloadcolor(int, const char *, Color *);
+ static int xloadfont(Font *, FcPattern *);
+ static void xloadfonts(char *, double);
++static int xloadsparefont(FcPattern *, int);
++static void xloadsparefonts(void);
+ static void xunloadfont(Font *);
+ static void xunloadfonts(void);
+ static void xsetenv(void);
+@@ -296,6 +298,7 @@ zoomabs(const Arg *arg)
+ {
+ xunloadfonts();
+ xloadfonts(usedfont, arg->f);
++ xloadsparefonts();
+ cresize(0, 0);
+ redraw();
+ xhints();
+@@ -977,6 +980,101 @@ xloadfonts(char *fontstr, double fontsize)
+ FcPatternDestroy(pattern);
+ }
+
++int
++xloadsparefont(FcPattern *pattern, int flags)
++{
++ FcPattern *match;
++ FcResult result;
++
++ match = FcFontMatch(NULL, pattern, &result);
++ if (!match) {
++ return 1;
++ }
++
++ if (!(frc[frclen].font = XftFontOpenPattern(xw.dpy, match))) {
++ FcPatternDestroy(match);
++ return 1;
++ }
++
++ frc[frclen].flags = flags;
++ /* Believe U+0000 glyph will present in each default font */
++ frc[frclen].unicodep = 0;
++ frclen++;
++
++ return 0;
++}
++
++void
++xloadsparefonts(void)
++{
++ FcPattern *pattern;
++ double sizeshift, fontval;
++ int fc;
++ char **fp;
++
++ if (frclen != 0)
++ die("can't embed spare fonts. cache isn't empty");
++
++ /* Calculate count of spare fonts */
++ fc = sizeof(font2) / sizeof(*font2);
++ if (fc == 0)
++ return;
++
++ /* Allocate memory for cache entries. */
++ if (frccap < 4 * fc) {
++ frccap += 4 * fc - frccap;
++ frc = xrealloc(frc, frccap * sizeof(Fontcache));
++ }
++
++ for (fp = font2; fp - font2 < fc; ++fp) {
++
++ if (**fp == '-')
++ pattern = XftXlfdParse(*fp, False, False);
++ else
++ pattern = FcNameParse((FcChar8 *)*fp);
++
++ if (!pattern)
++ die("can't open spare font %s\n", *fp);
++
++ if (defaultfontsize > 0) {
++ sizeshift = usedfontsize - defaultfontsize;
++ if (sizeshift != 0 &&
++ FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
++ FcResultMatch) {
++ fontval += sizeshift;
++ FcPatternDel(pattern, FC_PIXEL_SIZE);
++ FcPatternDel(pattern, FC_SIZE);
++ FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontval);
++ }
++ }
++
++ FcPatternAddBool(pattern, FC_SCALABLE, 1);
++
++ FcConfigSubstitute(NULL, pattern, FcMatchPattern);
++ XftDefaultSubstitute(xw.dpy, xw.scr, pattern);
++
++ if (xloadsparefont(pattern, FRC_NORMAL))
++ die("can't open spare font %s\n", *fp);
++
++ FcPatternDel(pattern, FC_SLANT);
++ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
++ if (xloadsparefont(pattern, FRC_ITALIC))
++ die("can't open spare font %s\n", *fp);
++
++ FcPatternDel(pattern, FC_WEIGHT);
++ FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
++ if (xloadsparefont(pattern, FRC_ITALICBOLD))
++ die("can't open spare font %s\n", *fp);
++
++ FcPatternDel(pattern, FC_SLANT);
++ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
++ if (xloadsparefont(pattern, FRC_BOLD))
++ die("can't open spare font %s\n", *fp);
++
++ FcPatternDestroy(pattern);
++ }
++}
++
+ void
+ xunloadfont(Font *f)
+ {
+@@ -1057,6 +1155,9 @@ xinit(int cols, int rows)
+ usedfont = (opt_font == NULL)? font : opt_font;
+ xloadfonts(usedfont, 0);
+
++ /* spare fonts */
++ xloadsparefonts();
++
+ /* colors */
+ xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
+ xloadcols();
+--
+2.21.0
+
diff --git a/st-scrollback-20200419-72e3f6c.diff b/st-scrollback-20200419-72e3f6c.diff
@@ -0,0 +1,351 @@
+diff --git a/config.def.h b/config.def.h
+index 0895a1f..eef24df 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -188,6 +188,8 @@ static Shortcut shortcuts[] = {
+ { TERMMOD, XK_Y, selpaste, {.i = 0} },
+ { ShiftMask, XK_Insert, selpaste, {.i = 0} },
+ { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
++ { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
++ { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
+ };
+
+ /*
+diff --git a/st.c b/st.c
+index 0ce6ac2..641edc0 100644
+--- a/st.c
++++ b/st.c
+@@ -35,6 +35,7 @@
+ #define ESC_ARG_SIZ 16
+ #define STR_BUF_SIZ ESC_BUF_SIZ
+ #define STR_ARG_SIZ ESC_ARG_SIZ
++#define HISTSIZE 2000
+
+ /* macros */
+ #define IS_SET(flag) ((term.mode & (flag)) != 0)
+@@ -42,6 +43,9 @@
+ #define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
+ #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
+ #define ISDELIM(u) (u && wcschr(worddelimiters, u))
++#define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - \
++ term.scr + HISTSIZE + 1) % HISTSIZE] : \
++ term.line[(y) - term.scr])
+
+ enum term_mode {
+ MODE_WRAP = 1 << 0,
+@@ -117,6 +121,9 @@ typedef struct {
+ int col; /* nb col */
+ Line *line; /* screen */
+ Line *alt; /* alternate screen */
++ Line hist[HISTSIZE]; /* history buffer */
++ int histi; /* history index */
++ int scr; /* scroll back */
+ int *dirty; /* dirtyness of lines */
+ TCursor c; /* cursor */
+ int ocx; /* old cursor col */
+@@ -185,8 +192,8 @@ static void tnewline(int);
+ static void tputtab(int);
+ static void tputc(Rune);
+ static void treset(void);
+-static void tscrollup(int, int);
+-static void tscrolldown(int, int);
++static void tscrollup(int, int, int);
++static void tscrolldown(int, int, int);
+ static void tsetattr(int *, int);
+ static void tsetchar(Rune, Glyph *, int, int);
+ static void tsetdirt(int, int);
+@@ -415,10 +422,10 @@ tlinelen(int y)
+ {
+ int i = term.col;
+
+- if (term.line[y][i - 1].mode & ATTR_WRAP)
++ if (TLINE(y)[i - 1].mode & ATTR_WRAP)
+ return i;
+
+- while (i > 0 && term.line[y][i - 1].u == ' ')
++ while (i > 0 && TLINE(y)[i - 1].u == ' ')
+ --i;
+
+ return i;
+@@ -527,7 +534,7 @@ selsnap(int *x, int *y, int direction)
+ * Snap around if the word wraps around at the end or
+ * beginning of a line.
+ */
+- prevgp = &term.line[*y][*x];
++ prevgp = &TLINE(*y)[*x];
+ prevdelim = ISDELIM(prevgp->u);
+ for (;;) {
+ newx = *x + direction;
+@@ -542,14 +549,14 @@ selsnap(int *x, int *y, int direction)
+ yt = *y, xt = *x;
+ else
+ yt = newy, xt = newx;
+- if (!(term.line[yt][xt].mode & ATTR_WRAP))
++ if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
+ break;
+ }
+
+ if (newx >= tlinelen(newy))
+ break;
+
+- gp = &term.line[newy][newx];
++ gp = &TLINE(newy)[newx];
+ delim = ISDELIM(gp->u);
+ if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
+ || (delim && gp->u != prevgp->u)))
+@@ -570,14 +577,14 @@ selsnap(int *x, int *y, int direction)
+ *x = (direction < 0) ? 0 : term.col - 1;
+ if (direction < 0) {
+ for (; *y > 0; *y += direction) {
+- if (!(term.line[*y-1][term.col-1].mode
++ if (!(TLINE(*y-1)[term.col-1].mode
+ & ATTR_WRAP)) {
+ break;
+ }
+ }
+ } else if (direction > 0) {
+ for (; *y < term.row-1; *y += direction) {
+- if (!(term.line[*y][term.col-1].mode
++ if (!(TLINE(*y)[term.col-1].mode
+ & ATTR_WRAP)) {
+ break;
+ }
+@@ -608,13 +615,13 @@ getsel(void)
+ }
+
+ if (sel.type == SEL_RECTANGULAR) {
+- gp = &term.line[y][sel.nb.x];
++ gp = &TLINE(y)[sel.nb.x];
+ lastx = sel.ne.x;
+ } else {
+- gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
++ gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0];
+ lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
+ }
+- last = &term.line[y][MIN(lastx, linelen-1)];
++ last = &TLINE(y)[MIN(lastx, linelen-1)];
+ while (last >= gp && last->u == ' ')
+ --last;
+
+@@ -849,6 +856,9 @@ void
+ ttywrite(const char *s, size_t n, int may_echo)
+ {
+ const char *next;
++ Arg arg = (Arg) { .i = term.scr };
++
++ kscrolldown(&arg);
+
+ if (may_echo && IS_SET(MODE_ECHO))
+ twrite(s, n, 1);
+@@ -1060,13 +1070,53 @@ tswapscreen(void)
+ }
+
+ void
+-tscrolldown(int orig, int n)
++kscrolldown(const Arg* a)
++{
++ int n = a->i;
++
++ if (n < 0)
++ n = term.row + n;
++
++ if (n > term.scr)
++ n = term.scr;
++
++ if (term.scr > 0) {
++ term.scr -= n;
++ selscroll(0, -n);
++ tfulldirt();
++ }
++}
++
++void
++kscrollup(const Arg* a)
++{
++ int n = a->i;
++
++ if (n < 0)
++ n = term.row + n;
++
++ if (term.scr <= HISTSIZE-n) {
++ term.scr += n;
++ selscroll(0, n);
++ tfulldirt();
++ }
++}
++
++void
++tscrolldown(int orig, int n, int copyhist)
+ {
+ int i;
+ Line temp;
+
+ LIMIT(n, 0, term.bot-orig+1);
+
++ if (copyhist) {
++ term.histi = (term.histi - 1 + HISTSIZE) % HISTSIZE;
++ temp = term.hist[term.histi];
++ term.hist[term.histi] = term.line[term.bot];
++ term.line[term.bot] = temp;
++ }
++
+ tsetdirt(orig, term.bot-n);
+ tclearregion(0, term.bot-n+1, term.col-1, term.bot);
+
+@@ -1076,17 +1126,28 @@ tscrolldown(int orig, int n)
+ term.line[i-n] = temp;
+ }
+
+- selscroll(orig, n);
++ if (term.scr == 0)
++ selscroll(orig, n);
+ }
+
+ void
+-tscrollup(int orig, int n)
++tscrollup(int orig, int n, int copyhist)
+ {
+ int i;
+ Line temp;
+
+ LIMIT(n, 0, term.bot-orig+1);
+
++ if (copyhist) {
++ term.histi = (term.histi + 1) % HISTSIZE;
++ temp = term.hist[term.histi];
++ term.hist[term.histi] = term.line[orig];
++ term.line[orig] = temp;
++ }
++
++ if (term.scr > 0 && term.scr < HISTSIZE)
++ term.scr = MIN(term.scr + n, HISTSIZE-1);
++
+ tclearregion(0, orig, term.col-1, orig+n-1);
+ tsetdirt(orig+n, term.bot);
+
+@@ -1096,7 +1157,8 @@ tscrollup(int orig, int n)
+ term.line[i+n] = temp;
+ }
+
+- selscroll(orig, -n);
++ if (term.scr == 0)
++ selscroll(orig, -n);
+ }
+
+ void
+@@ -1135,7 +1197,7 @@ tnewline(int first_col)
+ int y = term.c.y;
+
+ if (y == term.bot) {
+- tscrollup(term.top, 1);
++ tscrollup(term.top, 1, 1);
+ } else {
+ y++;
+ }
+@@ -1300,14 +1362,14 @@ void
+ tinsertblankline(int n)
+ {
+ if (BETWEEN(term.c.y, term.top, term.bot))
+- tscrolldown(term.c.y, n);
++ tscrolldown(term.c.y, n, 0);
+ }
+
+ void
+ tdeleteline(int n)
+ {
+ if (BETWEEN(term.c.y, term.top, term.bot))
+- tscrollup(term.c.y, n);
++ tscrollup(term.c.y, n, 0);
+ }
+
+ int32_t
+@@ -1738,11 +1800,11 @@ csihandle(void)
+ break;
+ case 'S': /* SU -- Scroll <n> line up */
+ DEFAULT(csiescseq.arg[0], 1);
+- tscrollup(term.top, csiescseq.arg[0]);
++ tscrollup(term.top, csiescseq.arg[0], 0);
+ break;
+ case 'T': /* SD -- Scroll <n> line down */
+ DEFAULT(csiescseq.arg[0], 1);
+- tscrolldown(term.top, csiescseq.arg[0]);
++ tscrolldown(term.top, csiescseq.arg[0], 0);
+ break;
+ case 'L': /* IL -- Insert <n> blank lines */
+ DEFAULT(csiescseq.arg[0], 1);
+@@ -2248,7 +2310,7 @@ eschandle(uchar ascii)
+ return 0;
+ case 'D': /* IND -- Linefeed */
+ if (term.c.y == term.bot) {
+- tscrollup(term.top, 1);
++ tscrollup(term.top, 1, 1);
+ } else {
+ tmoveto(term.c.x, term.c.y+1);
+ }
+@@ -2261,7 +2323,7 @@ eschandle(uchar ascii)
+ break;
+ case 'M': /* RI -- Reverse index */
+ if (term.c.y == term.top) {
+- tscrolldown(term.top, 1);
++ tscrolldown(term.top, 1, 1);
+ } else {
+ tmoveto(term.c.x, term.c.y-1);
+ }
+@@ -2482,7 +2544,7 @@ twrite(const char *buf, int buflen, int show_ctrl)
+ void
+ tresize(int col, int row)
+ {
+- int i;
++ int i, j;
+ int minrow = MIN(row, term.row);
+ int mincol = MIN(col, term.col);
+ int *bp;
+@@ -2519,6 +2581,14 @@ tresize(int col, int row)
+ term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
+ term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
+
++ for (i = 0; i < HISTSIZE; i++) {
++ term.hist[i] = xrealloc(term.hist[i], col * sizeof(Glyph));
++ for (j = mincol; j < col; j++) {
++ term.hist[i][j] = term.c.attr;
++ term.hist[i][j].u = ' ';
++ }
++ }
++
+ /* resize each row to new width, zero-pad if needed */
+ for (i = 0; i < minrow; i++) {
+ term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
+@@ -2577,7 +2647,7 @@ drawregion(int x1, int y1, int x2, int y2)
+ continue;
+
+ term.dirty[y] = 0;
+- xdrawline(term.line[y], x1, y, x2);
++ xdrawline(TLINE(y), x1, y, x2);
+ }
+ }
+
+@@ -2598,8 +2668,9 @@ draw(void)
+ cx--;
+
+ drawregion(0, 0, term.col, term.row);
+- xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
+- term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
++ 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 = cx;
+ term.ocy = term.c.y;
+ xfinishdraw();
+diff --git a/st.h b/st.h
+index d978458..b9a4eeb 100644
+--- a/st.h
++++ b/st.h
+@@ -81,6 +81,8 @@ void die(const char *, ...);
+ void redraw(void);
+ void draw(void);
+
++void kscrolldown(const Arg *);
++void kscrollup(const Arg *);
+ void printscreen(const Arg *);
+ void printsel(const Arg *);
+ void sendbreak(const Arg *);
diff --git a/st-scrollback-mouse-20191024-a2c479c.diff b/st-scrollback-mouse-20191024-a2c479c.diff
@@ -0,0 +1,13 @@
+diff --git a/config.def.h b/config.def.h
+index ec1b576..4b3bf15 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -163,6 +163,8 @@ static uint forcemousemod = ShiftMask;
+ */
+ static MouseShortcut mshortcuts[] = {
+ /* mask button function argument release */
++ { ShiftMask, Button4, kscrollup, {.i = 1} },
++ { ShiftMask, Button5, kscrolldown, {.i = 1} },
+ { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
+ { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
+ { XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
diff --git a/st-vertcenter-20180320-6ac8c8a.diff b/st-vertcenter-20180320-6ac8c8a.diff
@@ -0,0 +1,51 @@
+--- a/x.c Tue Mar 20 00:28:57 2018
++++ b/x.c Tue Mar 20 00:29:02 2018
+@@ -80,6 +80,7 @@
+ int w, h; /* window width and height */
+ int ch; /* char height */
+ int cw; /* char width */
++ int cyo; /* char y offset */
+ int mode; /* window state/mode flags */
+ int cursor; /* cursor style */
+ } TermWindow;
+@@ -949,6 +950,7 @@
+ /* Setting character width and height. */
+ win.cw = ceilf(dc.font.width * cwscale);
+ win.ch = ceilf(dc.font.height * chscale);
++ win.cyo = ceilf(dc.font.height * (chscale - 1) / 2);
+
+ FcPatternDel(pattern, FC_SLANT);
+ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
+@@ -1130,7 +1132,7 @@
+ FcCharSet *fccharset;
+ int i, f, numspecs = 0;
+
+- for (i = 0, xp = winx, yp = winy + font->ascent; i < len; ++i) {
++ for (i = 0, xp = winx, yp = winy + font->ascent + win.cyo; i < len; ++i) {
+ /* Fetch rune and mode for current glyph. */
+ rune = glyphs[i].u;
+ mode = glyphs[i].mode;
+@@ -1155,7 +1157,7 @@
+ font = &dc.bfont;
+ frcflags = FRC_BOLD;
+ }
+- yp = winy + font->ascent;
++ yp = winy + font->ascent + win.cyo;
+ }
+
+ /* Lookup character index with default font. */
+@@ -1371,12 +1373,12 @@
+
+ /* Render underline and strikethrough. */
+ if (base.mode & ATTR_UNDERLINE) {
+- XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
++ 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 + 2 * dc.font.ascent / 3,
++ XftDrawRect(xw.draw, fg, winx, winy + win.cyo + 2 * dc.font.ascent / 3,
+ width, 1);
+ }
+
diff --git a/st-xresources-20200604-9ba7ecf.diff b/st-xresources-20200604-9ba7ecf.diff
@@ -0,0 +1,184 @@
+From 2752a599ee01305a435729bfacf43b1dde7cf0ef Mon Sep 17 00:00:00 2001
+From: Benji Encalada Mora <benji@encalada.dev>
+Date: Thu, 4 Jun 2020 00:41:10 -0500
+Subject: [PATCH] fix: replace xfps and actionfps variables
+
+---
+ config.def.h | 36 ++++++++++++++++++++++++
+ x.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++---
+ 2 files changed, 110 insertions(+), 4 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 6f05dce..9b99782 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -168,6 +168,42 @@ static unsigned int defaultattr = 11;
+ */
+ static uint forcemousemod = ShiftMask;
+
++/*
++ * Xresources preferences to load at startup
++ */
++ResourcePref resources[] = {
++ { "font", STRING, &font },
++ { "color0", STRING, &colorname[0] },
++ { "color1", STRING, &colorname[1] },
++ { "color2", STRING, &colorname[2] },
++ { "color3", STRING, &colorname[3] },
++ { "color4", STRING, &colorname[4] },
++ { "color5", STRING, &colorname[5] },
++ { "color6", STRING, &colorname[6] },
++ { "color7", STRING, &colorname[7] },
++ { "color8", STRING, &colorname[8] },
++ { "color9", STRING, &colorname[9] },
++ { "color10", STRING, &colorname[10] },
++ { "color11", STRING, &colorname[11] },
++ { "color12", STRING, &colorname[12] },
++ { "color13", STRING, &colorname[13] },
++ { "color14", STRING, &colorname[14] },
++ { "color15", STRING, &colorname[15] },
++ { "background", STRING, &colorname[256] },
++ { "foreground", STRING, &colorname[257] },
++ { "cursorColor", STRING, &colorname[258] },
++ { "termname", STRING, &termname },
++ { "shell", STRING, &shell },
++ { "minlatency", INTEGER, &minlatency },
++ { "maxlatency", INTEGER, &maxlatency },
++ { "blinktimeout", INTEGER, &blinktimeout },
++ { "bellvolume", INTEGER, &bellvolume },
++ { "tabspaces", INTEGER, &tabspaces },
++ { "borderpx", INTEGER, &borderpx },
++ { "cwscale", FLOAT, &cwscale },
++ { "chscale", FLOAT, &chscale },
++};
++
+ /*
+ * Internal mouse shortcuts.
+ * Beware that overloading Button1 will disable the selection.
+diff --git a/x.c b/x.c
+index 210f184..76f167f 100644
+--- a/x.c
++++ b/x.c
+@@ -14,6 +14,7 @@
+ #include <X11/keysym.h>
+ #include <X11/Xft/Xft.h>
+ #include <X11/XKBlib.h>
++#include <X11/Xresource.h>
+
+ char *argv0;
+ #include "arg.h"
+@@ -45,6 +46,19 @@ typedef struct {
+ signed char appcursor; /* application cursor */
+ } Key;
+
++/* Xresources preferences */
++enum resource_type {
++ STRING = 0,
++ INTEGER = 1,
++ FLOAT = 2
++};
++
++typedef struct {
++ char *name;
++ enum resource_type type;
++ void *dst;
++} ResourcePref;
++
+ /* X modifiers */
+ #define XK_ANY_MOD UINT_MAX
+ #define XK_NO_MOD 0
+@@ -828,8 +842,8 @@ xclear(int x1, int y1, int x2, int y2)
+ void
+ xhints(void)
+ {
+- XClassHint class = {opt_name ? opt_name : termname,
+- opt_class ? opt_class : termname};
++ XClassHint class = {opt_name ? opt_name : "st",
++ opt_class ? opt_class : "St"};
+ XWMHints wm = {.flags = InputHint, .input = 1};
+ XSizeHints *sizeh;
+
+@@ -1104,8 +1118,6 @@ xinit(int cols, int rows)
+ pid_t thispid = getpid();
+ XColor xmousefg, xmousebg;
+
+- if (!(xw.dpy = XOpenDisplay(NULL)))
+- die("can't open display\n");
+ xw.scr = XDefaultScreen(xw.dpy);
+ xw.vis = XDefaultVisual(xw.dpy, xw.scr);
+
+@@ -1964,6 +1976,59 @@ run(void)
+ }
+ }
+
++int
++resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
++{
++ char **sdst = dst;
++ int *idst = dst;
++ float *fdst = dst;
++
++ char fullname[256];
++ char fullclass[256];
++ char *type;
++ XrmValue ret;
++
++ snprintf(fullname, sizeof(fullname), "%s.%s",
++ opt_name ? opt_name : "st", name);
++ snprintf(fullclass, sizeof(fullclass), "%s.%s",
++ opt_class ? opt_class : "St", name);
++ fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
++
++ XrmGetResource(db, fullname, fullclass, &type, &ret);
++ if (ret.addr == NULL || strncmp("String", type, 64))
++ return 1;
++
++ switch (rtype) {
++ case STRING:
++ *sdst = ret.addr;
++ break;
++ case INTEGER:
++ *idst = strtoul(ret.addr, NULL, 10);
++ break;
++ case FLOAT:
++ *fdst = strtof(ret.addr, NULL);
++ break;
++ }
++ return 0;
++}
++
++void
++config_init(void)
++{
++ char *resm;
++ XrmDatabase db;
++ ResourcePref *p;
++
++ XrmInitialize();
++ resm = XResourceManagerString(xw.dpy);
++ if (!resm)
++ return;
++
++ db = XrmGetStringDatabase(resm);
++ for (p = resources; p < resources + LEN(resources); p++)
++ resource_load(db, p->name, p->type, p->dst);
++}
++
+ void
+ usage(void)
+ {
+@@ -2037,6 +2102,11 @@ run:
+
+ setlocale(LC_CTYPE, "");
+ XSetLocaleModifiers("");
++
++ if(!(xw.dpy = XOpenDisplay(NULL)))
++ die("Can't open display\n");
++
++ config_init();
+ cols = MAX(cols, 1);
+ rows = MAX(rows, 1);
+ tnew(cols, rows);
+--
+2.26.2
+
diff --git a/st.h b/st.h
@@ -123,3 +123,4 @@ extern char *termname;
extern unsigned int tabspaces;
extern unsigned int defaultfg;
extern unsigned int defaultbg;
+extern float alpha;
diff --git a/st.h b/st.h.orig
diff --git a/x.c b/x.c
@@ -105,6 +105,7 @@ typedef struct {
XSetWindowAttributes attrs;
int scr;
int isfixed; /* is fixed geometry? */
+ int depth; /* bit depth */
int l, t; /* left and top offset */
int gm; /* geometry mask */
} XWindow;
@@ -243,6 +244,7 @@ static char *usedfont = NULL;
static double usedfontsize = 0;
static double defaultfontsize = 0;
+static char *opt_alpha = NULL;
static char *opt_class = NULL;
static char **opt_cmd = NULL;
static char *opt_embed = NULL;
@@ -734,7 +736,7 @@ xresize(int col, int row)
XFreePixmap(xw.dpy, xw.buf);
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
- DefaultDepth(xw.dpy, xw.scr));
+ xw.depth);
XftDrawChange(xw.draw, xw.buf);
xclear(0, 0, win.w, win.h);
@@ -794,6 +796,13 @@ xloadcols(void)
else
die("could not allocate color %d\n", i);
}
+
+ /* set alpha value of bg color */
+ if (opt_alpha)
+ alpha = strtof(opt_alpha, NULL);
+ dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
+ dc.col[defaultbg].pixel &= 0x00FFFFFF;
+ dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
loaded = 1;
}
@@ -1103,11 +1112,23 @@ xinit(int cols, int rows)
Window parent;
pid_t thispid = getpid();
XColor xmousefg, xmousebg;
+ XWindowAttributes attr;
+ XVisualInfo vis;
if (!(xw.dpy = XOpenDisplay(NULL)))
die("can't open display\n");
xw.scr = XDefaultScreen(xw.dpy);
- xw.vis = XDefaultVisual(xw.dpy, xw.scr);
+
+ if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
+ parent = XRootWindow(xw.dpy, xw.scr);
+ xw.depth = 32;
+ } else {
+ XGetWindowAttributes(xw.dpy, parent, &attr);
+ xw.depth = attr.depth;
+ }
+
+ XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
+ xw.vis = vis.visual;
/* font */
if (!FcInit())
@@ -1117,7 +1138,7 @@ xinit(int cols, int rows)
xloadfonts(usedfont, 0);
/* colors */
- xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
+ xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
xloadcols();
/* adjust fixed window geometry */
@@ -1137,19 +1158,15 @@ xinit(int cols, int rows)
| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
xw.attrs.colormap = xw.cmap;
- if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
- parent = XRootWindow(xw.dpy, xw.scr);
xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
- win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
+ win.w, win.h, 0, xw.depth, InputOutput,
xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
| CWEventMask | CWColormap, &xw.attrs);
memset(&gcvalues, 0, sizeof(gcvalues));
gcvalues.graphics_exposures = False;
- dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
- &gcvalues);
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
- DefaultDepth(xw.dpy, xw.scr));
+ xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
+ dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
@@ -1988,6 +2005,9 @@ main(int argc, char *argv[])
case 'a':
allowaltscreen = 0;
break;
+ case 'A':
+ opt_alpha = EARGF(usage());
+ break;
case 'c':
opt_class = EARGF(usage());
break;
diff --git a/x.c b/x.c.orig