- switch border colors to Xft

- merge border/menu color structures/functions since they now both use Xft
- switch xu_xorcolor to operating on XftColor instead of just
  XRenderColor (basically adding pixel)
- if color name allocation fails, revert back to default (this, along
  with font validation should occur during config parse, but we don't
  have screens setup yet - likely to change at some point)
This commit is contained in:
okan
2013-05-19 23:09:59 +00:00
parent c84145661e
commit dac00a232f
6 changed files with 61 additions and 90 deletions

47
conf.c
View File

@@ -84,31 +84,49 @@ conf_ignore(struct conf *c, char *val)
TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry);
}
static char *menu_color_binds[CWM_COLOR_MENU_MAX] = {
static char *color_binds[CWM_COLOR_MAX] = {
"#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */
"#666666", /* CWM_COLOR_BORDER_INACTIVE */
"blue", /* CWM_COLOR_BORDER_GROUP */
"red", /* CWM_COLOR_BORDER_UNGROUP */
"black", /* CWM_COLOR_MENU_FG */
"white", /* CWM_COLOR_MENU_BG */
"black", /* CWM_COLOR_MENU_FONT */
"", /* CWM_COLOR_MENU_FONT_SEL */
};
static char *color_binds[CWM_COLOR_BORDER_MAX] = {
"#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */
"#666666", /* CWM_COLOR_BORDER_INACTIVE */
"blue", /* CWM_COLOR_BORDER_GROUP */
"red", /* CWM_COLOR_BORDER_UNGROUP */
};
void
conf_screen(struct screen_ctx *sc)
{
int i;
int i;
XftColor xc;
sc->gap = Conf.gap;
font_init(sc, Conf.font, (const char **)Conf.menucolor);
font_init(sc, Conf.font);
for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
sc->color[i] = xu_getcolor(sc, Conf.color[i]);
for (i = 0; i < CWM_COLOR_MAX; i++) {
if (*Conf.color[i] == '\0')
break;
if (XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
Conf.color[i], &xc)) {
sc->xftcolor[i] = xc;
XftColorFree(X_Dpy, sc->visual, sc->colormap, &xc);
} else {
warnx("XftColorAllocName: '%s'", Conf.color[i]);
XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
color_binds[i], &sc->xftcolor[i]);
}
}
if (i == CWM_COLOR_MAX)
return;
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG],
sc->xftcolor[CWM_COLOR_MENU_FG], &xc);
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT], xc, &xc);
if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap,
&xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
warnx("XftColorAllocValue: '%s'", Conf.color[i]);
}
static struct {
@@ -210,9 +228,6 @@ conf_init(struct conf *c)
for (i = 0; i < nitems(color_binds); i++)
c->color[i] = xstrdup(color_binds[i]);
for (i = 0; i < nitems(menu_color_binds); i++)
c->menucolor[i] = xstrdup(menu_color_binds[i]);
/* Default term/lock */
(void)strlcpy(c->termpath, "xterm", sizeof(c->termpath));
(void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
@@ -260,7 +275,7 @@ conf_clear(struct conf *c)
free(mb);
}
for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
for (i = 0; i < CWM_COLOR_MAX; i++)
free(c->color[i]);
free(c->font);