aboutsummaryrefslogtreecommitdiffstats
path: root/font.c
diff options
context:
space:
mode:
authorokan2012-12-17 02:28:45 +0000
committerokan2012-12-17 02:28:45 +0000
commit413da1eebb4612d1fe0c55b2b9a5957b5379285d (patch)
treed4ab320aa75fefece4189a84bf0e697503416b9e /font.c
parent168c81d59eaf5d21c57d30f3ddb5674168a753f8 (diff)
downloadcwm-413da1eebb4612d1fe0c55b2b9a5957b5379285d.tar.gz
non-trivial menu drawing rewrite, moving to Xft and solving various
font/color drawing issues; from Alexander Polakov
Diffstat (limited to '')
-rw-r--r--font.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/font.c b/font.c
index abec848..7268b7e 100644
--- a/font.c
+++ b/font.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: font.c,v 1.20 2012/11/28 14:14:44 okan Exp $
+ * $OpenBSD: font.c,v 1.21 2012/12/17 02:28:45 okan Exp $
*/
#include <sys/param.h>
@@ -49,20 +49,37 @@ font_height(struct screen_ctx *sc)
}
void
-font_init(struct screen_ctx *sc, const char *name, const char *color)
+font_init(struct screen_ctx *sc, const char *name, const char **color)
{
+ int i;
+ XRenderColor c;
+
sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin,
DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which));
if (sc->xftdraw == NULL)
errx(1, "XftDrawCreate");
- if (!XftColorAllocName(X_Dpy, DefaultVisual(X_Dpy, sc->which),
- DefaultColormap(X_Dpy, sc->which), color, &sc->xftcolor))
- errx(1, "XftColorAllocName");
-
sc->font = XftFontOpenName(X_Dpy, sc->which, name);
if (sc->font == NULL)
errx(1, "XftFontOpenName");
+ for(i = 0; i < CWM_COLOR_MENU_MAX; i++) {
+ if (*color[i] == '\0')
+ break;
+ if (!XftColorAllocName(X_Dpy, DefaultVisual(X_Dpy, sc->which),
+ DefaultColormap(X_Dpy, sc->which), 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, DefaultVisual(X_Dpy, sc->which),
+ DefaultColormap(X_Dpy, sc->which), &c,
+ &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
+ errx(1, "XftColorAllocValue");
}
int
@@ -78,9 +95,12 @@ font_width(struct screen_ctx *sc, const char *text, int len)
void
font_draw(struct screen_ctx *sc, const char *text, int len,
- Drawable d, int x, int y)
+ Drawable d, int active, int x, int y)
{
+ int color;
+
+ color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
XftDrawChange(sc->xftdraw, d);
- XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor, sc->font, x, y,
+ XftDrawStringUtf8(sc->xftdraw, &sc->xftcolor[color], sc->font, x, y,
(const FcChar8*)text, len);
}