#include "bardata.h" #include #include #include #include #include "pipe.h" #include "tsar.h" int fontsize = 16; color_t default_fg, default_bg; int bar_height = 20; // Global state, oh naur D: comp_t comps[32]; size_t comps_size = 0; comp_t *comps_left[16], *comps_right[16], *comps_center[16]; size_t left_size = 0, right_size = 0, center_size = 0; comp_t *find_comp(char *name) { for (size_t i = 0; i < comps_size; i++) { if (strcmp(comps[i].name, name) == 0) { return &comps[i]; } } return NULL; } void new_component(char *name) { comp_t* existing = find_comp(name); if (existing) return; strcpy(comps[comps_size].name, name); comps_size++; } void add_component(comp_side_t side, char *name) { comp_t *comp = find_comp(name); if (side == SIDE_LEFT) { comps_left[left_size] = comp; left_size++; return; } if (side == SIDE_RIGHT) { comps_right[right_size] = comp; right_size++; return; } if (side == SIDE_CENTER) { comps_center[center_size] = comp; center_size++; return; } } void set_component(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) { comp_t* comp = find_comp(argv[1]); for (int i = 2; i < argc; i++) { if (strcmp(argv[i], "-text") == 0) { strcpy(comp->data, argv[i + 1]); i++; continue; } } } void set_layout(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) { comp_side_t side = SIDE_LEFT; left_size = 0; center_size = 0; right_size = 0; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-left") == 0) { side = SIDE_LEFT; continue; } if (strcmp(argv[i], "-center") == 0) { side = SIDE_CENTER; continue; } if (strcmp(argv[i], "-right") == 0) { side = SIDE_RIGHT; continue; } add_component(side, argv[i]); } } void set_config(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) { char *var = argv[1]; if (strcmp(var, "height") == 0) { int new_bar_height = atoi(argv[2]); if (new_bar_height <= 0) { fprintf(stderr, "invalid bar height %d\n", new_bar_height); return; } bar_height = new_bar_height; } if (strcmp(var, "font") == 0) { // fontsize = atoi(argv[2]); load_font(argv[2]); } }