diff --git a/config.def.h b/config.def.h index 433cd63..558625e 100644 --- a/config.def.h +++ b/config.def.h @@ -99,6 +99,9 @@ unsigned int tabspaces = 8; /* bg opacity */ float alpha = 0.8; +/* Background opacity */ +float alpha_def; + /* Terminal colors (16 first used in escape sequence) */ static const char *colorname[] = { /* 8 normal colors */ @@ -249,6 +252,9 @@ static Shortcut shortcuts[] = { { ControlMask, XK_Page_Down, kscrolldown, {.i = 10} }, { ControlMask, XK_k, kscrollup, {.i = 1} }, { ControlMask, XK_j, kscrolldown, {.i = 1} }, + { TERMMOD, XK_N, chgalpha, {.f = -1} }, /* Decrease opacity */ + { TERMMOD, XK_M, chgalpha, {.f = +1} }, /* Increase opacity */ + { TERMMOD, XK_B, chgalpha, {.f = 0} }, /* Reset opacity */ }; /* diff --git a/config.h b/config.h index 433cd63..558625e 100644 --- a/config.h +++ b/config.h @@ -99,6 +99,9 @@ unsigned int tabspaces = 8; /* bg opacity */ float alpha = 0.8; +/* Background opacity */ +float alpha_def; + /* Terminal colors (16 first used in escape sequence) */ static const char *colorname[] = { /* 8 normal colors */ @@ -249,6 +252,9 @@ static Shortcut shortcuts[] = { { ControlMask, XK_Page_Down, kscrolldown, {.i = 10} }, { ControlMask, XK_k, kscrollup, {.i = 1} }, { ControlMask, XK_j, kscrolldown, {.i = 1} }, + { TERMMOD, XK_N, chgalpha, {.f = -1} }, /* Decrease opacity */ + { TERMMOD, XK_M, chgalpha, {.f = +1} }, /* Increase opacity */ + { TERMMOD, XK_B, chgalpha, {.f = 0} }, /* Reset opacity */ }; /* diff --git a/patches/st-changealpha-20230519-b44f2ad.diff b/patches/st-changealpha-20230519-b44f2ad.diff new file mode 100644 index 0000000..172969f --- /dev/null +++ b/patches/st-changealpha-20230519-b44f2ad.diff @@ -0,0 +1,80 @@ +diff --git a/config.def.h b/config.def.h +index 91ab8ca..8a06176 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -93,6 +93,9 @@ char *termname = "st-256color"; + */ + unsigned int tabspaces = 8; + ++/* Background opacity */ ++float alpha_def; ++ + /* Terminal colors (16 first used in escape sequence) */ + static const char *colorname[] = { + /* 8 normal colors */ +@@ -201,6 +204,9 @@ static Shortcut shortcuts[] = { + { TERMMOD, XK_Y, selpaste, {.i = 0} }, + { ShiftMask, XK_Insert, selpaste, {.i = 0} }, + { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, ++ { MODKEY, XK_bracketleft, chgalpha, {.f = -1} }, /* Decrease opacity */ ++ { MODKEY|ShiftMask, XK_braceright, chgalpha, {.f = +1} }, /* Increase opacity */ ++ { MODKEY, XK_bracketright,chgalpha, {.f = 0} }, /* Reset opacity */ + }; + + /* +diff --git a/st.h b/st.h +index fd3b0d8..3bb587e 100644 +--- a/st.h ++++ b/st.h +@@ -124,3 +124,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 aa09997..f8c8c1a 100644 +--- a/x.c ++++ b/x.c +@@ -59,6 +59,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" +@@ -1147,6 +1148,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 = XDefaultColormap(xw.dpy, xw.scr); + xloadcols(); +@@ -1371,6 +1375,24 @@ 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; ++ ++ 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) + { diff --git a/st b/st index 871b403..c3f34c4 100755 Binary files a/st and b/st differ diff --git a/st.h b/st.h index 5434356..4bf20d5 100644 --- a/st.h +++ b/st.h @@ -134,3 +134,4 @@ extern unsigned int defaultfg; extern unsigned int defaultbg; extern unsigned int defaultcs; extern float alpha; +extern float alpha_def; diff --git a/x.c b/x.c index a9b9c27..2a4680f 100644 --- a/x.c +++ b/x.c @@ -73,6 +73,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" @@ -1281,6 +1282,9 @@ xinit(int cols, int rows) /* spare fonts */ xloadsparefonts(); + /* Backup default alpha value */ + alpha_def = alpha; + /* colors */ xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None); xloadcols(); @@ -1501,6 +1505,24 @@ 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; + + 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, int dmode) { diff --git a/x.o b/x.o index b9da6ab..194d880 100644 Binary files a/x.o and b/x.o differ