change alpha patch

This commit is contained in:
mrsu 2023-06-29 15:48:57 +01:00
parent c0d403acdb
commit ec85db6a2d
7 changed files with 115 additions and 0 deletions

View File

@ -99,6 +99,9 @@ unsigned int tabspaces = 8;
/* bg opacity */ /* bg opacity */
float alpha = 0.8; float alpha = 0.8;
/* Background opacity */
float alpha_def;
/* Terminal colors (16 first used in escape sequence) */ /* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = { static const char *colorname[] = {
/* 8 normal colors */ /* 8 normal colors */
@ -249,6 +252,9 @@ static Shortcut shortcuts[] = {
{ ControlMask, XK_Page_Down, kscrolldown, {.i = 10} }, { ControlMask, XK_Page_Down, kscrolldown, {.i = 10} },
{ ControlMask, XK_k, kscrollup, {.i = 1} }, { ControlMask, XK_k, kscrollup, {.i = 1} },
{ ControlMask, XK_j, kscrolldown, {.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 */
}; };
/* /*

View File

@ -99,6 +99,9 @@ unsigned int tabspaces = 8;
/* bg opacity */ /* bg opacity */
float alpha = 0.8; float alpha = 0.8;
/* Background opacity */
float alpha_def;
/* Terminal colors (16 first used in escape sequence) */ /* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = { static const char *colorname[] = {
/* 8 normal colors */ /* 8 normal colors */
@ -249,6 +252,9 @@ static Shortcut shortcuts[] = {
{ ControlMask, XK_Page_Down, kscrolldown, {.i = 10} }, { ControlMask, XK_Page_Down, kscrolldown, {.i = 10} },
{ ControlMask, XK_k, kscrollup, {.i = 1} }, { ControlMask, XK_k, kscrollup, {.i = 1} },
{ ControlMask, XK_j, kscrolldown, {.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 */
}; };
/* /*

View File

@ -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)
{

BIN
st

Binary file not shown.

1
st.h
View File

@ -134,3 +134,4 @@ extern unsigned int defaultfg;
extern unsigned int defaultbg; extern unsigned int defaultbg;
extern unsigned int defaultcs; extern unsigned int defaultcs;
extern float alpha; extern float alpha;
extern float alpha_def;

22
x.c
View File

@ -73,6 +73,7 @@ static void zoom(const Arg *);
static void zoomabs(const Arg *); static void zoomabs(const Arg *);
static void zoomreset(const Arg *); static void zoomreset(const Arg *);
static void ttysend(const Arg *); static void ttysend(const Arg *);
static void chgalpha(const Arg *);
/* config.h for applying patches and the configuration. */ /* config.h for applying patches and the configuration. */
#include "config.h" #include "config.h"
@ -1281,6 +1282,9 @@ xinit(int cols, int rows)
/* spare fonts */ /* spare fonts */
xloadsparefonts(); xloadsparefonts();
/* Backup default alpha value */
alpha_def = alpha;
/* colors */ /* colors */
xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None); xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
xloadcols(); xloadcols();
@ -1501,6 +1505,24 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
return numspecs; 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 void
xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y, int dmode) xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y, int dmode)
{ {

BIN
x.o

Binary file not shown.