aboutsummaryrefslogtreecommitdiffstats
path: root/screen.c
diff options
context:
space:
mode:
authorokan2019-03-04 19:28:17 +0000
committerokan2019-03-04 19:28:17 +0000
commitf9cc6bc28fcaadc3f0eea32de200c98ed65671e4 (patch)
tree3b59621a6066197982d20408c605078bb092a1d2 /screen.c
parent630b170b88810b2ccb695b6f715b9a415525c926 (diff)
downloadcwm-f9cc6bc28fcaadc3f0eea32de200c98ed65671e4.tar.gz
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.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/screen.c b/screen.c
index ca6df76..8b22807 100644
--- a/screen.c
+++ b/screen.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: screen.c,v 1.91 2019/03/04 14:48:59 okan Exp $
+ * $OpenBSD: screen.c,v 1.92 2019/03/04 19:28:18 okan Exp $
*/
#include <sys/types.h>
@@ -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);
+}