st-focus-20200731-patch_alpha.diff - sites - public wiki contents of suckless.o… | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
st-focus-20200731-patch_alpha.diff (4414B) | |
--- | |
1 From 3307b33b60adb4e1b5db4dd9849c78fce72b6ca4 Mon Sep 17 00:00:00 2001 | |
2 From: Julius Huelsmann <[email protected]> | |
3 Date: Fri, 31 Jul 2020 10:13:30 +0200 | |
4 Subject: [PATCH] patch: focus | |
5 | |
6 --- | |
7 config.def.h | 5 +++-- | |
8 st.c | 1 - | |
9 st.h | 3 ++- | |
10 x.c | 44 ++++++++++++++++++++++++++++++-------------- | |
11 4 files changed, 35 insertions(+), 18 deletions(-) | |
12 | |
13 diff --git a/config.def.h b/config.def.h | |
14 index b94b23c..577d1f1 100644 | |
15 --- a/config.def.h | |
16 +++ b/config.def.h | |
17 @@ -85,7 +85,7 @@ char *termname = "st-256color"; | |
18 unsigned int tabspaces = 8; | |
19 | |
20 /* bg opacity */ | |
21 -float alpha = 0.8; | |
22 +float alpha = 0.8, alphaUnfocused = 0.6; | |
23 | |
24 /* Terminal colors (16 first used in escape sequence) */ | |
25 static const char *colorname[] = { | |
26 @@ -123,9 +123,10 @@ static const char *colorname[] = { | |
27 * foreground, background, cursor, reverse cursor | |
28 */ | |
29 unsigned int defaultfg = 7; | |
30 -unsigned int defaultbg = 258; | |
31 +unsigned int defaultbg = 0; | |
32 static unsigned int defaultcs = 256; | |
33 static unsigned int defaultrcs = 257; | |
34 +unsigned int bg = 17, bgUnfocused = 16; | |
35 | |
36 /* | |
37 * Default shape of cursor | |
38 diff --git a/st.c b/st.c | |
39 index 0ce6ac2..c7f40c8 100644 | |
40 --- a/st.c | |
41 +++ b/st.c | |
42 @@ -194,7 +194,6 @@ static void tsetscroll(int, int); | |
43 static void tswapscreen(void); | |
44 static void tsetmode(int, int, int *, int); | |
45 static int twrite(const char *, int, int); | |
46 -static void tfulldirt(void); | |
47 static void tcontrolcode(uchar ); | |
48 static void tdectest(char ); | |
49 static void tdefutf8(char); | |
50 diff --git a/st.h b/st.h | |
51 index 2c656af..44cb3fd 100644 | |
52 --- a/st.h | |
53 +++ b/st.h | |
54 @@ -79,6 +79,7 @@ typedef union { | |
55 | |
56 void die(const char *, ...); | |
57 void redraw(void); | |
58 +void tfulldirt(void); | |
59 void draw(void); | |
60 | |
61 void printscreen(const Arg *); | |
62 @@ -122,4 +123,4 @@ extern char *termname; | |
63 extern unsigned int tabspaces; | |
64 extern unsigned int defaultfg; | |
65 extern unsigned int defaultbg; | |
66 -extern float alpha; | |
67 +extern float alpha, alphaUnfocused; | |
68 diff --git a/x.c b/x.c | |
69 index 50da23c..a2e820f 100644 | |
70 --- a/x.c | |
71 +++ b/x.c | |
72 @@ -254,6 +254,8 @@ static char *opt_line = NULL; | |
73 static char *opt_name = NULL; | |
74 static char *opt_title = NULL; | |
75 | |
76 +static int focused = 0; | |
77 + | |
78 static int oldbutton = 3; /* button event on startup: 3 = release */ | |
79 | |
80 void | |
81 @@ -774,35 +776,38 @@ xloadcolor(int i, const char *name, Color *ncolor) | |
82 return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); | |
83 } | |
84 | |
85 +void | |
86 +xloadalpha(void) | |
87 +{ | |
88 + float const usedAlpha = focused ? alpha : alphaUnfocused; | |
89 + if (opt_alpha) alpha = strtof(opt_alpha, NULL); | |
90 + dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedA… | |
91 + dc.col[defaultbg].pixel &= 0x00FFFFFF; | |
92 + dc.col[defaultbg].pixel |= (unsigned char)(0xff * usedAlpha) <<… | |
93 +} | |
94 + | |
95 void | |
96 xloadcols(void) | |
97 { | |
98 - int i; | |
99 static int loaded; | |
100 Color *cp; | |
101 | |
102 - if (loaded) { | |
103 - for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp) | |
104 - XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); | |
105 - } else { | |
106 - dc.collen = MAX(LEN(colorname), 256); | |
107 - dc.col = xmalloc(dc.collen * sizeof(Color)); | |
108 + if (!loaded) { | |
109 + dc.collen = 1 + (defaultbg = MAX(LEN(colorname), 256)); | |
110 + dc.col = xmalloc((dc.collen) * sizeof(Color)); | |
111 } | |
112 | |
113 - for (i = 0; i < dc.collen; i++) | |
114 + for (int i = 0; i+1 < dc.collen; ++i) | |
115 if (!xloadcolor(i, NULL, &dc.col[i])) { | |
116 if (colorname[i]) | |
117 die("could not allocate color '%s'\n", … | |
118 else | |
119 die("could not allocate color %d\n", i); | |
120 } | |
121 + if (dc.collen) // cannot die, as the color is already loaded. | |
122 + xloadcolor(focused ?bg :bgUnfocused, NULL, &dc.col[defa… | |
123 | |
124 - /* set alpha value of bg color */ | |
125 - if (opt_alpha) | |
126 - alpha = strtof(opt_alpha, NULL); | |
127 - dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha… | |
128 - dc.col[defaultbg].pixel &= 0x00FFFFFF; | |
129 - dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24; | |
130 + xloadalpha(); | |
131 loaded = 1; | |
132 } | |
133 | |
134 @@ -1747,12 +1752,22 @@ focus(XEvent *ev) | |
135 xseturgency(0); | |
136 if (IS_SET(MODE_FOCUS)) | |
137 ttywrite("\033[I", 3, 0); | |
138 + if (!focused) { | |
139 + focused = 1; | |
140 + xloadcols(); | |
141 + tfulldirt(); | |
142 + } | |
143 } else { | |
144 if (xw.ime.xic) | |
145 XUnsetICFocus(xw.ime.xic); | |
146 win.mode &= ~MODE_FOCUSED; | |
147 if (IS_SET(MODE_FOCUS)) | |
148 ttywrite("\033[O", 3, 0); | |
149 + if (focused) { | |
150 + focused = 0; | |
151 + xloadcols(); | |
152 + tfulldirt(); | |
153 + } | |
154 } | |
155 } | |
156 | |
157 @@ -2065,6 +2080,7 @@ run: | |
158 XSetLocaleModifiers(""); | |
159 cols = MAX(cols, 1); | |
160 rows = MAX(rows, 1); | |
161 + defaultbg = MAX(LEN(colorname), 256); | |
162 tnew(cols, rows); | |
163 xinit(cols, rows); | |
164 xsetenv(); | |
165 -- | |
166 2.28.0 | |
167 |