summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2013-05-19 23:09:59 +0000
committerokan <okan>2013-05-19 23:09:59 +0000
commitdac00a232f975967dec9ae8e838b069ec01e6c62 (patch)
tree8f27cc8716cdd65e644fb183c4bbe3cf89bc62e0
parentc84145661e14cc62032f30c6a8c744ba84b95601 (diff)
downloadcwm-dac00a232f975967dec9ae8e838b069ec01e6c62.tar.gz
cwm-dac00a232f975967dec9ae8e838b069ec01e6c62.tar.xz
cwm-dac00a232f975967dec9ae8e838b069ec01e6c62.zip
- 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)
-rw-r--r--calmwm.h29
-rw-r--r--client.c8
-rw-r--r--conf.c47
-rw-r--r--font.c22
-rw-r--r--parse.y21
-rw-r--r--xutil.c24
6 files changed, 61 insertions, 90 deletions
diff --git a/calmwm.h b/calmwm.h
index cf980e1..ebc5bd0 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -85,20 +85,16 @@ union arg {
 	int	 i;
 };
 
-enum menucolor {
-	CWM_COLOR_MENU_FG,
-	CWM_COLOR_MENU_BG,
-	CWM_COLOR_MENU_FONT,
-	CWM_COLOR_MENU_FONT_SEL,
-	CWM_COLOR_MENU_MAX
-};
-
-enum bordercolor {
+enum color {
 	CWM_COLOR_BORDER_ACTIVE,
 	CWM_COLOR_BORDER_INACTIVE,
 	CWM_COLOR_BORDER_GROUP,
 	CWM_COLOR_BORDER_UNGROUP,
-	CWM_COLOR_BORDER_MAX
+	CWM_COLOR_MENU_FG,
+	CWM_COLOR_MENU_BG,
+	CWM_COLOR_MENU_FONT,
+	CWM_COLOR_MENU_FONT_SEL,
+	CWM_COLOR_MAX
 };
 
 struct geom {
@@ -213,13 +209,12 @@ struct screen_ctx {
 	Colormap		 colormap;
 	Window			 rootwin;
 	Window			 menuwin;
-	unsigned long		 color[CWM_COLOR_BORDER_MAX];
 	int			 cycling;
 	struct geom		 view; /* viewable area */
 	struct geom		 work; /* workable area, gap-applied */
 	struct gap		 gap;
 	struct cycle_entry_q	 mruq;
-	XftColor		 xftcolor[CWM_COLOR_MENU_MAX];
+	XftColor		 xftcolor[CWM_COLOR_MAX];
 	XftDraw			*xftdraw;
 	XftFont			*xftfont;
 	int			 xinerama_no;
@@ -293,8 +288,7 @@ struct conf {
 #define	CONF_SNAPDIST			0
 	int			 snapdist;
 	struct gap		 gap;
-	char			*color[CWM_COLOR_BORDER_MAX];
-	char		 	*menucolor[CWM_COLOR_MENU_MAX];
+	char			*color[CWM_COLOR_MAX];
 	char			 termpath[MAXPATHLEN];
 	char			 lockpath[MAXPATHLEN];
 	char			 known_hosts[MAXPATHLEN];
@@ -452,8 +446,7 @@ void			 conf_ungrab(struct conf *, struct keybinding *);
 
 void			 font_draw(struct screen_ctx *, const char *,
 			     Drawable, int, int, int);
-void			 font_init(struct screen_ctx *, const char *,
-			     const char **);
+void			 font_init(struct screen_ctx *, const char *);
 int			 font_width(XftFont *, const char *, int);
 
 void			 xev_loop(void);
@@ -462,7 +455,6 @@ void			 xu_btn_grab(Window, int, u_int);
 void			 xu_btn_ungrab(Window, int, u_int);
 void			 xu_configure(struct client_ctx *);
 void			 xu_getatoms(void);
-unsigned long		 xu_getcolor(struct screen_ctx *, char *);
 int			 xu_getprop(Window, Atom, Atom, long, u_char **);
 int			 xu_get_wm_state(Window, int *);
 int			 xu_getstrprop(Window, Atom, char **);
@@ -475,8 +467,7 @@ void			 xu_ptr_setpos(Window, int, int);
 void			 xu_ptr_ungrab(void);
 void			 xu_sendmsg(Window, Atom, long);
 void			 xu_set_wm_state(Window win, int);
-void 			 xu_xorcolor(XRenderColor, XRenderColor,
-			     XRenderColor *);
+void 			 xu_xorcolor(XftColor, XftColor, XftColor *);
 
 void			 xu_ewmh_net_supported(struct screen_ctx *);
 void			 xu_ewmh_net_supported_wm_check(struct screen_ctx *);
diff --git a/client.c b/client.c
index 6001372..9ebd8bc 100644
--- a/client.c
+++ b/client.c
@@ -480,17 +480,17 @@ client_draw_border(struct client_ctx *cc)
 	if (cc->active)
 		switch (cc->flags & CLIENT_HIGHLIGHT) {
 		case CLIENT_GROUP:
-			pixel = sc->color[CWM_COLOR_BORDER_GROUP];
+			pixel = sc->xftcolor[CWM_COLOR_BORDER_GROUP].pixel;
 			break;
 		case CLIENT_UNGROUP:
-			pixel = sc->color[CWM_COLOR_BORDER_UNGROUP];
+			pixel = sc->xftcolor[CWM_COLOR_BORDER_UNGROUP].pixel;
 			break;
 		default:
-			pixel = sc->color[CWM_COLOR_BORDER_ACTIVE];
+			pixel = sc->xftcolor[CWM_COLOR_BORDER_ACTIVE].pixel;
 			break;
 		}
 	else
-		pixel = sc->color[CWM_COLOR_BORDER_INACTIVE];
+		pixel = sc->xftcolor[CWM_COLOR_BORDER_INACTIVE].pixel;
 
 	XSetWindowBorderWidth(X_Dpy, cc->win, cc->bwidth);
 	XSetWindowBorder(X_Dpy, cc->win, pixel);
diff --git a/conf.c b/conf.c
index 698ab4c..657c686 100644
--- a/conf.c
+++ b/conf.c
@@ -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] = {
-	"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] = {
+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 */
 };
 
 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_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;
 
-	for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
-		sc->color[i] = xu_getcolor(sc, Conf.color[i]);
+	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);
diff --git a/font.c b/font.c
index e2b68c0..f4251d9 100644
--- a/font.c
+++ b/font.c
@@ -31,11 +31,8 @@
 #include "calmwm.h"
 
 void
-font_init(struct screen_ctx *sc, const char *name, const char **color)
+font_init(struct screen_ctx *sc, const char *name)
 {
-	int		 i;
-	XRenderColor	 c;
-
 	sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin,
 	    sc->visual, sc->colormap);
 	if (sc->xftdraw == NULL)
@@ -44,23 +41,6 @@ font_init(struct screen_ctx *sc, const char *name, const char **color)
 	sc->xftfont = XftFontOpenName(X_Dpy, sc->which, name);
 	if (sc->xftfont == NULL)
 		errx(1, "XftFontOpenName");
-
-	for (i = 0; i < CWM_COLOR_MENU_MAX; i++) {
-		if (*color[i] == '\0')
-			break;
-		if (!XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
-			color[i], &sc->xftcolor[i]))
-			errx(1, "XftColorAllocName");
-	}
-	if (i == CWM_COLOR_MENU_MAX)
-		return;
-
-	xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG].color,
-		    sc->xftcolor[CWM_COLOR_MENU_FG].color, &c);
-	xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT].color, c, &c);
-	if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap,
-		&c, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
-		errx(1, "XftColorAllocValue");
 }
 
 int
