summaryrefslogtreecommitdiff
path: root/x.c
diff options
context:
space:
mode:
Diffstat (limited to 'x.c')
-rw-r--r--x.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/x.c b/x.c
index 696ade9..d1721d7 100644
--- a/x.c
+++ b/x.c
@@ -272,6 +272,8 @@ static char *opt_line = NULL;
static char *opt_name = NULL;
static char *opt_title = NULL;
+static int focused = 0;
+
static int oldbutton = 3; /* button event on startup: 3 = release */
void
@@ -808,21 +810,28 @@ xloadcolor(int i, const char *name, Color *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
xloadcols(void)
{
int i;
static int loaded;
Color *cp;
- if (loaded) {
- for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
- XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
- } else {
- dc.collen = MAX(LEN(colorname), 256);
+ if (!loaded) {
+ dc.collen = 1 + (defaultbg = MAX(LEN(colorname), 256));
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 (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);
}
- /* set alpha value of bg color */
- if (opt_alpha)
- alpha = strtof(opt_alpha, NULL);
- dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
- dc.col[defaultbg].pixel &= 0x00FFFFFF;
- dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
+ if (dc.collen) // cannot die, as the color is already loaded.
+ xloadcolor(background, NULL, &dc.col[defaultbg]);
+
+ xloadalpha();
loaded = 1;
}
@@ -1910,12 +1917,22 @@ focus(XEvent *ev)
xseturgency(0);
if (IS_SET(MODE_FOCUS))
ttywrite("\033[I", 3, 0);
+ if (!focused) {
+ focused = 1;
+ xloadcols();
+ tfulldirt();
+ }
} else {
if (xw.ime.xic)
XUnsetICFocus(xw.ime.xic);
win.mode &= ~MODE_FOCUSED;
if (IS_SET(MODE_FOCUS))
ttywrite("\033[O", 3, 0);
+ if (focused) {
+ focused = 0;
+ xloadcols();
+ tfulldirt();
+ }
}
}
@@ -2280,6 +2297,7 @@ run:
config_init();
cols = MAX(cols, 1);
rows = MAX(rows, 1);
+ defaultbg = MAX(LEN(colorname), 256);
tnew(cols, rows);
xinit(cols, rows);
xsetenv();