From 57aa57b39e6fe9ff336a9186559e842898bddf85 Mon Sep 17 00:00:00 2001 From: Karl Fleischmann Date: Fri, 13 Feb 2026 13:37:52 +0100 Subject: [PATCH] daemon: structures, input - Store macro repetition delay if it was sent Macro commands currently come in the form "$macro:". This command extends the parsing of the payload to store a suffix ":" into the keymacro struct. --- src/daemon/input.c | 21 ++++++++++++++++++++- src/daemon/structures.h | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/daemon/input.c b/src/daemon/input.c index 194d1da4..d709d155 100644 --- a/src/daemon/input.c +++ b/src/daemon/input.c @@ -5,6 +5,7 @@ #include "input.h" #include "notify.h" #include +#include #define IS_SCROLLWHEEL_V(scan) ((scan) == BTN_WHEELUP || (scan) == BTN_WHEELDOWN) #define IS_SCROLLWHEEL_H(scan) ((scan) == BTN_WHEELLEFT || (scan) == BTN_WHEELRIGHT) @@ -673,8 +674,26 @@ static void _cmd_macro(usbmode* mode, const char* keys, const char* assignment, // Scan the actions position = 0; field = 0; + + // Check if repetition debounce and delay tokens are attached to the assignment. + // Validate value to be between 0 and 2000 inclusive. Default to 500ms. + const char *delay_tok = strchr(assignment, ':'); + macro.repetition_debounce_ms = 500; + macro.repetition_delay_ms = 500; + if (delay_tok != NULL) { + unsigned long debounce_ms = 0; + unsigned long delay_ms = 0; + + if (sscanf(delay_tok, ":%lu;%lu", &debounce_ms, &delay_ms) == 2) { + if (debounce_ms > 0 && debounce_ms <= 2000) + macro.repetition_debounce_ms = (uint32_t) debounce_ms; + if (delay_ms > 0 && delay_ms <= 2000) + macro.repetition_delay_ms = (uint32_t) delay_ms; + } + } + // max action = old 11 chars plus 12 chars which is the max 32-bit unsigned int 4294967295 size * 2 + 1 for range underscore - while(position < right && sscanf(assignment + position, "%"N_SCANF_KEYNAME"[^,]%n", keyname, &field) == 1){ + while(position < right && sscanf(assignment + position, "%"N_SCANF_KEYNAME"[^,:]%n", keyname, &field) == 1){ if(!strcmp(keyname, "clear")) break; diff --git a/src/daemon/structures.h b/src/daemon/structures.h index cd7d40a5..c2eba80a 100644 --- a/src/daemon/structures.h +++ b/src/daemon/structures.h @@ -57,6 +57,9 @@ typedef struct { */ char triggered; struct _macro_param* param; + + uint32_t repetition_debounce_ms; + uint32_t repetition_delay_ms; } keymacro; // Key bindings for a mode (keyboard + mouse)