commit d93e2d94081806ab161def5d60fbd1c415b94eb4
Author: Julius Huelsmann <juliusHuelsmann_AT_gmail.com>
Date: Fri Jul 31 10:22:20 2020 +0200
[st][patch][alpha_focus_highlight]: fix
Apply fix for removing flicker.
diff --git a/st.suckless.org/patches/alpha_focus_highlight/index.md b/st.suckless.org/patches/alpha_focus_highlight/index.md
index d251dc7d..51142c0a 100644
--- a/st.suckless.org/patches/alpha_focus_highlight/index.md
+++ b/st.suckless.org/patches/alpha_focus_highlight/index.md
_AT_@ -53,8 +53,8 @@ Patch: alpha + focus
--------------------
**st-0.8.3**
-- [Version 1 (attached)](st-focus-20200530-43a395a.diff)
-- Most recent release: [st-focus-20200530-43a395a.diff Github](
https://github.com/juliusHuelsmann/st/releases/download/v2/st-focus-20200530-43a395a.diff)
+- [Version 1 (attached)](st-focus-20200731-43a395a.diff)
+- Most recent release: [st-focus-20200530-43a395a.diff Github](
https://github.com/juliusHuelsmann/st/releases/download/v2/st-focus-20200731-43a395a.diff)
---
_AT_@ -62,8 +62,8 @@ Patch: focus
------------
**st-0.8.3**
-- [Version 1 (attached)](st-focus-20200530-patch_alpha.diff)
-- Most recent release: [st-focus-20200530-patch_alpha.diff (Github)](
https://github.com/juliusHuelsmann/st/releases/download/v2/st-focus-20200530-patch_alpha.diff)
+- [Version 1 (attached)](st-focus-20200731-patch_alpha.diff)
+- Most recent release: [st-focus-20200530-patch_alpha.diff (Github)](
https://github.com/juliusHuelsmann/st/releases/download/v2/st-focus-20200731-patch_alpha.diff)
MISC
diff --git a/st.suckless.org/patches/alpha_focus_highlight/st-focus-20200731-43a395a.diff b/st.suckless.org/patches/alpha_focus_highlight/st-focus-20200731-43a395a.diff
new file mode 100644
index 00000000..809cb469
--- /dev/null
+++ b/st.suckless.org/patches/alpha_focus_highlight/st-focus-20200731-43a395a.diff
_AT_@ -0,0 +1,271 @@
+From 10fa2b6aebceb3a12219ef25376297b063638bd9 Mon Sep 17 00:00:00 2001
+From: Julius Huelsmann <juliusHuelsmann_AT_gmail.com>
+Date: Fri, 31 Jul 2020 10:13:35 +0200
+Subject: [PATCH] patch: focus
+
+---
+ config.def.h | 5 ++++
+ config.mk | 2 +-
+ st.c | 1 -
+ st.h | 2 ++
+ x.c | 72 +++++++++++++++++++++++++++++++++++++++-------------
+ 5 files changed, 62 insertions(+), 20 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 0895a1f..577d1f1 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -84,6 +84,9 @@ char *termname = "st-256color";
+ */
+ unsigned int tabspaces = 8;
+
++/* bg opacity */
++float alpha = 0.8, alphaUnfocused = 0.6;
++
+ /* Terminal colors (16 first used in escape sequence) */
+ static const char *colorname[] = {
+ /* 8 normal colors */
+_AT_@ -111,6 +114,7 @@ static const char *colorname[] = {
+ /* more colors can be added after 255 to use with DefaultXX */
+ "#cccccc",
+ "#555555",
++ "black",
+ };
+
+
+_AT_@ -122,6 +126,7 @@ unsigned int defaultfg = 7;
+ unsigned int defaultbg = 0;
+ static unsigned int defaultcs = 256;
+ static unsigned int defaultrcs = 257;
++unsigned int bg = 17, bgUnfocused = 16;
+
+ /*
+ * Default shape of cursor
+diff --git a/config.mk b/config.mk
+index beafc35..ddc65ae 100644
+--- a/config.mk
++++ b/config.mk
+_AT_@ -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.c b/st.c
+index 0ce6ac2..c7f40c8 100644
+--- a/st.c
++++ b/st.c
+_AT_@ -194,7 +194,6 @@ static void tsetscroll(int, int);
+ static void tswapscreen(void);
+ static void tsetmode(int, int, int *, int);
+ static int twrite(const char *, int, int);
+-static void tfulldirt(void);
+ static void tcontrolcode(uchar );
+ static void tdectest(char );
+ static void tdefutf8(char);
+diff --git a/st.h b/st.h
+index d978458..44cb3fd 100644
+--- a/st.h
++++ b/st.h
+_AT_@ -79,6 +79,7 @@ typedef union {
+
+ void die(const char *, ...);
+ void redraw(void);
++void tfulldirt(void);
+ void draw(void);
+
+ void printscreen(const Arg *);
+_AT_@ -122,3 +123,4 @@ extern char *termname;
+ extern unsigned int tabspaces;
+ extern unsigned int defaultfg;
+ extern unsigned int defaultbg;
++extern float alpha, alphaUnfocused;
+diff --git a/x.c b/x.c
+index e5f1737..a2e820f 100644
+--- a/x.c
++++ b/x.c
+_AT_@ -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;
+_AT_@ -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;
+_AT_@ -252,6 +254,8 @@ static char *opt_line = NULL;
+ static char *opt_name = NULL;
+ static char *opt_title = NULL;
+
++static int focused = 0;
++
+ static int oldbutton = 3; /* button event on startup: 3 = release */
+
+ void
+_AT_@ -734,7 +738,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);
+
+_AT_@ -772,28 +776,38 @@ xloadcolor(int i, const char *name, Color *ncolor)
+ return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
+ }
+
++void
++xloadalpha(void)
++{
++ float const usedAlpha = focused ? alpha : alphaUnfocused;
++ if (opt_alpha) alpha = strtof(opt_alpha, NULL);
++ dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedAlpha);
++ dc.col[defaultbg].pixel &= 0x00FFFFFF;
++ dc.col[defaultbg].pixel |= (unsigned char)(0xff * usedAlpha) << 24;
++}
++
+ void
+ xloadcols(void)
+ {
+- int i;
+ static int loaded;
+ Color *cp;
+
+- if (loaded) {
+- for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
+- XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
+- } else {
+- dc.collen = MAX(LEN(colorname), 256);
+- dc.col = xmalloc(dc.collen * sizeof(Color));
++ if (!loaded) {
++ dc.collen = 1 + (defaultbg = MAX(LEN(colorname), 256));
++ dc.col = xmalloc((dc.collen) * sizeof(Color));
+ }
+
+- for (i = 0; i < dc.collen; i++)
++ for (int i = 0; i+1 < dc.collen; ++i)
+ if (!xloadcolor(i, NULL, &dc.col[i])) {
+ if (colorname[i])
+ die("could not allocate color '%s'
", colorname[i]);
+ else
+ die("could not allocate color %d
", i);
+ }
++ if (dc.collen) // cannot die, as the color is already loaded.
++ xloadcolor(focused ?bg :bgUnfocused, NULL, &dc.col[defaultbg]);
++
++ xloadalpha();
+ loaded = 1;
+ }
+
+_AT_@ -1103,11 +1117,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
");
+ 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())
+_AT_@ -1117,7 +1143,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 */
+_AT_@ -1137,19 +1163,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);
+
+_AT_@ -1730,12 +1752,22 @@ focus(XEvent *ev)
+ xseturgency(0);
+ if (IS_SET(MODE_FOCUS))
+ ttywrite("[I", 3, 0);
++ if (!focused) {
++ focused = 1;
++ xloadcols();
++ tfulldirt();
++ }
+ } else {
+ if (xw.ime.xic)
+ XUnsetICFocus(xw.ime.xic);
+ win.mode &= ~MODE_FOCUSED;
+ if (IS_SET(MODE_FOCUS))
+ ttywrite("[O", 3, 0);
++ if (focused) {
++ focused = 0;
++ xloadcols();
++ tfulldirt();
++ }
+ }
+ }
+
+_AT_@ -1994,6 +2026,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;
+_AT_@ -2045,6 +2080,7 @@ run:
+ XSetLocaleModifiers("");
+ cols = MAX(cols, 1);
+ rows = MAX(rows, 1);
++ defaultbg = MAX(LEN(colorname), 256);
+ tnew(cols, rows);
+ xinit(cols, rows);
+ xsetenv();
+--
+2.28.0
+
diff --git a/st.suckless.org/patches/alpha_focus_highlight/st-focus-20200731-patch_alpha.diff b/st.suckless.org/patches/alpha_focus_highlight/st-focus-20200731-patch_alpha.diff
new file mode 100644
index 00000000..42166b71
--- /dev/null
+++ b/st.suckless.org/patches/alpha_focus_highlight/st-focus-20200731-patch_alpha.diff
_AT_@ -0,0 +1,167 @@
+From 3307b33b60adb4e1b5db4dd9849c78fce72b6ca4 Mon Sep 17 00:00:00 2001
+From: Julius Huelsmann <juliusHuelsmann_AT_gmail.com>
+Date: Fri, 31 Jul 2020 10:13:30 +0200
+Subject: [PATCH] patch: focus
+
+---
+ config.def.h | 5 +++--
+ st.c | 1 -
+ st.h | 3 ++-
+ x.c | 44 ++++++++++++++++++++++++++++++--------------
+ 4 files changed, 35 insertions(+), 18 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index b94b23c..577d1f1 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -85,7 +85,7 @@ char *termname = "st-256color";
+ unsigned int tabspaces = 8;
+
+ /* bg opacity */
+-float alpha = 0.8;
++float alpha = 0.8, alphaUnfocused = 0.6;
+
+ /* Terminal colors (16 first used in escape sequence) */
+ static const char *colorname[] = {
+_AT_@ -123,9 +123,10 @@ static const char *colorname[] = {
+ * foreground, background, cursor, reverse cursor
+ */
+ unsigned int defaultfg = 7;
+-unsigned int defaultbg = 258;
++unsigned int defaultbg = 0;
+ static unsigned int defaultcs = 256;
+ static unsigned int defaultrcs = 257;
++unsigned int bg = 17, bgUnfocused = 16;
+
+ /*
+ * Default shape of cursor
+diff --git a/st.c b/st.c
+index 0ce6ac2..c7f40c8 100644
+--- a/st.c
++++ b/st.c
+_AT_@ -194,7 +194,6 @@ static void tsetscroll(int, int);
+ static void tswapscreen(void);
+ static void tsetmode(int, int, int *, int);
+ static int twrite(const char *, int, int);
+-static void tfulldirt(void);
+ static void tcontrolcode(uchar );
+ static void tdectest(char );
+ static void tdefutf8(char);
+diff --git a/st.h b/st.h
+index 2c656af..44cb3fd 100644
+--- a/st.h
++++ b/st.h
+_AT_@ -79,6 +79,7 @@ typedef union {
+
+ void die(const char *, ...);
+ void redraw(void);
++void tfulldirt(void);
+ void draw(void);
+
+ void printscreen(const Arg *);
+_AT_@ -122,4 +123,4 @@ extern char *termname;
+ extern unsigned int tabspaces;
+ extern unsigned int defaultfg;
+ extern unsigned int defaultbg;
+-extern float alpha;
++extern float alpha, alphaUnfocused;
+diff --git a/x.c b/x.c
+index 50da23c..a2e820f 100644
+--- a/x.c
++++ b/x.c
+_AT_@ -254,6 +254,8 @@ static char *opt_line = NULL;
+ static char *opt_name = NULL;
+ static char *opt_title = NULL;
+
++static int focused = 0;
++
+ static int oldbutton = 3; /* button event on startup: 3 = release */
+
+ void
+_AT_@ -774,35 +776,38 @@ xloadcolor(int i, const char *name, Color *ncolor)
+ return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
+ }
+
++void
++xloadalpha(void)
++{
++ float const usedAlpha = focused ? alpha : alphaUnfocused;
++ if (opt_alpha) alpha = strtof(opt_alpha, NULL);
++ dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedAlpha);
++ dc.col[defaultbg].pixel &= 0x00FFFFFF;
++ dc.col[defaultbg].pixel |= (unsigned char)(0xff * usedAlpha) << 24;
++}
++
+ void
+ xloadcols(void)
+ {
+- int i;
+ static int loaded;
+ Color *cp;
+
+- if (loaded) {
+- for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
+- XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
+- } else {
+- dc.collen = MAX(LEN(colorname), 256);
+- dc.col = xmalloc(dc.collen * sizeof(Color));
++ if (!loaded) {
++ dc.collen = 1 + (defaultbg = MAX(LEN(colorname), 256));
++ dc.col = xmalloc((dc.collen) * sizeof(Color));
+ }
+
+- for (i = 0; i < dc.collen; i++)
++ for (int i = 0; i+1 < dc.collen; ++i)
+ if (!xloadcolor(i, NULL, &dc.col[i])) {
+ if (colorname[i])
+ die("could not allocate color '%s'
", colorname[i]);
+ else
+ die("could not allocate color %d
", i);
+ }
++ if (dc.collen) // cannot die, as the color is already loaded.
++ xloadcolor(focused ?bg :bgUnfocused, NULL, &dc.col[defaultbg]);
+
+- /* 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;
++ xloadalpha();
+ loaded = 1;
+ }
+
+_AT_@ -1747,12 +1752,22 @@ focus(XEvent *ev)
+ xseturgency(0);
+ if (IS_SET(MODE_FOCUS))
+ ttywrite("[I", 3, 0);
++ if (!focused) {
++ focused = 1;
++ xloadcols();
++ tfulldirt();
++ }
+ } else {
+ if (xw.ime.xic)
+ XUnsetICFocus(xw.ime.xic);
+ win.mode &= ~MODE_FOCUSED;
+ if (IS_SET(MODE_FOCUS))
+ ttywrite("[O", 3, 0);
++ if (focused) {
++ focused = 0;
++ xloadcols();
++ tfulldirt();
++ }
+ }
+ }
+
+_AT_@ -2065,6 +2080,7 @@ run:
+ XSetLocaleModifiers("");
+ cols = MAX(cols, 1);
+ rows = MAX(rows, 1);
++ defaultbg = MAX(LEN(colorname), 256);
+ tnew(cols, rows);
+ xinit(cols, rows);
+ xsetenv();
+--
+2.28.0
+
Received on Fri Jul 31 2020 - 10:23:09 CEST