st-changealpha-20230519-b44f2ad.diff - sites - public wiki contents of suckless… | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
st-changealpha-20230519-b44f2ad.diff (2409B) | |
--- | |
1 diff --git a/config.def.h b/config.def.h | |
2 index 91ab8ca..8a06176 100644 | |
3 --- a/config.def.h | |
4 +++ b/config.def.h | |
5 @@ -93,6 +93,9 @@ char *termname = "st-256color"; | |
6 */ | |
7 unsigned int tabspaces = 8; | |
8 | |
9 +/* Background opacity */ | |
10 +float alpha_def; | |
11 + | |
12 /* Terminal colors (16 first used in escape sequence) */ | |
13 static const char *colorname[] = { | |
14 /* 8 normal colors */ | |
15 @@ -201,6 +204,9 @@ static Shortcut shortcuts[] = { | |
16 { TERMMOD, XK_Y, selpaste, {.i = … | |
17 { ShiftMask, XK_Insert, selpaste, {.i = … | |
18 { TERMMOD, XK_Num_Lock, numlock, {.i = … | |
19 + { MODKEY, XK_bracketleft, chgalpha, {.f = -… | |
20 + { MODKEY|ShiftMask, XK_braceright, chgalpha, {.f = +… | |
21 + { MODKEY, XK_bracketright,chgalpha, {.f = … | |
22 }; | |
23 | |
24 /* | |
25 diff --git a/st.h b/st.h | |
26 index fd3b0d8..3bb587e 100644 | |
27 --- a/st.h | |
28 +++ b/st.h | |
29 @@ -124,3 +124,4 @@ extern unsigned int tabspaces; | |
30 extern unsigned int defaultfg; | |
31 extern unsigned int defaultbg; | |
32 extern unsigned int defaultcs; | |
33 +extern float alpha_def; | |
34 diff --git a/x.c b/x.c | |
35 index aa09997..f8c8c1a 100644 | |
36 --- a/x.c | |
37 +++ b/x.c | |
38 @@ -59,6 +59,7 @@ static void zoom(const Arg *); | |
39 static void zoomabs(const Arg *); | |
40 static void zoomreset(const Arg *); | |
41 static void ttysend(const Arg *); | |
42 +static void chgalpha(const Arg *); | |
43 | |
44 /* config.h for applying patches and the configuration. */ | |
45 #include "config.h" | |
46 @@ -1147,6 +1148,9 @@ xinit(int cols, int rows) | |
47 usedfont = (opt_font == NULL)? font : opt_font; | |
48 xloadfonts(usedfont, 0); | |
49 | |
50 + /* Backup default alpha value */ | |
51 + alpha_def = alpha; | |
52 + | |
53 /* colors */ | |
54 xw.cmap = XDefaultColormap(xw.dpy, xw.scr); | |
55 xloadcols(); | |
56 @@ -1371,6 +1375,24 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, cons… | |
57 return numspecs; | |
58 } | |
59 | |
60 +void | |
61 +chgalpha(const Arg *arg) | |
62 +{ | |
63 + if (arg->f == -1.0f && alpha >= 0.1f) | |
64 + alpha -= 0.1f; | |
65 + else if (arg->f == 1.0f && alpha < 1.0f) | |
66 + alpha += 0.1f; | |
67 + else if (arg->f == 0.0f) | |
68 + alpha = alpha_def; | |
69 + else | |
70 + return; | |
71 + | |
72 + dc.col[defaultbg].color.alpha = (unsigned short)(0xFFFF * alpha); | |
73 + /* Required to remove artifacting from borderpx */ | |
74 + cresize(0, 0); | |
75 + redraw(); | |
76 +} | |
77 + | |
78 void | |
79 xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len,… | |
80 { |