Adding alpha-focus-highlight patch

This commit is contained in:
bakkeby 2021-05-09 14:40:30 +02:00
parent 56e208e0de
commit 1a1d492cd8
5 changed files with 85 additions and 2 deletions

View File

@ -15,7 +15,7 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
### Changelog: ### Changelog:
2021-05-09 - Added the sync patch 2021-05-09 - Added the sync and alpha-focus-hightlight patches
2021-05-08 - Added blinking cursor, delkey, undercurl,universcroll, desktopentry, netwmicon and osc_10_11_12_2 patches 2021-05-08 - Added blinking cursor, delkey, undercurl,universcroll, desktopentry, netwmicon and osc_10_11_12_2 patches
@ -68,6 +68,10 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
- [alpha](https://st.suckless.org/patches/alpha/) - [alpha](https://st.suckless.org/patches/alpha/)
- adds transparency for the terminal - adds transparency for the terminal
- [alpha-focus-highlight](https://st.suckless.org/patches/alpha_focus_highlight/)
- allows the user to specify two distinct opacity values or background colors in order to
easily differentiate between focused and unfocused terminal windows
- [anysize](https://st.suckless.org/patches/anysize/) - [anysize](https://st.suckless.org/patches/anysize/)
- allows st to reize to any pixel size rather than snapping to character width / height - allows st to reize to any pixel size rather than snapping to character width / height

View File

@ -140,6 +140,9 @@ float alpha = 0.8;
float grad_alpha = 0.54; //alpha value that'll change float grad_alpha = 0.54; //alpha value that'll change
float stat_alpha = 0.46; //constant alpha value that'll get added to grad_alpha float stat_alpha = 0.46; //constant alpha value that'll get added to grad_alpha
#endif // ALPHA_GRADIENT_PATCH #endif // ALPHA_GRADIENT_PATCH
#if ALPHA_FOCUS_HIGHLIGHT_PATCH
float alphaUnfocused = 0.6;
#endif // ALPHA_FOCUS_HIGHLIGHT_PATCH
#endif // ALPHA_PATCH #endif // ALPHA_PATCH
/* Terminal colors (16 first used in escape sequence) */ /* Terminal colors (16 first used in escape sequence) */
@ -178,8 +181,13 @@ static const char *colorname[] = {
* Default colors (colorname index) * Default colors (colorname index)
* foreground, background, cursor, reverse cursor * foreground, background, cursor, reverse cursor
*/ */
unsigned int defaultfg = 259; #if ALPHA_PATCH && ALPHA_FOCUS_HIGHLIGHT_PATCH
unsigned int defaultbg = 0;
unsigned int bg = 17, bgUnfocused = 16;
#else
unsigned int defaultbg = 258; unsigned int defaultbg = 258;
#endif // ALPHA_FOCUS_HIGHLIGHT_PATCH
unsigned int defaultfg = 259;
unsigned int defaultcs = 256; unsigned int defaultcs = 256;
unsigned int defaultrcs = 257; unsigned int defaultrcs = 257;

View File

@ -16,6 +16,14 @@
*/ */
#define ALPHA_PATCH 0 #define ALPHA_PATCH 0
/* The alpha focus highlight patch allows the user to specify two distinct opacity values or
* background colors in order to easily differentiate between focused and unfocused terminal
* windows. This depends on the alpha patch.
* https://github.com/juliusHuelsmann/st-focus/
* https://st.suckless.org/patches/alpha_focus_highlight/
*/
#define ALPHA_FOCUS_HIGHLIGHT_PATCH 0
/* Adds gradient transparency to st, depends on the alpha patch. /* Adds gradient transparency to st, depends on the alpha patch.
* https://st.suckless.org/patches/gradient/ * https://st.suckless.org/patches/gradient/
*/ */

3
st.h
View File

@ -343,6 +343,9 @@ extern const int boxdraw, boxdraw_bold, boxdraw_braille;
#endif // BOXDRAW_PATCH #endif // BOXDRAW_PATCH
#if ALPHA_PATCH #if ALPHA_PATCH
extern float alpha; extern float alpha;
#if ALPHA_FOCUS_HIGHLIGHT_PATCH
extern float alphaUnfocused;
#endif // ALPHA_FOCUS_HIGHLIGHT_PATCH
#endif // ALPHA_PATCH #endif // ALPHA_PATCH
extern DC dc; extern DC dc;

60
x.c
View File

@ -185,6 +185,10 @@ static char *opt_title = NULL;
static char *opt_dir = NULL; static char *opt_dir = NULL;
#endif // WORKINGDIR_PATCH #endif // WORKINGDIR_PATCH
#if ALPHA_PATCH && ALPHA_FOCUS_HIGHLIGHT_PATCH
static int focused = 0;
#endif // ALPHA_FOCUS_HIGHLIGHT_PATCH
static int oldbutton = 3; /* button event on startup: 3 = release */ static int oldbutton = 3; /* button event on startup: 3 = release */
#if BLINKING_CURSOR_PATCH #if BLINKING_CURSOR_PATCH
static int cursorblinks = 0; static int cursorblinks = 0;
@ -772,6 +776,44 @@ xloadcolor(int i, const char *name, Color *ncolor)
return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
} }
#if ALPHA_PATCH && ALPHA_FOCUS_HIGHLIGHT_PATCH
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;
}
#endif // ALPHA_FOCUS_HIGHLIGHT_PATCH
#if ALPHA_PATCH && ALPHA_FOCUS_HIGHLIGHT_PATCH
void
xloadcols(void)
{
static int loaded;
Color *cp;
if (!loaded) {
dc.collen = 1 + (defaultbg = MAX(LEN(colorname), 256));
dc.col = xmalloc((dc.collen) * sizeof(Color));
}
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'\n", colorname[i]);
else
die("could not allocate color %d\n", i);
}
if (dc.collen) // cannot die, as the color is already loaded.
xloadcolor(focused ? bg : bgUnfocused, NULL, &dc.col[defaultbg]);
xloadalpha();
loaded = 1;
}
#else
void void
xloadcols(void) xloadcols(void)
{ {
@ -804,6 +846,7 @@ xloadcols(void)
#endif // ALPHA_PATCH #endif // ALPHA_PATCH
loaded = 1; loaded = 1;
} }
#endif // ALPHA_FOCUS_HIGHLIGHT_PATCH
int int
xsetcolorname(int x, const char *name) xsetcolorname(int x, const char *name)
@ -2344,12 +2387,26 @@ focus(XEvent *ev)
xseturgency(0); xseturgency(0);
if (IS_SET(MODE_FOCUS)) if (IS_SET(MODE_FOCUS))
ttywrite("\033[I", 3, 0); ttywrite("\033[I", 3, 0);
#if ALPHA_PATCH && ALPHA_FOCUS_HIGHLIGHT_PATCH
if (!focused) {
focused = 1;
xloadcols();
redraw();
}
#endif // ALPHA_FOCUS_HIGHLIGHT_PATCH
} else { } else {
if (xw.ime.xic) if (xw.ime.xic)
XUnsetICFocus(xw.ime.xic); XUnsetICFocus(xw.ime.xic);
win.mode &= ~MODE_FOCUSED; win.mode &= ~MODE_FOCUSED;
if (IS_SET(MODE_FOCUS)) if (IS_SET(MODE_FOCUS))
ttywrite("\033[O", 3, 0); ttywrite("\033[O", 3, 0);
#if ALPHA_PATCH && ALPHA_FOCUS_HIGHLIGHT_PATCH
if (focused) {
focused = 0;
xloadcols();
redraw();
}
#endif // ALPHA_FOCUS_HIGHLIGHT_PATCH
} }
} }
@ -2771,6 +2828,9 @@ run:
#endif // XRESOURCES_RELOAD_PATCH #endif // XRESOURCES_RELOAD_PATCH
cols = MAX(cols, 1); cols = MAX(cols, 1);
rows = MAX(rows, 1); rows = MAX(rows, 1);
#if ALPHA_PATCH && ALPHA_FOCUS_HIGHLIGHT_PATCH
defaultbg = MAX(LEN(colorname), 256);
#endif // ALPHA_FOCUS_HIGHLIGHT_PATCH
tnew(cols, rows); tnew(cols, rows);
xinit(cols, rows); xinit(cols, rows);
xsetenv(); xsetenv();