diff --git a/parse.y b/parse.y
index 9de56da..e0c13bb 100644
--- a/parse.y
+++ b/parse.y
@@ -198,20 +198,20 @@ colors		: ACTIVEBORDER STRING {
 			conf->color[CWM_COLOR_BORDER_UNGROUP] = $2;
 		}
 		| MENUBG STRING {
-			free(conf->menucolor[CWM_COLOR_MENU_BG]);
-			conf->menucolor[CWM_COLOR_MENU_BG] = $2;
+			free(conf->color[CWM_COLOR_MENU_BG]);
+			conf->color[CWM_COLOR_MENU_BG] = $2;
 		}
 		| MENUFG STRING {
-			free(conf->menucolor[CWM_COLOR_MENU_FG]);
-			conf->menucolor[CWM_COLOR_MENU_FG] = $2;
+			free(conf->color[CWM_COLOR_MENU_FG]);
+			conf->color[CWM_COLOR_MENU_FG] = $2;
 		}
 		| FONTCOLOR STRING {
-			free(conf->menucolor[CWM_COLOR_MENU_FONT]);
-			conf->menucolor[CWM_COLOR_MENU_FONT] = $2;
+			free(conf->color[CWM_COLOR_MENU_FONT]);
+			conf->color[CWM_COLOR_MENU_FONT] = $2;
 		}
 		| FONTSELCOLOR STRING {
-			free(conf->menucolor[CWM_COLOR_MENU_FONT_SEL]);
-			conf->menucolor[CWM_COLOR_MENU_FONT_SEL] = $2;
+			free(conf->color[CWM_COLOR_MENU_FONT_SEL]);
+			conf->color[CWM_COLOR_MENU_FONT_SEL] = $2;
 		}
 		;
 %%
@@ -589,12 +589,9 @@ parse_config(const char *filename, struct conf *xconf)
 		(void)strlcpy(xconf->lockpath, conf->lockpath,
 		    sizeof(xconf->lockpath));
 
-		for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
+		for (i = 0; i < CWM_COLOR_MAX; i++)
 			xconf->color[i] = conf->color[i];
 
-		for (i = 0; i < CWM_COLOR_MENU_MAX; i++)
-			xconf->menucolor[i] = conf->menucolor[i];
-
 		xconf->font = conf->font;
 	}
 
diff --git a/xutil.c b/xutil.c
index d9f2106..bcc7366 100644
--- a/xutil.c
+++ b/xutil.c
@@ -420,24 +420,12 @@ xu_ewmh_net_wm_desktop(struct client_ctx *cc)
 	    XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1);
 }
 
-unsigned long
-xu_getcolor(struct screen_ctx *sc, char *name)
-{
-	XColor	 color, tmp;
-
-	if (!XAllocNamedColor(X_Dpy, sc->colormap, name, &color, &tmp)) {
-		warnx("XAllocNamedColor error: '%s'", name);
-		return (0);
-	}
-
-	return (color.pixel);
-}
-
 void
-xu_xorcolor(XRenderColor a, XRenderColor b, XRenderColor *r)
+xu_xorcolor(XftColor a, XftColor b, XftColor *r)
 {
-	r->red = a.red ^ b.red;
-	r->green = a.green ^ b.green;
-	r->blue = a.blue ^ b.blue;
-	r->alpha = 0xffff;
+	r->pixel = a.pixel ^ b.pixel;
+	r->color.red = a.color.red ^ b.color.red;
+	r->color.green = a.color.green ^ b.color.green;
+	r->color.blue = a.color.blue ^ b.color.blue;
+	r->color.alpha = 0xffff;
 }