From 5836897bf06ca50eb81eb83dcd13dc1d3c176a3e Mon Sep 17 00:00:00 2001 From: Raheman Vaiya Date: Mon, 18 Apr 2022 03:24:30 -0400 Subject: [PATCH] feature: Allow timeouts to be used in conjunction with + (#181) This patch allows macro chains of the form key1+key2 to be punctuated with timeouts. It is mainly useful to account for broken software which assumes human-scale timeouts between key down and key up events. E.G leftcontrol+n+30ms will force a 30ms delay between ' ' and the subsequent ' '. --- src/descriptor.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/descriptor.c b/src/descriptor.c index 8f7a6b0..d0e7244 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -219,20 +219,24 @@ static int do_parse_macro(struct macro *macro, char *s) if (!parse_sequence(tok, &code, &mods)) { macro_add(macro, MACRO_KEYSEQUENCE, (mods << 8) | code); - } else if (len > 1 && tok[len-2] == 'm' && tok[len-1] == 's') { - macro_add(macro, MACRO_TIMEOUT, atoi(tok)); } else if (strchr(tok, '+')) { char *saveptr; char *key; for (key = strtok_r(tok, "+", &saveptr); key; key = strtok_r(NULL, "+", &saveptr)) { - if (parse_sequence(key, &code, &mods)) - return -1; + size_t len = strlen(key); - macro_add(macro, MACRO_HOLD, code); + if (len > 1 && key[len-2] == 'm' && key[len-1] == 's') + macro_add(macro, MACRO_TIMEOUT, atoi(key)); + else if (!parse_sequence(key, &code, &mods)) + macro_add(macro, MACRO_HOLD, code); + else + return -1; } macro_add(macro, MACRO_RELEASE, 0); + } else if (len > 1 && tok[len-2] == 'm' && tok[len-1] == 's') { + macro_add(macro, MACRO_TIMEOUT, atoi(tok)); } else { uint32_t codepoint; int chrsz;