aboutsummaryrefslogtreecommitdiff
path: root/src/tsar.c
diff options
context:
space:
mode:
authoriamcheeseman <[hidden email]>2026-03-02 19:00:42 -0500
committeriamcheeseman <[hidden email]>2026-03-02 19:00:42 -0500
commitb1df65a9325f95c09b85c2cd5483e198c909b4e3 (patch)
tree63bbc75a30167d8532a3f6955978cc4448c4e261 /src/tsar.c
parenta996c83e1079f49830138858f6c54816102daeba (diff)
Add support for different bg/fg colors per comp
Diffstat (limited to 'src/tsar.c')
-rw-r--r--src/tsar.c25
1 files changed, 13 insertions, 12 deletions
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;