Load fg and bg from config
Anirudh Oppiliappan x@icyphox.sh
Sat, 24 Apr 2021 20:15:20 +0530
M
barito.c
→
barito.c
@@ -15,12 +15,21 @@ static Colormap colormap;
static int depth; static int screen; +static unsigned long alloc_color(const char *s) +{ + XColor color; + if(!XAllocNamedColor(dpy, colormap, s, &color, &color)) + errx(1, "cannot allocate color"); + + return color.pixel; +} + static Window create_win(int x, int y, int w, int h) { XSetWindowAttributes swa; Window win; - swa.background_pixel = WhitePixel(dpy, screen); + swa.background_pixel = alloc_color(bg); swa.override_redirect = 1; swa.event_mask = ExposureMask; win = XCreateWindow(dpy, root, x, y, w, h, 0, CopyFromParent,@@ -77,7 +86,7 @@ /* allocate color for Xft */
static void xft_alloc_color(const char *colorname, XftColor *color) { if (!XftColorAllocName(dpy, visual, colormap, colorname, color)) - errx(1, "could not allocate color"); + errx(1, "cannot allocate color"); } /* draw text on pixmap */@@ -92,12 +101,10 @@ draw = XftDrawCreate(dpy, pix, visual, colormap);
len = strlen(text); - /* get text extents */ XftTextExtentsUtf8(dpy, font, text, len, &ext); x = (WIDTH - ext.width) / 2; y = (HEIGHT + ext.height) / 2; - /* draw text */ XftDrawStringUtf8(draw, color, font, x, y, text, len); XftDrawDestroy(draw);@@ -145,7 +152,7 @@ win = create_win(0, 0, WIDTH, HEIGHT);
gc = XCreateGC(dpy, root, 0, NULL); pix = create_pixmap(gc, WIDTH, HEIGHT); font = XftFontOpenName(dpy, screen, fontname); - xft_alloc_color(colorname, &color); + xft_alloc_color(fg, &color); init_atoms(win);