st/patches/st-changealpha-20230519-b44...

81 lines
2.4 KiB
Diff
Raw Normal View History

2023-06-29 15:48:57 +01:00
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)
{