diff --git a/cfg/succaderc.1 b/cfg/succaderc.1 index ea5b494..712ebdb 100644 --- a/cfg/succaderc.1 +++ b/cfg/succaderc.1 @@ -3,17 +3,17 @@ name = "testbar" blocks = "desktop | user | date time" height = 24 areas = 16 -foreground = "#000000" -background = "#ce7942" -underline = true +foreground = "#550000" +background = "#555555" line-width = 3 line-color = "#333333" -label-foreground = "#333333" -block-prefix = " " -block-suffix = " " -block-margin = 4 font = 6x13 +[default] +label-foreground = "#FF2222" +prefix = " " +suffix = " " + [desktop] command = "bspc query -D -d focused --names" trigger = "bspc subscribe" diff --git a/src/cfg.h b/src/cfg.h index 63f11d7..eac2fb2 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -73,6 +73,11 @@ int cfg_has(const cfg_s *cfg, size_t idx) return (idx < cfg->size && cfg->type[idx] != 0); } +cfg_opt_type_e cfg_type(const cfg_s *cfg, size_t idx) +{ + return cfg->type[idx]; +} + void cfg_set_int(const cfg_s *cfg, size_t idx, int val) { if (idx >= cfg->size) @@ -114,7 +119,7 @@ int cfg_get_int(const cfg_s *cfg, size_t idx) float cfg_get_float(const cfg_s *cfg, size_t idx) { return (idx < cfg->size && cfg->type[idx] == OPT_TYPE_FLOAT) ? - cfg->opts[idx].f : 0; + cfg->opts[idx].f : 0.0; } char *cfg_get_str(const cfg_s *cfg, size_t idx) diff --git a/src/loadini.c b/src/loadini.c index 28c99a6..a923547 100644 --- a/src/loadini.c +++ b/src/loadini.c @@ -1,6 +1,5 @@ #include // NULL, size_t, EXIT_SUCCESS, EXIT_FAILURE, ... -#include // strlen(), strcmp(), ... -#include // DBL_MAX +#include // strdup() #include "ini.h" // https://github.com/benhoyt/inih #include "succade.h" // defines, structs, all that stuff @@ -31,7 +30,7 @@ int lemon_ini_handler(void *data, const char *section, const char *name, const c cfg_set_str(lc, LEMON_OPT_BG, is_quoted(value) ? unquote(value) : strdup(value)); return 1; } - if (equals(name, "line-color") || equals(name, "line") || equals(name, "lc")) + if (equals(name, "line-color") || equals(name, "lc")) { cfg_set_str(lc, LEMON_OPT_LC, is_quoted(value) ? unquote(value) : strdup(value)); return 1; @@ -41,16 +40,6 @@ int lemon_ini_handler(void *data, const char *section, const char *name, const c cfg_set_int(lc, LEMON_OPT_LW, atoi(value)); return 1; } - if (equals(name, "overline") || equals(name, "ol")) - { - cfg_set_int(lc, LEMON_OPT_OL, equals(value, "true")); - return 1; - } - if (equals(name, "underline") || equals(name, "ul")) - { - cfg_set_int(lc, LEMON_OPT_UL, equals(value, "true")); - return 1; - } if (equals(name, "height") || equals(name, "h")) { cfg_set_int(lc, LEMON_OPT_HEIGHT, atoi(value)); @@ -91,26 +80,6 @@ int lemon_ini_handler(void *data, const char *section, const char *name, const c cfg_set_int(lc, LEMON_OPT_AREAS, atoi(value)); return 1; } - if (equals(name, "block-margin") || equals(name, "margin")) - { - cfg_set_int(lc, LEMON_OPT_BLOCK_MARGIN, atoi(value)); - return 1; - } - if (equals(name, "block-padding") || equals(name, "padding")) - { - cfg_set_int(lc, LEMON_OPT_BLOCK_PADDING, atoi(value)); - return 1; - } - if (equals(name, "block-prefix") || equals(name, "prefix")) - { - cfg_set_str(lc, LEMON_OPT_BLOCK_PREFIX, is_quoted(value) ? unquote(value) : strdup(value)); - return 1; - } - if (equals(name, "block-suffix") || equals(name, "suffix")) - { - cfg_set_str(lc, LEMON_OPT_BLOCK_SUFFIX, is_quoted(value) ? unquote(value) : strdup(value)); - return 1; - } if (equals(name, "blocks") || equals(name, "format")) { cfg_set_str(lc, LEMON_OPT_FORMAT, is_quoted(value) ? unquote(value) : strdup(value)); @@ -131,31 +100,6 @@ int lemon_ini_handler(void *data, const char *section, const char *name, const c cfg_set_str(lc, LEMON_OPT_AFFIX_FONT, is_quoted(value) ? unquote(value) : strdup(value)); return 1; } - if (equals(name, "block-background") || equals(name, "block-bg")) - { - cfg_set_str(lc, LEMON_OPT_BLOCK_BG, is_quoted(value) ? unquote(value) : strdup(value)); - return 1; - } - if (equals(name, "label-background") || equals(name, "label-bg")) - { - cfg_set_str(lc, LEMON_OPT_LABEL_BG, is_quoted(value) ? unquote(value) : strdup(value)); - return 1; - } - if (equals(name, "label-foreground") || equals(name, "label-fg")) - { - cfg_set_str(lc, LEMON_OPT_LABEL_FG, is_quoted(value) ? unquote(value) : strdup(value)); - return 1; - } - if (equals(name, "affix-background") || equals(name, "affix-bg")) - { - cfg_set_str(lc, LEMON_OPT_AFFIX_BG, is_quoted(value) ? unquote(value) : strdup(value)); - return 1; - } - if (equals(name, "affix-foreground") || equals(name, "affix-fg")) - { - cfg_set_str(lc, LEMON_OPT_AFFIX_FG, is_quoted(value) ? unquote(value) : strdup(value)); - return 1; - } // Unknown section or name return 0; @@ -233,6 +177,16 @@ int block_ini_handler(void *data, const char *section, const char *name, const c cfg_set_int(bc, BLOCK_OPT_MARGIN_RIGHT, atoi(value)); return 1; } + if (equals(name, "padding-left")) + { + cfg_set_int(bc, BLOCK_OPT_PADDING_LEFT, atoi(value)); + return 1; + } + if (equals(name, "padding-right")) + { + cfg_set_int(bc, BLOCK_OPT_PADDING_RIGHT, atoi(value)); + return 1; + } if (equals(name, "prefix")) { cfg_set_str(bc, BLOCK_OPT_PREFIX, is_quoted(value) ? unquote(value) : strdup(value)); diff --git a/src/succade.c b/src/succade.c index 04fda8e..a275602 100644 --- a/src/succade.c +++ b/src/succade.c @@ -328,11 +328,10 @@ static double time_to_wait(state_s *state, double now) * string this function is putting together, otherwise truncation will happen. * Alternatively, set `len` to 0 to let this function calculate the buffer. */ -static char *blockstr(const thing_s *lemon, const thing_s *block) +static char *blockstr(const thing_s *block) { // for convenience const cfg_s *bcfg = &block->cfg; - const cfg_s *lcfg = &lemon->cfg; char action_start[(5 * strlen(block->sid)) + 64]; char action_end[24]; @@ -383,29 +382,29 @@ static char *blockstr(const thing_s *lemon, const thing_s *block) // calculating the padding (fixed width) of the block, no? size_t diff = 0; - char *result = (cfg_has(bcfg, BLOCK_OPT_RAW) && cfg_get_int(bcfg, BLOCK_OPT_RAW)) ? + char *result = cfg_get_int(bcfg, BLOCK_OPT_RAW) ? strdup(block->output) : escape(block->output, '%', &diff); int min_width = cfg_get_int(bcfg, BLOCK_OPT_WIDTH) + diff; - const char *block_fg = strsel(cfg_get_str(bcfg, BLOCK_OPT_FG), "-", "-"); - const char *block_bg = strsel(cfg_get_str(bcfg, BLOCK_OPT_BG), cfg_get_str(lcfg, LEMON_OPT_BLOCK_BG), "-"); - const char *label_fg = strsel(cfg_get_str(bcfg, BLOCK_OPT_LABEL_FG), cfg_get_str(lcfg, LEMON_OPT_LABEL_FG), "-"); - const char *label_bg = strsel(cfg_get_str(bcfg, BLOCK_OPT_LABEL_BG), cfg_get_str(lcfg, LEMON_OPT_LABEL_BG), "-"); - const char *affix_fg = strsel(cfg_get_str(bcfg, BLOCK_OPT_AFFIX_FG), cfg_get_str(lcfg, LEMON_OPT_AFFIX_FG), "-"); - const char *affix_bg = strsel(cfg_get_str(bcfg, BLOCK_OPT_AFFIX_BG), cfg_get_str(lcfg, LEMON_OPT_AFFIX_BG), "-"); - - int padding = cfg_get_int(lcfg, LEMON_OPT_BLOCK_PADDING); - int margin = cfg_get_int(lcfg, LEMON_OPT_BLOCK_MARGIN); - int margin_l = cfg_has(bcfg, BLOCK_OPT_MARGIN_LEFT) ? cfg_get_int(bcfg, BLOCK_OPT_MARGIN_LEFT) : -1; - int margin_r = cfg_has(bcfg, BLOCK_OPT_MARGIN_RIGHT) ? cfg_get_int(bcfg, BLOCK_OPT_MARGIN_RIGHT) : -1; - int ol = cfg_has(bcfg, BLOCK_OPT_OL) ? cfg_get_int(bcfg, BLOCK_OPT_OL) : cfg_get_int(lcfg, LEMON_OPT_OL); - int ul = cfg_has(bcfg, BLOCK_OPT_UL) ? cfg_get_int(bcfg, BLOCK_OPT_UL) : cfg_get_int(lcfg, LEMON_OPT_UL); - const char *lc = strsel(cfg_get_str(bcfg, BLOCK_OPT_LC), cfg_get_str(lcfg, LEMON_OPT_LC) , "-"); - - const char *prefix = strsel(cfg_get_str(bcfg, BLOCK_OPT_PREFIX), cfg_get_str(lcfg, LEMON_OPT_BLOCK_PREFIX), ""); - const char *suffix = strsel(cfg_get_str(bcfg, BLOCK_OPT_PREFIX), cfg_get_str(lcfg, LEMON_OPT_BLOCK_SUFFIX), ""); - const char *label = strsel(cfg_get_str(bcfg, BLOCK_OPT_LABEL), "", ""); - //const char *unit = strsel(cfg_get_str(bcfg, BLOCK_OPT_UNIT), "", ""); + const char *block_fg = strsel(cfg_get_str(bcfg, BLOCK_OPT_FG), "-", ""); + const char *block_bg = strsel(cfg_get_str(bcfg, BLOCK_OPT_BG), "-", ""); + const char *label_fg = strsel(cfg_get_str(bcfg, BLOCK_OPT_LABEL_FG), "-", ""); + const char *label_bg = strsel(cfg_get_str(bcfg, BLOCK_OPT_LABEL_BG), "-", ""); + const char *affix_fg = strsel(cfg_get_str(bcfg, BLOCK_OPT_AFFIX_FG), "-", ""); + const char *affix_bg = strsel(cfg_get_str(bcfg, BLOCK_OPT_AFFIX_BG), "-", ""); + const char *lc = strsel(cfg_get_str(bcfg, BLOCK_OPT_LC), "-", ""); + + const char *prefix = strsel(cfg_get_str(bcfg, BLOCK_OPT_PREFIX), "", ""); + const char *suffix = strsel(cfg_get_str(bcfg, BLOCK_OPT_PREFIX), "", ""); + const char *label = strsel(cfg_get_str(bcfg, BLOCK_OPT_LABEL), "", ""); + //const char *unit = strsel(cfg_get_str(bcfg, BLOCK_OPT_UNIT), "", ""); + + int padding_l = cfg_get_int(bcfg, BLOCK_OPT_PADDING_LEFT); + int padding_r = cfg_get_int(bcfg, BLOCK_OPT_PADDING_RIGHT); + int margin_l = cfg_get_int(bcfg, BLOCK_OPT_MARGIN_LEFT); + int margin_r = cfg_get_int(bcfg, BLOCK_OPT_MARGIN_RIGHT); + int ol = cfg_get_int(bcfg, BLOCK_OPT_OL); + int ul = cfg_get_int(bcfg, BLOCK_OPT_UL); // TODO currently we are adding the format thingies for label, // prefix and suffix, even if those are empty anyway, which @@ -416,29 +415,34 @@ static char *blockstr(const thing_s *lemon, const thing_s *block) char *str = malloc(BUFFER_BLOCK_STR); snprintf(str, BUFFER_BLOCK_STR, - "%%{O%d}" - "%s%%{F%s B%s U%s %co %cu}" - "%%{T3 F%s B%s}%s" - "%%{T2 F%s B%s}%s" - "%%{T1 F%s B%s}%*s%*s%*s" - "%%{T3 F%s B%s}%s" - "%%{T- F- B- U- -o -u}%s" - "%%{O%d}", + "%%{O%d}" // margin left + "%s" // action start + "%%{F%s B%s U%s %co %cu}" // format start + "%%{T3 F%s B%s}%s" // prefix + "%%{T2 F%s B%s}%s" // label + "%%{T1 F%s B%s}%*s%*s%*s" // block + "%%{T3 F%s B%s}%s" // suffix + "%%{T- F- B- U- -o -u}" // format end + "%s" // action end + "%%{O%d}", // margin right // margin left - margin_l >= 0 ? margin_l : margin, - // start - action_start, block_fg, block_bg, lc, (ol ? '+' : '-'), (ul ? '+' : '-'), + margin_l, + // action start + action_start, + // format start + block_fg, block_bg, lc, (ol ? '+' : '-'), (ul ? '+' : '-'), // prefix affix_fg, affix_bg, prefix, // label label_fg, label_bg, label, // block - block_fg, block_bg, padding, "", min_width, result, padding, "", + block_fg, block_bg, padding_l, "", min_width, result, padding_r, "", // suffix affix_fg, affix_bg, suffix, - // end + // action end action_end, - margin_r >= 0 ? margin_r : margin + // margin right + margin_r ); free(result); @@ -468,7 +472,6 @@ static char *barstr(const state_s *state) } // For convenience... - const thing_s *bar = &state->lemon; size_t num_blocks = state->num_blocks; // Short blocks like temperature, volume or battery, will usually use @@ -493,7 +496,7 @@ static char *barstr(const state_s *state) int block_align = cfg_get_int(&block->cfg, BLOCK_OPT_ALIGN); - char *block_str = blockstr(bar, block); + char *block_str = blockstr(block); size_t block_str_len = strlen(block_str); if (block_align != last_align) { @@ -671,7 +674,7 @@ int block_cfg_handler(void *data, const char *section, const char *name, const c } // Find the block whose name fits the section name - thing_s *block = get_block(state, section); + thing_s *block = equals(section, ALBEDO_SID) ? &state->albedo : get_block(state, section); // Abort if we couldn't find that block if (block == NULL) @@ -1275,6 +1278,16 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + // + // ALBEDO + // + + thing_s *albedo = &(state.albedo); // For convenience + albedo->sid = ALBEDO_SID; + albedo->t_type = THING_BLOCK; + albedo->b_type = BLOCK_NONE; + cfg_init(&albedo->cfg, ALBEDO_SID, BLOCK_OPT_COUNT); + // // BLOCKS // @@ -1308,6 +1321,28 @@ int main(int argc, char **argv) char *block_bin = cfg_get_str(&block->cfg, BLOCK_OPT_BIN); char *block_cmd = block_bin ? block_bin : block->sid; block->child = make_child(&state, block_cmd, 0, 1, 1); + + // TODO merge albedo (default config) with this block's config + for (int i = 0; i < BLOCK_OPT_COUNT; ++i) + { + if (cfg_has(&albedo->cfg, i) && !cfg_has(&block->cfg, i)) + { + switch (cfg_type(&albedo->cfg, i)) + { + case OPT_TYPE_INT: + cfg_set_int(&block->cfg, i, cfg_get_int(&albedo->cfg, i)); + break; + case OPT_TYPE_FLOAT: + cfg_set_float(&block->cfg, i, cfg_get_float(&albedo->cfg, i)); + break; + case OPT_TYPE_STRING: + cfg_set_str(&block->cfg, i, strdup(cfg_get_str(&albedo->cfg, i))); + break; + default: + break; + } + } + } } // diff --git a/src/succade.h b/src/succade.h index ebdec6a..2ebd1ff 100644 --- a/src/succade.h +++ b/src/succade.h @@ -24,6 +24,8 @@ #define DEFAULT_CFG_FILE "succaderc" +#define ALBEDO_SID "default" + #define DEFAULT_LEMON_BIN "lemonbar" #define DEFAULT_LEMON_NAME "succade_lemonbar" #define DEFAULT_LEMON_SECTION "bar" @@ -62,67 +64,58 @@ typedef enum succade_fdesc_type fdesc_type_e; enum succade_lemon_opt { - LEMON_OPT_NAME, - LEMON_OPT_BIN, - LEMON_OPT_WIDTH, - LEMON_OPT_HEIGHT, - LEMON_OPT_X, - LEMON_OPT_Y, - LEMON_OPT_BOTTOM, - LEMON_OPT_FORCE, - LEMON_OPT_AREAS, - LEMON_OPT_FORMAT, - LEMON_OPT_FG, // block - LEMON_OPT_BG, - LEMON_OPT_LW, - LEMON_OPT_LC, // block - LEMON_OPT_OL, // block - LEMON_OPT_UL, // block - LEMON_OPT_BLOCK_BG, // block - LEMON_OPT_LABEL_FG, // block - LEMON_OPT_LABEL_BG, // block - LEMON_OPT_AFFIX_FG, // block - LEMON_OPT_AFFIX_BG, // block - LEMON_OPT_BLOCK_MARGIN, // block - LEMON_OPT_BLOCK_PADDING, // block - LEMON_OPT_BLOCK_PREFIX, // block - LEMON_OPT_BLOCK_SUFFIX, // block - LEMON_OPT_BLOCK_FONT, - LEMON_OPT_LABEL_FONT, - LEMON_OPT_AFFIX_FONT, + LEMON_OPT_BIN, // lemonbar binary + LEMON_OPT_FORMAT, // blocks to display + LEMON_OPT_WIDTH, // -g: lemonbar width + LEMON_OPT_HEIGHT, // -g: lemonbar height + LEMON_OPT_X, // -g: lemonbar x pos + LEMON_OPT_Y, // -g: lemonbar y pos + LEMON_OPT_BOTTOM, // -b: dock at bottom + LEMON_OPT_FORCE, // -d: force docking + LEMON_OPT_BLOCK_FONT, // -f: font for blocks + LEMON_OPT_LABEL_FONT, // -f: font for blocks' labels + LEMON_OPT_AFFIX_FONT, // -a: font for blocks' affixes + LEMON_OPT_AREAS, // -a: number of clickable areas + LEMON_OPT_NAME, // -n: WM_NAME + LEMON_OPT_LW, // -u: underline width + LEMON_OPT_BG, // -B: default background color + LEMON_OPT_FG, // -F: default font color + LEMON_OPT_LC, // -U: underline color LEMON_OPT_COUNT }; enum succade_block_opt { - BLOCK_OPT_BIN, - BLOCK_OPT_FG, - BLOCK_OPT_BG, - BLOCK_OPT_LABEL_FG, - BLOCK_OPT_LABEL_BG, - BLOCK_OPT_AFFIX_FG, - BLOCK_OPT_AFFIX_BG, - BLOCK_OPT_LC, - BLOCK_OPT_OL, - BLOCK_OPT_UL, - BLOCK_OPT_WIDTH, - BLOCK_OPT_MARGIN_LEFT, - BLOCK_OPT_MARGIN_RIGHT, - BLOCK_OPT_ALIGN, - BLOCK_OPT_PREFIX, - BLOCK_OPT_SUFFIX, - BLOCK_OPT_LABEL, - BLOCK_OPT_UNIT, - BLOCK_OPT_TRIGGER, - BLOCK_OPT_CONSUME, - BLOCK_OPT_RELOAD, - BLOCK_OPT_LIVE, - BLOCK_OPT_RAW, - BLOCK_OPT_CMD_LMB, - BLOCK_OPT_CMD_MMB, - BLOCK_OPT_CMD_RMB, - BLOCK_OPT_CMD_SUP, - BLOCK_OPT_CMD_SDN, + BLOCK_OPT_BIN, // string: binary + BLOCK_OPT_FG, // color: font + BLOCK_OPT_BG, // color: background + BLOCK_OPT_LABEL_FG, // color: label + BLOCK_OPT_LABEL_BG, // color: label backgorund + BLOCK_OPT_AFFIX_FG, // color: affix font + BLOCK_OPT_AFFIX_BG, // color: affix background + BLOCK_OPT_LC, // color: underline / overline + BLOCK_OPT_OL, // bool: draw overline + BLOCK_OPT_UL, // bool: draw underline + BLOCK_OPT_WIDTH, // int: minimum result width + BLOCK_OPT_MARGIN_LEFT, // int: margin left + BLOCK_OPT_MARGIN_RIGHT, // int: margin right + BLOCK_OPT_PADDING_LEFT, // int: padding left + BLOCK_OPT_PADDING_RIGHT, // int: padding right + BLOCK_OPT_ALIGN, // TODO + BLOCK_OPT_PREFIX, // string: prefix + BLOCK_OPT_SUFFIX, // string: suffix + BLOCK_OPT_LABEL, // string: label + BLOCK_OPT_UNIT, // string: unit + BLOCK_OPT_TRIGGER, // string: trigger binary + BLOCK_OPT_CONSUME, // bool: consume trigger output + BLOCK_OPT_RELOAD, // bool: reload if dead + BLOCK_OPT_LIVE, // bool: live (keeps running) + BLOCK_OPT_RAW, // bool: don't escape '%' + BLOCK_OPT_CMD_LMB, // string: run on left click + BLOCK_OPT_CMD_MMB, // string: run on middle click + BLOCK_OPT_CMD_RMB, // string: run on right click + BLOCK_OPT_CMD_SUP, // string: run on scroll up + BLOCK_OPT_CMD_SDN, // string: run on scroll down BLOCK_OPT_COUNT }; @@ -171,6 +164,7 @@ struct succade_state { prefs_s prefs; // Preferences (options/config) thing_s lemon; + thing_s albedo; // Dummy block for the default configuration thing_s *blocks; // Reference to block array thing_s *sparks; // Reference to spark array (prev. 'trigger') size_t num_blocks; // Number of blocks in blocks array