Add support for additional alpha when the term-window is not focused
This commit is contained in:
parent
7e6e779130
commit
69925ee23b
@ -1,5 +1,6 @@
|
|||||||
!! Transparency (0-1):
|
!! Transparency (0-1):
|
||||||
st.alpha: 0.92
|
st.alpha: 0.92
|
||||||
|
st.alphaUnfocus: 0.62
|
||||||
|
|
||||||
!! Set a default font and font size as below:
|
!! Set a default font and font size as below:
|
||||||
st.font: Monospace-11;
|
st.font: Monospace-11;
|
||||||
|
3
config.h
3
config.h
@ -108,6 +108,7 @@ unsigned int tabspaces = 8;
|
|||||||
|
|
||||||
/* bg opacity */
|
/* bg opacity */
|
||||||
float alpha = 0.8;
|
float alpha = 0.8;
|
||||||
|
float alphaUnfocus = 0.8;
|
||||||
|
|
||||||
/* Terminal colors (16 first used in escape sequence) */
|
/* Terminal colors (16 first used in escape sequence) */
|
||||||
static const char *colorname[] = {
|
static const char *colorname[] = {
|
||||||
@ -144,6 +145,7 @@ unsigned int defaultfg = 259;
|
|||||||
unsigned int defaultbg = 258;
|
unsigned int defaultbg = 258;
|
||||||
unsigned int defaultcs = 256;
|
unsigned int defaultcs = 256;
|
||||||
unsigned int defaultrcs = 257;
|
unsigned int defaultrcs = 257;
|
||||||
|
unsigned int background = 258;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default shape of cursor
|
* Default shape of cursor
|
||||||
@ -217,6 +219,7 @@ ResourcePref resources[] = {
|
|||||||
{ "cwscale", FLOAT, &cwscale },
|
{ "cwscale", FLOAT, &cwscale },
|
||||||
{ "chscale", FLOAT, &chscale },
|
{ "chscale", FLOAT, &chscale },
|
||||||
{ "alpha", FLOAT, &alpha },
|
{ "alpha", FLOAT, &alpha },
|
||||||
|
{ "alphaUnfocus", FLOAT, &alphaUnfocus },
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
1
st.c
1
st.c
@ -201,7 +201,6 @@ static void tsetscroll(int, int);
|
|||||||
static void tswapscreen(void);
|
static void tswapscreen(void);
|
||||||
static void tsetmode(int, int, int *, int);
|
static void tsetmode(int, int, int *, int);
|
||||||
static int twrite(const char *, int, int);
|
static int twrite(const char *, int, int);
|
||||||
static void tfulldirt(void);
|
|
||||||
static void tcontrolcode(uchar );
|
static void tcontrolcode(uchar );
|
||||||
static void tdectest(char );
|
static void tdectest(char );
|
||||||
static void tdefutf8(char);
|
static void tdefutf8(char);
|
||||||
|
2
st.h
2
st.h
@ -82,6 +82,7 @@ typedef union {
|
|||||||
|
|
||||||
void die(const char *, ...);
|
void die(const char *, ...);
|
||||||
void redraw(void);
|
void redraw(void);
|
||||||
|
void tfulldirt(void);
|
||||||
void draw(void);
|
void draw(void);
|
||||||
|
|
||||||
void externalpipe(const Arg *);
|
void externalpipe(const Arg *);
|
||||||
@ -138,4 +139,5 @@ extern unsigned int tabspaces;
|
|||||||
extern unsigned int defaultfg;
|
extern unsigned int defaultfg;
|
||||||
extern unsigned int defaultbg;
|
extern unsigned int defaultbg;
|
||||||
extern float alpha;
|
extern float alpha;
|
||||||
|
extern float alphaUnfocus;
|
||||||
extern const int boxdraw, boxdraw_bold, boxdraw_braille;
|
extern const int boxdraw, boxdraw_bold, boxdraw_braille;
|
||||||
|
42
x.c
42
x.c
@ -272,6 +272,8 @@ static char *opt_line = NULL;
|
|||||||
static char *opt_name = NULL;
|
static char *opt_name = NULL;
|
||||||
static char *opt_title = NULL;
|
static char *opt_title = NULL;
|
||||||
|
|
||||||
|
static int focused = 0;
|
||||||
|
|
||||||
static int oldbutton = 3; /* button event on startup: 3 = release */
|
static int oldbutton = 3; /* button event on startup: 3 = release */
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -807,6 +809,16 @@ xloadcolor(int i, const char *name, Color *ncolor)
|
|||||||
return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
|
return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xloadalpha(void)
|
||||||
|
{
|
||||||
|
float const usedAlpha = focused ? alpha : alphaUnfocus;
|
||||||
|
if (opt_alpha) alpha = strtof(opt_alpha, NULL);
|
||||||
|
dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedAlpha);
|
||||||
|
dc.col[defaultbg].pixel &= 0x00FFFFFF;
|
||||||
|
dc.col[defaultbg].pixel |= (unsigned char)(0xff * usedAlpha) << 24;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xloadcols(void)
|
xloadcols(void)
|
||||||
{
|
{
|
||||||
@ -814,15 +826,12 @@ xloadcols(void)
|
|||||||
static int loaded;
|
static int loaded;
|
||||||
Color *cp;
|
Color *cp;
|
||||||
|
|
||||||
if (loaded) {
|
if (!loaded) {
|
||||||
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
|
dc.collen = 1 + (defaultbg = MAX(LEN(colorname), 256));
|
||||||
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
|
|
||||||
} else {
|
|
||||||
dc.collen = MAX(LEN(colorname), 256);
|
|
||||||
dc.col = xmalloc(dc.collen * sizeof(Color));
|
dc.col = xmalloc(dc.collen * sizeof(Color));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < dc.collen; i++)
|
for (i = 0; i+1 < dc.collen; i++)
|
||||||
if (!xloadcolor(i, NULL, &dc.col[i])) {
|
if (!xloadcolor(i, NULL, &dc.col[i])) {
|
||||||
if (colorname[i])
|
if (colorname[i])
|
||||||
die("could not allocate color '%s'\n", colorname[i]);
|
die("could not allocate color '%s'\n", colorname[i]);
|
||||||
@ -830,12 +839,10 @@ xloadcols(void)
|
|||||||
die("could not allocate color %d\n", i);
|
die("could not allocate color %d\n", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set alpha value of bg color */
|
if (dc.collen) // cannot die, as the color is already loaded.
|
||||||
if (opt_alpha)
|
xloadcolor(background, NULL, &dc.col[defaultbg]);
|
||||||
alpha = strtof(opt_alpha, NULL);
|
|
||||||
dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
|
xloadalpha();
|
||||||
dc.col[defaultbg].pixel &= 0x00FFFFFF;
|
|
||||||
dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
|
|
||||||
loaded = 1;
|
loaded = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1910,12 +1917,22 @@ focus(XEvent *ev)
|
|||||||
xseturgency(0);
|
xseturgency(0);
|
||||||
if (IS_SET(MODE_FOCUS))
|
if (IS_SET(MODE_FOCUS))
|
||||||
ttywrite("\033[I", 3, 0);
|
ttywrite("\033[I", 3, 0);
|
||||||
|
if (!focused) {
|
||||||
|
focused = 1;
|
||||||
|
xloadcols();
|
||||||
|
tfulldirt();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (xw.ime.xic)
|
if (xw.ime.xic)
|
||||||
XUnsetICFocus(xw.ime.xic);
|
XUnsetICFocus(xw.ime.xic);
|
||||||
win.mode &= ~MODE_FOCUSED;
|
win.mode &= ~MODE_FOCUSED;
|
||||||
if (IS_SET(MODE_FOCUS))
|
if (IS_SET(MODE_FOCUS))
|
||||||
ttywrite("\033[O", 3, 0);
|
ttywrite("\033[O", 3, 0);
|
||||||
|
if (focused) {
|
||||||
|
focused = 0;
|
||||||
|
xloadcols();
|
||||||
|
tfulldirt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2280,6 +2297,7 @@ run:
|
|||||||
config_init();
|
config_init();
|
||||||
cols = MAX(cols, 1);
|
cols = MAX(cols, 1);
|
||||||
rows = MAX(rows, 1);
|
rows = MAX(rows, 1);
|
||||||
|
defaultbg = MAX(LEN(colorname), 256);
|
||||||
tnew(cols, rows);
|
tnew(cols, rows);
|
||||||
xinit(cols, rows);
|
xinit(cols, rows);
|
||||||
xsetenv();
|
xsetenv();
|
||||||
|
Loading…
Reference in New Issue
Block a user