Add patches for st 0.8.4

This commit is contained in:
Shourai 2020-07-18 12:54:54 +02:00
parent 066e1d364b
commit 6707a7fe91
5 changed files with 491 additions and 0 deletions

View File

@ -0,0 +1,185 @@
From 7979ecf01c6d68f8a6593e3f338c77b8d7526931 Mon Sep 17 00:00:00 2001
From: Shourai <10200748+Shourai@users.noreply.github.com>
Date: Sat, 18 Jul 2020 12:48:15 +0200
Subject: [PATCH 1/5] Apply alpha
---
config.def.h | 13 ++++++++-----
config.mk | 2 +-
st.h | 1 +
x.c | 40 ++++++++++++++++++++++++++++++----------
4 files changed, 40 insertions(+), 16 deletions(-)
diff --git a/config.def.h b/config.def.h
index 6f05dce..53b93ab 100644
--- 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.70;
+
/* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = {
/* 8 normal colors */
@@ -118,8 +121,8 @@ static const char *colorname[] = {
[255] = 0,
/* more colors can be added after 255 to use with DefaultXX */
- "#cccccc",
- "#555555",
+ "#272727",
+ "#ffffff",
};
@@ -127,9 +130,9 @@ static const char *colorname[] = {
* Default colors (colorname index)
* foreground, background, cursor, reverse cursor
*/
-unsigned int defaultfg = 7;
-unsigned int defaultbg = 0;
-static unsigned int defaultcs = 256;
+unsigned int defaultfg = 257;
+unsigned int defaultbg = 256;
+static unsigned int defaultcs = 257;
static unsigned int defaultrcs = 257;
/*
diff --git a/config.mk b/config.mk
index c070a4a..aaa54ff 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 3d351b6..9f11a6a 100644
--- 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/x.c b/x.c
index 210f184..73545d8 100644
--- 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;
--
2.27.0

View File

@ -0,0 +1,181 @@
From ff4fd8469be355ae8fe9e8a0feee46a734b68e74 Mon Sep 17 00:00:00 2001
From: Shourai <10200748+Shourai@users.noreply.github.com>
Date: Sat, 18 Jul 2020 12:48:28 +0200
Subject: [PATCH 2/5] Apply font2
---
Makefile | 2 +-
config.def.h | 10 ++++-
x.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 111 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 470ac86..4d49649 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ st: $(OBJ)
$(CC) -o $@ $(OBJ) $(STLDFLAGS)
clean:
- rm -f st $(OBJ) st-$(VERSION).tar.gz
+ rm -f st $(OBJ) st-$(VERSION).tar.gz config.h
dist: clean
mkdir -p st-$(VERSION)
diff --git a/config.def.h b/config.def.h
index 53b93ab..984158d 100644
--- a/config.def.h
+++ b/config.def.h
@@ -5,7 +5,15 @@
*
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/
-static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
+static char *font = "Jetbrains Mono:pixelsize=14:antialias=true:autohint=true";
+/* Spare fonts */
+static char *font2[] = {
+ "Droid Sans Mono:style=Regular:pixelsize=14:antialias=true:autohint=true",
+ "Menlo:style=Regular:pixelsize=14:antialias=true:autohint=true",
+ "Inconsolata for Powerline:pixelsize=14:antialias=true:autohint=true",
+ "Hack Nerd Font Mono:pixelsize=14:antialias=true:autohint=true",
+};
+
static int borderpx = 2;
/*
diff --git a/x.c b/x.c
index 73545d8..a729880 100644
--- a/x.c
+++ b/x.c
@@ -158,6 +158,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);
@@ -308,6 +310,7 @@ zoomabs(const Arg *arg)
{
xunloadfonts();
xloadfonts(usedfont, arg->f);
+ xloadsparefonts();
cresize(0, 0);
redraw();
xhints();
@@ -1028,6 +1031,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)
{
@@ -1137,6 +1235,9 @@ xinit(int cols, int rows)
usedfont = (opt_font == NULL)? font : opt_font;
xloadfonts(usedfont, 0);
+ /* spare fonts */
+ xloadsparefonts();
+
/* colors */
xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
xloadcols();
--
2.27.0

View File

@ -0,0 +1,61 @@
From 01802617dab7370542755f7e38453be57e7516c8 Mon Sep 17 00:00:00 2001
From: Shourai <10200748+Shourai@users.noreply.github.com>
Date: Sat, 18 Jul 2020 12:48:48 +0200
Subject: [PATCH 3/5] Apply colorscheme
---
config.def.h | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/config.def.h b/config.def.h
index 984158d..1e55784 100644
--- a/config.def.h
+++ b/config.def.h
@@ -106,25 +106,25 @@ float alpha = 0.70;
/* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = {
- /* 8 normal colors */
- "black",
- "red3",
- "green3",
- "yellow3",
- "blue2",
- "magenta3",
- "cyan3",
- "gray90",
-
- /* 8 bright colors */
- "gray50",
- "red",
- "green",
- "yellow",
- "#5c5cff",
- "magenta",
- "cyan",
- "white",
+ /* 8 normal colors */
+ [0] = "#1d2021", /* black */
+ [1] = "#dc322f", /* red */
+ [2] = "#859900", /* green */
+ [3] = "#b58900", /* yellow */
+ [4] = "#268bd2", /* blue */
+ [5] = "#d33682", /* magenta */
+ [6] = "#2aa198", /* cyan */
+ [7] = "#eee8d5", /* white */
+
+ /* 8 bright colors */
+ [8] = "#928374", /* black */
+ [9] = "#cb4b16", /* red */
+ [10] = "#586e75", /* green */
+ [11] = "#657b83", /* yellow */
+ [12] = "#839496", /* blue */
+ [13] = "#6c71c4", /* magenta */
+ [14] = "#93a1a1", /* cyan */
+ [15] = "#fdf6e3", /* white */
[255] = 0,
--
2.27.0

View File

@ -0,0 +1,24 @@
From ea299313051d7d0aa1240b1e7ce57c8844915262 Mon Sep 17 00:00:00 2001
From: Shourai <10200748+Shourai@users.noreply.github.com>
Date: Sat, 18 Jul 2020 12:48:58 +0200
Subject: [PATCH 4/5] Apply clipboard
---
x.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/x.c b/x.c
index a729880..c87e48e 100644
--- a/x.c
+++ b/x.c
@@ -678,6 +678,7 @@ setsel(char *str, Time t)
XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, t);
if (XGetSelectionOwner(xw.dpy, XA_PRIMARY) != xw.win)
selclear();
+ clipcopy(NULL);
}
void
--
2.27.0

