diff options
Diffstat (limited to 'src/config.c')
| -rw-r--r-- | src/config.c | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/config.c b/src/config.c index d20aebe..619d95c 100644 --- a/src/config.c +++ b/src/config.c @@ -41,6 +41,7 @@ static const config_entry_t block_entries[] = { { "min-width", CONFIG_UINT, NULL, offsetof(block_t, min_width) }, { "max-width", CONFIG_UINT, NULL, offsetof(block_t, max_width) }, { "interval", CONFIG_TIME, NULL, offsetof(block_t, update_interval) }, + { "action", CONFIG_STRING, NULL, offsetof(block_t, actions) }, { 0 }, }; @@ -574,7 +575,8 @@ int config_read(config_t *config, FILE *file) "s:value", value, "i:line", ini.line); - if (!bar_section && block == NULL) + // Skip unknown sections + if (!bar_section && block == NULL && action == NULL) goto skip_pair; const char *type; @@ -669,10 +671,32 @@ int config_validate(config_t *config) return errors; } +bool config_resolve_action(config_t *config, block_t *block) +{ + char *label = (char *)block->actions; + + if (label == NULL) return true; + + for (size_t j = 0; j < config->n_actions; j++) { + if (!strcmp(label, config->actions[j].label)) { + log_debug("Block '%s' uses action '%s'", block->label, label); + free(label); + block->actions = &config->actions[j]; + return true; + } + } + + log_error("Action '%s' not found", label); + return false; +} + bool config_resolve_children(config_t *config, block_t *block) { block->resolved = true; + if (!config_resolve_action(config, block)) + return false; + if (block->type != BLOCK_GROUP) return true; @@ -698,11 +722,11 @@ bool config_resolve_children(config_t *config, block_t *block) if (!strcmp(children[i], config->blocks[j]->label)) { if (config->blocks[j]->resolved) { - log_error("Block '%s' can only be referenced by one block", config->blocks[j]->label); + log_error("Block '%s' can only be referenced by one block", children[i]); goto error; } - log_debug("Block '%s' is parent of '%s'", block->label, config->blocks[j]->label); + log_debug("Block '%s' is parent of '%s'", block->label, children[i]); group->children[i] = config->blocks[j]; if (!config_resolve_children(config, config->blocks[j])) @@ -747,12 +771,14 @@ void config_free(config_t *config) for (size_t i = 0; i < config->n_blocks; i++) block_free(config->blocks[i]); + free(config->blocks); + for (size_t i = 0; i < config->n_actions; i++) action_free(&config->actions[i]); - gradient_free(&config->background); + free(config->actions); - free(config->blocks); + gradient_free(&config->background); free(config->font); free(config->monitor); } |
