change alpha

This commit is contained in:
Your Name
2025-12-23 19:43:06 -07:00
parent b37126608a
commit c0fc1e9095
3 changed files with 35 additions and 1 deletions

View File

@@ -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 */
};
/*

1
st.h
View File

@@ -127,3 +127,4 @@ extern unsigned int tabspaces;
extern unsigned int defaultfg;
extern unsigned int defaultbg;
extern unsigned int defaultcs;
extern float alpha_def;

28
x.c
View File

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