From b1df65a9325f95c09b85c2cd5483e198c909b4e3 Mon Sep 17 00:00:00 2001 From: iamcheeseman <[hidden email]> Date: Mon, 2 Mar 2026 19:00:42 -0500 Subject: Add support for different bg/fg colors per comp --- src/tsar.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/tsar.c') diff --git a/src/tsar.c b/src/tsar.c index 00eed2f..39e3717 100644 --- a/src/tsar.c +++ b/src/tsar.c @@ -17,7 +17,6 @@ Window win; GC gc; XftFont* font = NULL; -XftColor xft_fg_color; static int bar_width = 1000; static float width_ratio = 1; @@ -94,14 +93,6 @@ void init_x(void) { load_font("monospace:size=10"); - XftColorAllocName( - display, - DefaultVisual(display, DefaultScreen(display)), - DefaultColormap(display, DefaultScreen(display)), - "#FFFFFF", - &xft_fg_color - ); - gc = XCreateGC(display, win, 0, NULL); XSetForeground(display, gc, 0xFFFFFF); @@ -115,7 +106,13 @@ void deinit_x(void) { XDestroyWindow(display, win); } -void draw_text(const char* text, int x, int y) { +void draw_text( + const char* text, + int x, + int y, + const XftColor* fg_color, + const XftColor* bg_color +) { XftDraw* xft_draw = XftDrawCreate( display, win, @@ -123,8 +120,11 @@ void draw_text(const char* text, int x, int y) { DefaultColormap(display, DefaultScreen(display)) ); + size_t width = font->max_advance_width * utf8_strlen(text); + XftDrawRect(xft_draw, bg_color, x, y, width, bar_height); + int dy = y + (bar_height - font->height) / 2 + font->ascent; - XftDrawStringUtf8(xft_draw, &xft_fg_color, font, x, dy, (const FcChar8*)text, strlen(text)); + XftDrawStringUtf8(xft_draw, fg_color, font, x, dy, (const FcChar8*)text, strlen(text)); XftDrawDestroy(xft_draw); } @@ -143,7 +143,7 @@ void draw_comp_set(float pos_ratio, comp_t **set, int size) { for (int i = 0; i < size; i++) { comp_t *comp = set[i]; - draw_text(comp->data, x, y); + draw_text(comp->data, x, y, comp->fg, comp->bg); x += font->max_advance_width * utf8_strlen(comp->data); x += comp_gap; } @@ -152,6 +152,7 @@ void draw_comp_set(float pos_ratio, comp_t **set, int size) { int main(void) { init_pipe(); init_x(); + init_bardata(); while (true) { XEvent ev; -- cgit v1.3-2-g0d8e