summary refs log tree commit diff
path: root/screen.c
diff options
context:
space:
mode:
authorokan <okan>2019-03-04 19:28:17 +0000
committerokan <okan>2019-03-04 19:28:17 +0000
commit0bda8f76067b737f34c11ef094b349c0c12fe118 (patch)
tree81fd0a0d76d553fa1635dcdf16a3c30338c45475 /screen.c
parent9d5b0e5d22fca1b6fb37a8df906bdad0317238c9 (diff)
downloadcwm-0bda8f76067b737f34c11ef094b349c0c12fe118.tar.gz
cwm-0bda8f76067b737f34c11ef094b349c0c12fe118.tar.xz
cwm-0bda8f76067b737f34c11ef094b349c0c12fe118.zip
Separate out the menu window from the client resize/move geom window; in each
case, create and destroy on-demand. Isolate more menu specific code.
Diffstat (limited to 'screen.c')
-rw-r--r--screen.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/screen.c b/screen.c
index a449219..eb84a17 100644
--- a/screen.c
+++ b/screen.c
@@ -24,6 +24,7 @@
 #include <err.h>
 #include <errno.h>
 #include <limits.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -250,3 +251,47 @@ screen_assert_clients_within(struct screen_ctx *sc)
 		}
 	}
 }
+
+void
+screen_prop_win_create(struct screen_ctx *sc, Window win)
+{
+	sc->prop.win = XCreateSimpleWindow(X_Dpy, win, 0, 0, 1, 1, 0,
+	    sc->xftcolor[CWM_COLOR_MENU_BG].pixel,
+	    sc->xftcolor[CWM_COLOR_MENU_BG].pixel);
+	sc->prop.xftdraw = XftDrawCreate(X_Dpy, sc->prop.win,
+	    sc->visual, sc->colormap);
+
+	XMapWindow(X_Dpy, sc->prop.win);
+}
+
+void
+screen_prop_win_destroy(struct screen_ctx *sc)
+{
+	XftDrawDestroy(sc->prop.xftdraw);
+	XDestroyWindow(X_Dpy, sc->prop.win);
+}
+
+void
+screen_prop_win_draw(struct screen_ctx *sc, 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);
+	XResizeWindow(X_Dpy, sc->prop.win, extents.xOff, sc->xftfont->height);
+	XClearWindow(X_Dpy, sc->prop.win);
+	XftDrawStringUtf8(sc->prop.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT],
+	    sc->xftfont, 0, sc->xftfont->ascent + 1,
+	    (const FcChar8*)text, strlen(text));
+
+	free(text);
+}