diff options
| author | iamcheeseman <[hidden email]> | 2026-03-02 19:00:42 -0500 |
|---|---|---|
| committer | iamcheeseman <[hidden email]> | 2026-03-02 19:00:42 -0500 |
| commit | b1df65a9325f95c09b85c2cd5483e198c909b4e3 (patch) | |
| tree | 63bbc75a30167d8532a3f6955978cc4448c4e261 /src/tsar.c | |
| parent | a996c83e1079f49830138858f6c54816102daeba (diff) | |
Add support for different bg/fg colors per comp
Diffstat (limited to 'src/tsar.c')
| -rw-r--r-- | src/tsar.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -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; |
