diff options
| author | Federico Angelilli <code@fedang.net> | 2024-11-24 23:00:33 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-11-24 23:00:33 +0100 |
| commit | 7ed39aca6d07b8ca69c0373f5623ffd6a5564412 (patch) | |
| tree | b640cf38ade176b6c1ad22608fed87dc83b18c63 /src/config.c | |
| parent | b5c06f76b9a7cbc64590ec247778704459efb3ea (diff) | |
Add other actions to config
Diffstat (limited to 'src/config.c')
| -rw-r--r-- | src/config.c | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/src/config.c b/src/config.c index ffceba9..3bbce6d 100644 --- a/src/config.c +++ b/src/config.c @@ -36,16 +36,24 @@ const config_entry_t bar_entries[] = { }; const config_entry_t block_entries[] = { - { "hidden", CONFIG_BOOL, NULL, offsetof(block_t, hidden) }, - { "color", CONFIG_GRADIENT, NULL, offsetof(block_t, bg_color) }, - { "line-color", CONFIG_GRADIENT, NULL, offsetof(block_t, line_color) }, - { "line-width", CONFIG_UINT, NULL, offsetof(block_t, line_width) }, - { "x-padding", CONFIG_UINT, NULL, offsetof(block_t, x_padding) }, - { "y-padding", CONFIG_UINT, NULL, offsetof(block_t, y_padding) }, - { "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) }, + { "hidden", CONFIG_BOOL, NULL, offsetof(block_t, hidden) }, + { "color", CONFIG_GRADIENT, NULL, offsetof(block_t, bg_color) }, + { "line-color", CONFIG_GRADIENT, NULL, offsetof(block_t, line_color) }, + { "line-width", CONFIG_UINT, NULL, offsetof(block_t, line_width) }, + { "x-padding", CONFIG_UINT, NULL, offsetof(block_t, x_padding) }, + { "y-padding", CONFIG_UINT, NULL, offsetof(block_t, y_padding) }, + { "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) }, + //{ "trigger", CONFIG_STRING, NULL, offsetof(block_t, actions[EVENT_TRIGGER]) }, + { "left-click", CONFIG_STRING, NULL, offsetof(block_t, actions[EVENT_LEFT_CLICK]) }, + { "middle-click", CONFIG_STRING, NULL, offsetof(block_t, actions[EVENT_MIDDLE_CLICK]) }, + { "right-click", CONFIG_STRING, NULL, offsetof(block_t, actions[EVENT_RIGHT_CLICK]) }, + { "scroll-up", CONFIG_STRING, NULL, offsetof(block_t, actions[EVENT_SCROLL_UP]) }, + { "scroll-down", CONFIG_STRING, NULL, offsetof(block_t, actions[EVENT_SCROLL_DOWN]) }, + { "hover-start", CONFIG_STRING, NULL, offsetof(block_t, actions[EVENT_HOVER_START]) }, + { "hover-move", CONFIG_STRING, NULL, offsetof(block_t, actions[EVENT_HOVER_MOVE]) }, + { "hover-stop", CONFIG_STRING, NULL, offsetof(block_t, actions[EVENT_HOVER_STOP]) }, { 0 }, }; @@ -277,6 +285,9 @@ static bool config_read_time(const char *value, struct timespec *result) // TODO: Handle quotation marks static bool config_read_list(const char *value, char ***result) { + // TODO: Ensure that this is correct + strfree(*result); + size_t count = 0; for (size_t i = 0; value[i] != '\0'; ++i) count += value[i] == ','; @@ -298,7 +309,8 @@ static bool config_read_list(const char *value, char ***result) if (!config_read_string(token, &list[n++])) { free(copy); - free(list); + list[n] = NULL; + strfree(list); return false; } } @@ -357,8 +369,10 @@ static config_status_t config_read_action(action_t *action, const char *key, con type = ACTION_TARGET; else if (!strncmp(key, "set-", 4)) type = ACTION_SET_PAIR; - else if (!strcmp(key, "run-script")) - type = ACTION_RUN_SCRIPT; + else if (!strcmp(key, "run-sync")) + type = ACTION_RUN_SYNC; + else if (!strcmp(key, "run-async")) + type = ACTION_RUN_ASYNC; else return CONFIG_UNKNOWN; @@ -732,21 +746,31 @@ int config_validate(config_t *config) bool config_resolve_action(config_t *config, block_t *block) { - char *label = (char *)block->actions; + action_t *actions[EVENT_MAX] = { 0 }; - if (label == NULL) return true; + for (size_t i = 0; i < EVENT_MAX; i++) { + char *label = (char *)block->actions[i]; - 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; + if (label == NULL) + continue; + + for (size_t j = 0; j < config->n_actions; j++) { + if (!strcmp(label, config->actions[j].label)) { + log_debug("Block '%s' uses action '%s' for %s", block->label, label, event_type_to_string(i)); + + actions[i] = &config->actions[j]; + free(label); + goto next; + } } + + log_error("Action '%s' not found (referenced by '%s')", label, block->label); + return false; +next: } - log_error("Action '%s' not found", label); - return false; + memcpy(block->actions, actions, sizeof(actions)); + return true; } bool config_resolve_children(config_t *config, block_t *block) @@ -794,7 +818,7 @@ bool config_resolve_children(config_t *config, block_t *block) } } - log_error("Block '%s' not found", children[i]); + log_error("Block '%s' not found (referenced by '%s')", children[i], block->label); goto error; next: } |
