diff options
| author | Federico Angelilli <code@fedang.net> | 2024-12-07 00:41:01 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-12-07 00:41:01 +0100 |
| commit | fd2ef765de733fbbbb15e28c91df255da36d5338 (patch) | |
| tree | b107ca1a2e9b1b0ae1ee7534cdd4a850f52d9cb0 | |
| parent | 4f1c110638749f0d6941967e313bdcc28b2b3485 (diff) | |
Add trigger actiontrunk
| -rw-r--r-- | comet.conf | 7 | ||||
| -rw-r--r-- | src/action.c | 41 | ||||
| -rw-r--r-- | src/action.h | 1 | ||||
| -rw-r--r-- | src/config.c | 2 |
4 files changed, 48 insertions, 3 deletions
@@ -93,6 +93,8 @@ sus = 1 x-padding = 5 y-padding = 5 + trigger = tried + [block.slide] type = slider bar-value = 88 @@ -136,3 +138,8 @@ sus = 1 ;target = block.mus ;set-blocks = bogus + target = block.next + trigger = ciao + +[action.tried] + run-sync = echo ciao diff --git a/src/action.c b/src/action.c index 6b48c15..df6ad3a 100644 --- a/src/action.c +++ b/src/action.c @@ -51,9 +51,11 @@ bool action_perform(action_t *action, block_t *block, config_t *config) case ACTION_SET_PAIR: { assert(target != NULL); - if (!warned && target->scheme->change_fn == NULL) { - log_warn("Block '%s' does not support 'set' actions", target->label); - warned = true; + if (target->scheme->change_fn == NULL) { + if (!warned) { + log_warn("Block '%s' does not support 'set' actions", target->label); + warned = true; + } continue; } @@ -96,6 +98,39 @@ bool action_perform(action_t *action, block_t *block, config_t *config) break; } + case ACTION_TRIGGER: { + event_t event; + event_init_trigger(&event, action->label, value); + + action_t *action = target->actions[EVENT_TRIGGER]; + block_event_t event_fn = target->type == BLOCK_SPEC + ? ((block_spec_t *)target)->event_fn + : NULL; + + log_value_debug("Block received a trigger", + "s:target", target->label, + "s:origin", event.trigger.origin, + "s:payload", event.trigger.payload, + "b:action", action != NULL, + "b:callback", event_fn != NULL); + + if (event_fn != NULL) { + // FIXME + layout_t tmp = { + .block = target, + }; + + event_fn(&tmp, config, event); + log_trace("Completed event callback"); + } else if (action != NULL) { + action_perform(action, target, config); + } else { + log_warn("Block '%s' was triggered but had nothing to respond", target->label); + } + + break; + } + default: unreachable(); } diff --git a/src/action.h b/src/action.h index eb144a5..946b629 100644 --- a/src/action.h +++ b/src/action.h @@ -10,6 +10,7 @@ typedef enum { ACTION_SET_PAIR, ACTION_RUN_SYNC, ACTION_RUN_ASYNC, + ACTION_TRIGGER, } action_type_t; typedef struct { diff --git a/src/config.c b/src/config.c index 6b8fc58..86d5ac2 100644 --- a/src/config.c +++ b/src/config.c @@ -446,6 +446,8 @@ static config_status_t config_read_action(action_t *action, const char *key, con type = ACTION_RUN_SYNC; else if (!strcmp(key, "run-async")) type = ACTION_RUN_ASYNC; + else if (!strcmp(key, "trigger")) + type = ACTION_TRIGGER; else return CONFIG_UNKNOWN; |
