summary refs log tree commit diff
path: root/menu.c
diff options
context:
space:
mode:
authorokan <okan>2016-09-30 15:12:19 +0000
committerokan <okan>2016-09-30 15:12:19 +0000
commit8b26a43bf17b3834de3127408e7274e8effc9beb (patch)
treec17d225d7bc5d3815b94add0fb45eeb2aab8da7a /menu.c
parentf63b2e2341b8e883598ab33a46708ae315a63a99 (diff)
downloadcwm-8b26a43bf17b3834de3127408e7274e8effc9beb.tar.gz
cwm-8b26a43bf17b3834de3127408e7274e8effc9beb.tar.xz
cwm-8b26a43bf17b3834de3127408e7274e8effc9beb.zip
Replace mousefunc_sweep_draw() with a generic menu_windraw() using va
lists; use it appropriately for both window dimension and position in
the respective mousefunc calls.

ok bryent@
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/menu.c b/menu.c
index a84f578..80197b9 100644
--- a/menu.c
+++ b/menu.c
@@ -638,3 +638,35 @@ menuq_clear(struct menu_q *mq)
 		free(mi);
 	}
 }
+
+void
+menu_windraw(struct screen_ctx *sc, Window win, const char *fmt, ...)
+{
+	va_list			 ap;
+	int			 i;
+	char			*text;
+	XGlyphInfo		 extents;
+
+	va_start(ap, fmt);
+	i = vasprintf(&text, fmt, ap);
+	va_end(ap);
+
+	if (i < 0 || text == NULL)
+		err(1, "vasprintf");
+
+	XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)text,
+	    strlen(text), &extents);
+
+	XReparentWindow(X_Dpy, sc->menu.win, win, 0, 0);
+	XMoveResizeWindow(X_Dpy, sc->menu.win, 0, 0,
+	    extents.xOff, sc->xftfont->height);
+	XMapWindow(X_Dpy, sc->menu.win);
+	XClearWindow(X_Dpy, sc->menu.win);
+
+	XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT],
+	    sc->xftfont, 0, sc->xftfont->ascent + 1,
+	    (const FcChar8*)text, strlen(text));
+
+	free(text);
+}
+