[wiki] [sites] [st][patch][alpha_focus_highlight]: port patch to master HEAD. || Julius Huelsmann

From: <git_AT_suckless.org>
Date: Sun, 16 Feb 2020 18:59:18 +0100

commit f80ff3839826233c55d1d33e465fc5adf287226f
Author: Julius Huelsmann <juliusHuelsmann_AT_gmail.com>
Date: Sun Feb 16 18:59:15 2020 +0100

    [st][patch][alpha_focus_highlight]: port patch to master HEAD.

diff --git a/st.suckless.org/patches/alpha_focus_highlight/index.md b/st.suckless.org/patches/alpha_focus_highlight/index.md
index f5397e80..b7075d8c 100644
--- a/st.suckless.org/patches/alpha_focus_highlight/index.md
+++ b/st.suckless.org/patches/alpha_focus_highlight/index.md
_AT_@ -40,8 +40,9 @@ Notes
 
 Download
 -----------------------------------
-**All versions (from old to new)**:
-Based on commit `2b8333f` of `st`.
+
+## Based on commit `2b8333f` of `st` (Okt 2019).
+*All versions (from old to new)*:
 * [Version 1.0 (attached)](st-alphafocushighlight-20191107-2b8333f.diff)
 * [Version 1.0 (Github)](https://github.com/juliusHuelsmann/st/releases/download/patchesV3/st-alphaFocusHighlight-20191107-2b8333f.diff)
 * [Version1.1 (attached)](st-alphaFocusHighlight-20191218-2b8333f.diff)
_AT_@ -49,9 +50,18 @@ Based on commit `2b8333f` of `st`.
 * [Version1.2 (attached)](st-alphaFocusHighlight-20200212-2b8333f.diff)
 * [Version1.2 (Github)](https://github.com/juliusHuelsmann/st/releases/download/patchesV3/st-alphaFocusHighlight-20200212-2b8333f.diff)
 
-**Most Recent**:
+*Most Recent*:
 * [st-alphaFocusHighlight-20200212-2b8333f.diff (Github)](https://github.com/juliusHuelsmann/st/releases/download/patchesV3/st-alphaFocusHighlight-20200212-2b8333f.diff)
 
+## Based on commit `cd78575` of `st` (February 2020).
+*All versions (from old to new)*:
+* [Version 1.2 (attached)](st-alphaFocusHighlight-20200216-26cdfeb.diff)
+
+*Most Recent*:
+* [st-alphaFocusHighlight-20200216-26cdfeb.diff (Github)](https://github.com/juliusHuelsmann/st/releases/download/patchesV3/st-alphaFocusHighlight-20200216-26cdfeb.diff)
+
+Note that patch errors can occur when the code in the st repo is updated. Please report [an
+Issue](https://github.com/juliusHuelsmann/st/issues) or contribute a merged patch in that case.
 
 Authors of the Alpha Patch
 --------------------------
diff --git a/st.suckless.org/patches/alpha_focus_highlight/st-alphaFocusHighlight-20200216-26cdfeb.diff b/st.suckless.org/patches/alpha_focus_highlight/st-alphaFocusHighlight-20200216-26cdfeb.diff
new file mode 100644
index 00000000..85c744bd
--- /dev/null
+++ b/st.suckless.org/patches/alpha_focus_highlight/st-alphaFocusHighlight-20200216-26cdfeb.diff
_AT_@ -0,0 +1,235 @@
+From 7538b0b641fa8291b98f65ecc5d140e0e9cc0028 Mon Sep 17 00:00:00 2001
+From: Julius Huelsmann <juliusHuelsmann_AT_gmail.com>
+Date: Sun, 16 Feb 2020 18:36:56 +0100
+Subject: [PATCH] alpha_focus: port patch
+
+---
+ config.def.h | 7 +++++-
+ config.mk | 2 +-
+ st.h | 2 ++
+ x.c | 61 +++++++++++++++++++++++++++++++++++++++++++---------
+ 4 files changed, 60 insertions(+), 12 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 546edda..6c6b928 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -82,6 +82,10 @@ char *termname = "st-256color";
+ */
+ unsigned int tabspaces = 8;
+
++/* bg opacity */
++float alpha = 0.8; //< alpha value used when the window is focused.
++float alphaUnfocussed = 0.6; //< alpha value used when the focus is lost
++
+ /* Terminal colors (16 first used in escape sequence) */
+ static const char *colorname[] = {
+ /* 8 normal colors */
+_AT_@ -109,6 +113,7 @@ static const char *colorname[] = {
+ /* more colors can be added after 255 to use with DefaultXX */
+ "#cccccc",
+ "#555555",
++ "black",
+ };
+
+
+_AT_@ -117,7 +122,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
+_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.h b/st.h
+index a1928ca..2009c33 100644
+--- a/st.h
++++ b/st.h
+_AT_@ -121,3 +121,5 @@ extern char *termname;
+ extern unsigned int tabspaces;
+ extern unsigned int defaultfg;
+ extern unsigned int defaultbg;
++extern float alpha;
++extern float alphaUnfocussed;
+diff --git a/x.c b/x.c
+index 1f62129..6d6751d 100644
+--- a/x.c
++++ b/x.c
+_AT_@ -4,6 +4,7 @@
+ #include <limits.h>
+ #include <locale.h>
+ #include <signal.h>
++#include <stdbool.h>
+ #include <sys/select.h>
+ #include <time.h>
+ #include <unistd.h>
+_AT_@ -105,6 +106,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_@ -242,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_@ -250,6 +253,7 @@ static char *opt_io = NULL;
+ static char *opt_line = NULL;
+ static char *opt_name = NULL;
+ static char *opt_title = NULL;
++static bool focused = true;
+
+ static int oldbutton = 3; /* button event on startup: 3 = release */
+
+_AT_@ -719,7 +723,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_@ -757,6 +761,20 @@ xloadcolor(int i, const char *name, Color *ncolor)
+ return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
+ }
+
++void
++xloadalpha(void)
++{
++ /* set alpha value of bg color */
++ if (opt_alpha)
++ alpha = strtof(opt_alpha, NULL);
++
++ float const usedAlpha = focused ? alpha : alphaUnfocussed;
++
++ 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)
+ {
+_AT_@ -779,6 +797,8 @@ xloadcols(void)
+ else
+ die("could not allocate color %d
", i);
+ }
++
++ xloadalpha();
+ loaded = 1;
+ }
+
+_AT_@ -1089,11 +1109,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_@ -1103,7 +1135,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_@ -1123,19 +1155,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_@ -1716,12 +1744,22 @@ focus(XEvent *ev)
+ xseturgency(0);
+ if (IS_SET(MODE_FOCUS))
+ ttywrite("", 3, 0);
++ if (!focused) {
++ focused = true;
++ xloadalpha();
++ redraw();
++ }
+ } else {
+ if (xw.ime.xic)
+ XUnsetICFocus(xw.ime.xic);
+ win.mode &= ~MODE_FOCUSED;
+ if (IS_SET(MODE_FOCUS))
+ ttywrite("", 3, 0);
++ if (focused) {
++ focused = false;
++ xloadalpha();
++ redraw();
++ }
+ }
+ }
+
+_AT_@ -1980,6 +2018,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.25.0
+
Received on Sun Feb 16 2020 - 18:59:18 CET

This archive was generated by hypermail 2.3.0 : Sun Feb 16 2020 - 19:00:37 CET