Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion block.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "log.h"
#include "sys.h"

static const char *resolve_alias_query(const char *button);

const char *block_get(const struct block *block, const char *key)
{
return map_get(block->env, key);
Expand Down Expand Up @@ -182,6 +184,8 @@ static int block_send_json(struct block *block)
static int block_send(struct block *block)
{
const char *button = block_get(block, "button");
const char *query = resolve_alias_query(button);
const char *alias;

if (!button) {
block_error(block, "no click data to send");
Expand All @@ -196,7 +200,8 @@ static int block_send(struct block *block)
if (block->format == FORMAT_JSON)
return block_send_json(block);

dprintf(block->in[1], "%s\n", button);
alias = map_get(block->config, query);
dprintf(block->in[1], "%s\n", alias ? alias : button);

return 0;
}
Expand Down Expand Up @@ -596,3 +601,15 @@ void block_printf(struct block *block, int lvl, const char *fmt, ...)
if (err)
fatal("failed to format message for block %s: %s", block->name, buf);
}

static const char *resolve_alias_query(const char *button)
{
if (strcmp(button, "1") == 0)
return "btn_left_cmd";
else if (strcmp(button, "2") == 0)
return "btn_middle_cmd";
else if (strcmp(button, "3") == 0)
return "btn_right_cmd";
else
return button;
}