-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-st-alphaFocusHighlight-20200212-2b8333f.diff
342 lines (307 loc) · 9.28 KB
/
02-st-alphaFocusHighlight-20200212-2b8333f.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
From 49fbc3f0a3d3524fa37ba4c0129425394b84feed Mon Sep 17 00:00:00 2001
From: Julius Huelsmann <[email protected]>
Date: Wed, 6 Nov 2019 21:59:28 +0100
Subject: [PATCH 1/3] [PATCH:FOCUS]: first version
---
config.def.h | 7 ++++++-
config.mk | 2 +-
st.h | 2 ++
x.c | 59 +++++++++++++++++++++++++++++++++++++++-------------
4 files changed, 54 insertions(+), 16 deletions(-)
diff --git a/config.def.h b/config.def.h
index 6ebea98..16f1ebd 100644
--- a/config.def.h
+++ b/config.def.h
@@ -82,6 +82,10 @@ char *termname = "st-256color";
*/
unsigned int tabspaces = 8;
+/* bg opacity */
+float alpha = 0.5; //< alpha value used when the window is focused.
+float alphaUnfocussed = 0.2; //< alpha value used when the focus is lost
+
/* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = {
/* 8 normal colors */
@@ -109,6 +113,7 @@ static const char *colorname[] = {
/* more colors can be added after 255 to use with DefaultXX */
"#cccccc",
"#555555",
+ "black",
};
@@ -117,7 +122,7 @@ static const char *colorname[] = {
* foreground, background, cursor, reverse cursor
*/
unsigned int defaultfg = 7;
-unsigned int defaultbg = 0;
+unsigned int defaultbg = 258;
static unsigned int defaultcs = 256;
static unsigned int defaultrcs = 257;
diff --git a/config.mk b/config.mk
index 0cbb002..1d2f0e2 100644
--- a/config.mk
+++ b/config.mk
@@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
INCS = -I$(X11INC) \
`$(PKG_CONFIG) --cflags fontconfig` \
`$(PKG_CONFIG) --cflags freetype2`
-LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
+LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
`$(PKG_CONFIG) --libs fontconfig` \
`$(PKG_CONFIG) --libs freetype2`
diff --git a/st.h b/st.h
index 4da3051..0bc69f8 100644
--- a/st.h
+++ b/st.h
@@ -120,3 +120,5 @@ extern char *termname;
extern unsigned int tabspaces;
extern unsigned int defaultfg;
extern unsigned int defaultbg;
+extern float alpha;
+extern float alphaUnfocussed;
diff --git a/x.c b/x.c
index 5828a3b..45bc960 100644
--- a/x.c
+++ b/x.c
@@ -4,6 +4,7 @@
#include <limits.h>
#include <locale.h>
#include <signal.h>
+#include <stdbool.h>
#include <sys/select.h>
#include <time.h>
#include <unistd.h>
@@ -98,6 +99,7 @@ typedef struct {
XSetWindowAttributes attrs;
int scr;
int isfixed; /* is fixed geometry? */
+ int depth; /* bit depth */
int l, t; /* left and top offset */
int gm; /* geometry mask */
} XWindow;
@@ -233,6 +235,7 @@ static char *usedfont = NULL;
static double usedfontsize = 0;
static double defaultfontsize = 0;
+static char *opt_alpha = NULL;
static char *opt_class = NULL;
static char **opt_cmd = NULL;
static char *opt_embed = NULL;
@@ -241,6 +244,7 @@ static char *opt_io = NULL;
static char *opt_line = NULL;
static char *opt_name = NULL;
static char *opt_title = NULL;
+static bool focused = true;
static int oldbutton = 3; /* button event on startup: 3 = release */
@@ -692,7 +696,7 @@ xresize(int col, int row)
XFreePixmap(xw.dpy, xw.buf);
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
- DefaultDepth(xw.dpy, xw.scr));
+ xw.depth);
XftDrawChange(xw.draw, xw.buf);
xclear(0, 0, win.w, win.h);
@@ -752,6 +756,14 @@ xloadcols(void)
else
die("could not allocate color %d\n", i);
}
+
+ /* set alpha value of bg color */
+ if (opt_alpha)
+ alpha = strtof(opt_alpha, NULL);
+ float const usedAlpha = focused ? alpha : alphaUnfocussed;
+ dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedAlpha);
+ dc.col[defaultbg].pixel &= 0x00FFFFFF;
+ dc.col[defaultbg].pixel |= (unsigned char)(0xff * usedAlpha) << 24;
loaded = 1;
}
@@ -1044,11 +1056,23 @@ xinit(int cols, int rows)
Window parent;
pid_t thispid = getpid();
XColor xmousefg, xmousebg;
+ XWindowAttributes attr;
+ XVisualInfo vis;
if (!(xw.dpy = XOpenDisplay(NULL)))
die("can't open display\n");
xw.scr = XDefaultScreen(xw.dpy);
- xw.vis = XDefaultVisual(xw.dpy, xw.scr);
+
+ if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
+ parent = XRootWindow(xw.dpy, xw.scr);
+ xw.depth = 32;
+ } else {
+ XGetWindowAttributes(xw.dpy, parent, &attr);
+ xw.depth = attr.depth;
+ }
+
+ XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
+ xw.vis = vis.visual;
/* font */
if (!FcInit())
@@ -1058,7 +1082,7 @@ xinit(int cols, int rows)
xloadfonts(usedfont, 0);
/* colors */
- xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
+ xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
xloadcols();
/* adjust fixed window geometry */
@@ -1078,19 +1102,15 @@ xinit(int cols, int rows)
| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
xw.attrs.colormap = xw.cmap;
- if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
- parent = XRootWindow(xw.dpy, xw.scr);
xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
- win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
+ win.w, win.h, 0, xw.depth, InputOutput,
xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
| CWEventMask | CWColormap, &xw.attrs);
memset(&gcvalues, 0, sizeof(gcvalues));
gcvalues.graphics_exposures = False;
- dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
- &gcvalues);
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
- DefaultDepth(xw.dpy, xw.scr));
+ xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
+ dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
@@ -1663,13 +1683,21 @@ focus(XEvent *ev)
XSetICFocus(xw.xic);
win.mode |= MODE_FOCUSED;
xseturgency(0);
- if (IS_SET(MODE_FOCUS))
- ttywrite("\033[I", 3, 0);
+ if (IS_SET(MODE_FOCUS)) { ttywrite("\033[I", 3, 0); }
+ if (!focused) {
+ focused = true;
+ xloadcols();
+ redraw();
+ }
} else {
XUnsetICFocus(xw.xic);
win.mode &= ~MODE_FOCUSED;
- if (IS_SET(MODE_FOCUS))
- ttywrite("\033[O", 3, 0);
+ if (IS_SET(MODE_FOCUS)) { ttywrite("\033[O", 3, 0); }
+ if (focused) {
+ focused = false;
+ xloadcols();
+ redraw();
+ }
}
}
@@ -1925,6 +1953,9 @@ main(int argc, char *argv[])
case 'a':
allowaltscreen = 0;
break;
+ case 'A':
+ opt_alpha = EARGF(usage());
+ break;
case 'c':
opt_class = EARGF(usage());
break;
--
2.25.0
From b442038e2f28b427f044a6bbd80481251ab532ad Mon Sep 17 00:00:00 2001
From: "gloom @ t440p" <gloom@t440p>
Date: Tue, 17 Dec 2019 18:43:31 +0800
Subject: [PATCH 2/3] merge: fix: do not reset terminal colors when
focus/unfocus
when using scripts which changes shell's
default ANSI colors like base16-shell
then focus/unfocus should not reset
foreground colors to default ones
---
x.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/x.c b/x.c
index 45bc960..7482adb 100644
--- a/x.c
+++ b/x.c
@@ -734,6 +734,20 @@ xloadcolor(int i, const char *name, Color *ncolor)
return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
}
+void
+xloadalpha(void)
+{
+ /* set alpha value of bg color */
+ if (opt_alpha)
+ alpha = strtof(opt_alpha, NULL);
+
+ float const usedAlpha = focused ? alpha : alphaUnfocussed;
+
+ dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedAlpha);
+ dc.col[defaultbg].pixel &= 0x00FFFFFF;
+ dc.col[defaultbg].pixel |= (unsigned char)(0xff * usedAlpha) << 24;
+}
+
void
xloadcols(void)
{
@@ -749,7 +763,7 @@ xloadcols(void)
dc.col = xmalloc(dc.collen * sizeof(Color));
}
- for (i = 0; i < dc.collen; i++)
+ for (i = 0; i < dc.collen; i++)
if (!xloadcolor(i, NULL, &dc.col[i])) {
if (colorname[i])
die("could not allocate color '%s'\n", colorname[i]);
@@ -757,13 +771,7 @@ xloadcols(void)
die("could not allocate color %d\n", i);
}
- /* set alpha value of bg color */
- if (opt_alpha)
- alpha = strtof(opt_alpha, NULL);
- float const usedAlpha = focused ? alpha : alphaUnfocussed;
- dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedAlpha);
- dc.col[defaultbg].pixel &= 0x00FFFFFF;
- dc.col[defaultbg].pixel |= (unsigned char)(0xff * usedAlpha) << 24;
+ xloadalpha();
loaded = 1;
}
@@ -1683,19 +1691,21 @@ focus(XEvent *ev)
XSetICFocus(xw.xic);
win.mode |= MODE_FOCUSED;
xseturgency(0);
- if (IS_SET(MODE_FOCUS)) { ttywrite("\033[I", 3, 0); }
+ if (IS_SET(MODE_FOCUS))
+ ttywrite("\033[I", 3, 0);
if (!focused) {
focused = true;
- xloadcols();
+ xloadalpha();
redraw();
}
} else {
XUnsetICFocus(xw.xic);
win.mode &= ~MODE_FOCUSED;
- if (IS_SET(MODE_FOCUS)) { ttywrite("\033[O", 3, 0); }
+ if (IS_SET(MODE_FOCUS))
+ ttywrite("\033[O", 3, 0);
if (focused) {
focused = false;
- xloadcols();
+ xloadalpha();
redraw();
}
}
--
2.25.0
From dffad320251fbab67181a005436f320717658cf9 Mon Sep 17 00:00:00 2001
From: M <[email protected]>
Date: Sun, 2 Feb 2020 14:20:52 +0100
Subject: [PATCH 3/3] Remove stray trailing whitespace
---
x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/x.c b/x.c
index 7482adb..cfbe64d 100644
--- a/x.c
+++ b/x.c
@@ -763,7 +763,7 @@ xloadcols(void)
dc.col = xmalloc(dc.collen * sizeof(Color));
}
- for (i = 0; i < dc.collen; i++)
+ for (i = 0; i < dc.collen; i++)
if (!xloadcolor(i, NULL, &dc.col[i])) {
if (colorname[i])
die("could not allocate color '%s'\n", colorname[i]);
--
2.25.0