View File

@ -0,0 +1,40 @@
From 066e1d364baef67e9cae2289dbb47d6a0724a360 Mon Sep 17 00:00:00 2001
From: Shourai <10200748+Shourai@users.noreply.github.com>
Date: Sat, 18 Jul 2020 12:50:44 +0200
Subject: [PATCH 5/5] Apply keybindings for zoom
---
config.def.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/config.def.h b/config.def.h
index 1e55784..828ee5f 100644
--- a/config.def.h
+++ b/config.def.h
@@ -210,6 +210,13 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
+ { MODKEY|ShiftMask, XK_Up, zoom, {.f = +1} },
+ { MODKEY|ShiftMask, XK_Down, zoom, {.f = -1} },
+ { MODKEY|ShiftMask, XK_K, zoom, {.f = +1} },
+ { MODKEY|ShiftMask, XK_J, zoom, {.f = -1} },
+ { MODKEY|ShiftMask, XK_plus, zoom, {.f = +1} },
+ { MODKEY|ShiftMask, XK_underscore, zoom, {.f = -1} },
+ { MODKEY|ShiftMask, XK_parenright, zoomreset, {.f = 0} },
};
/*
@@ -251,6 +258,9 @@ static uint ignoremod = Mod2Mask|XK_SWITCH_MOD;
*/
static Key key[] = {
/* keysym mask string appkey appcursor */
+ { XK_parenright, Mod1Mask|ShiftMask,"\033[41;6u", 0, 0},
+ { XK_underscore, Mod1Mask|ShiftMask,"\033[95;4u", 0, 0},
+ { XK_plus, Mod1Mask|ShiftMask,"\033[43;4u", 0, 0},
{ XK_KP_Home, ShiftMask, "\033[2J", 0, -1},
{ XK_KP_Home, ShiftMask, "\033[1;2H", 0, +1},
{ XK_KP_Home, XK_ANY_MOD, "\033[H", 0, -1},
--
2.27.0