all repos — barito @ e59e490a9cebbdc06b442d5ec65a0dd2bd9d98b8

an x11 bar

Load fg and bg from config
Anirudh Oppiliappan x@icyphox.sh
Sat, 24 Apr 2021 20:15:20 +0530
commit

e59e490a9cebbdc06b442d5ec65a0dd2bd9d98b8

parent

3bd7bd3ee6150bfbb7288b4969a85e3d5a7b022f

2 files changed, 14 insertions(+), 6 deletions(-)

jump to
M barito.cbarito.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);
M config.hconfig.h

@@ -1,4 +1,5 @@

static char *fontname = "SF Mono:size=12"; -static char *colorname = "#000000"; +static char *fg = "#000000"; +static char *bg = "#676767"; #define HEIGHT 30 #define WIDTH 1920