From c0fc1e9095c559ed9aac52da3d1d155ecab41c78 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 23 Dec 2025 19:43:06 -0700 Subject: [PATCH] change alpha --- config.h | 7 ++++++- st.h | 1 + x.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/config.h b/config.h index fdca135..75925cd 100644 --- a/config.h +++ b/config.h @@ -93,6 +93,9 @@ char *termname = "xterm-256color"; */ unsigned int tabspaces = 8; +/* Background opacity */ +float alpha_def; + /* bg opacity */ float alpha = 0.8; @@ -226,7 +229,9 @@ static Shortcut shortcuts[] = { { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} }, { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} }, - + { MODKEY, XK_bracketleft, chgalpha, {.f = -1} }, /* Decrease opacity */ + { MODKEY, XK_bracketright, chgalpha, {.f = +1} }, /* Increase opacity */ + { MODKEY|ShiftMask, XK_braceright,chgalpha, {.f = 0} }, /* Reset opacity */ }; /* diff --git a/st.h b/st.h index aef72ef..22ea25f 100644 --- a/st.h +++ b/st.h @@ -127,3 +127,4 @@ extern unsigned int tabspaces; extern unsigned int defaultfg; extern unsigned int defaultbg; extern unsigned int defaultcs; +extern float alpha_def; diff --git a/x.c b/x.c index 1a70718..1d4b115 100644 --- a/x.c +++ b/x.c @@ -60,6 +60,7 @@ static void zoom(const Arg *); static void zoomabs(const Arg *); static void zoomreset(const Arg *); static void ttysend(const Arg *); +static void chgalpha(const Arg *); /* config.h for applying patches and the configuration. */ #include "config.h" @@ -1178,6 +1179,9 @@ xinit(int cols, int rows) usedfont = (opt_font == NULL)? font : opt_font; xloadfonts(usedfont, 0); + /* Backup default alpha value */ + alpha_def = alpha; + /* colors */ xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None); @@ -1403,6 +1407,30 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x return numspecs; } +void +chgalpha(const Arg *arg) +{ + if (arg->f == -1.0f && alpha >= 0.1f) + alpha -= 0.1f; + else if (arg->f == 1.0f && alpha < 1.0f) + alpha += 0.1f; + else if (arg->f == 0.0f) + alpha = alpha_def; + else + return; + + /* Clamp alpha so it never exceeds valid range */ + if (alpha < 0.1f) + alpha = 0.1f; + if (alpha > 1.0f) + alpha = 1.0f; + + dc.col[defaultbg].color.alpha = (unsigned short)(0xFFFF * alpha); + /* Required to remove artifacting from borderpx */ + cresize(0, 0); + redraw(); +} + void xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y) {