From 8ed3b9bfb2108ec51121160533e8bd93b356cc98 Mon Sep 17 00:00:00 2001 From: ne_mene Date: Sun, 1 Mar 2026 21:28:19 +0100 Subject: right center (non political commit) --- src/tsar.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/tsar.c') diff --git a/src/tsar.c b/src/tsar.c index fdc854e..298e662 100644 --- a/src/tsar.c +++ b/src/tsar.c @@ -18,7 +18,7 @@ GC gc; XftFont* font = NULL; XftColor fg_color; -static int width = 1000; +static int bar_width = 1000; static float width_ratio = 1; static int err_code = 1; @@ -60,13 +60,13 @@ void init_x(void) { }; Screen* screen = DefaultScreenOfDisplay(display); - width = WidthOfScreen(screen); + bar_width = WidthOfScreen(screen); win = XCreateWindow( display, DefaultRootWindow(display), 0, 0, - width, bar_height, + bar_width, bar_height, 0, CopyFromParent, InputOutput, @@ -113,6 +113,22 @@ void draw_text(const char* text, int x, int y) { XftDrawDestroy(xft_draw); } +void draw_comp_set(float pos_ratio, comp_t **set, int size) { + int width = 0; + for (int i = 0; i < size; i++) { + comp_t *comp = set[i]; + width += font->max_advance_width * strlen(comp->data); + } + + int x = (bar_width - width) * pos_ratio; + for (int i = 0; i < size; i++) { + comp_t *comp = set[i]; + + draw_text(comp->data, x, 0); + x += font->max_advance_width * strlen(comp->data); + } +} + int main(void) { init_pipe(); init_x(); @@ -123,7 +139,7 @@ int main(void) { XNextEvent(display, &ev); XClearWindow(display, win); - XResizeWindow(display, win, width, bar_height); + XResizeWindow(display, win, bar_width, bar_height); int x = 0; for (int i = 0; i < left_size; i++) { @@ -131,6 +147,9 @@ int main(void) { draw_text(comp->data, x, 0); x += font->max_advance_width * strlen(comp->data); } + draw_comp_set(0, comps_left, left_size); + draw_comp_set(0.5, comps_center, center_size); + draw_comp_set(1, comps_right, right_size); XFlush(display); await_change(); -- cgit v1.3-2-g0d8e