aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xexamplebar.sh4
-rw-r--r--src/tsar.c27
2 files changed, 26 insertions, 5 deletions
diff --git a/examplebar.sh b/examplebar.sh
index 4bc516e..b72386f 100755
--- a/examplebar.sh
+++ b/examplebar.sh
@@ -12,4 +12,6 @@
./tsarc set date -text "$(date)"
./tsarc layout \
- -left test_comp sep date
+ -left test_comp sep date \
+ -right test_comp \
+ -center date
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();