From 4ccc7f91b990db14ec56ce37053d6f34bde75288 Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Fri, 25 Oct 2024 23:28:53 -0400 Subject: [PATCH] Introduce delayed overload this is (for now) a copy of the regular overload; in the future it will mimic the delayed keys of ahm, in the sense that no modifier or key will be simulated on keypress, but we will wait until either keyrelease or another key pressed to make a decision. --- src/config.c | 3 +-- src/config.h | 1 + src/keyboard.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index 0a4a1c9..9772c30 100644 --- a/src/config.c +++ b/src/config.c @@ -57,7 +57,7 @@ static struct { { "oneshotm", NULL, OP_ONESHOTM, { ARG_LAYER, ARG_MACRO } }, { "layer", NULL, OP_LAYER, { ARG_LAYER } }, - + { "overloadd", NULL, OP_OVERLOAD_DELAYED, {ARG_LAYER, ARG_DESCRIPTOR}}, { "overload", NULL, OP_OVERLOAD, { ARG_LAYER, ARG_DESCRIPTOR } }, { "overloadt", NULL, OP_OVERLOAD_TIMEOUT, { ARG_LAYER, ARG_DESCRIPTOR, ARG_TIMEOUT } }, { "overloadt2", NULL, OP_OVERLOAD_TIMEOUT_TAP, { ARG_LAYER, ARG_DESCRIPTOR, ARG_TIMEOUT } }, @@ -1027,4 +1027,3 @@ int config_add_entry(struct config *config, const char *exp) return set_layer_entry(config, layer, keyname, &d); } - diff --git a/src/config.h b/src/config.h index c108acf..7e08829 100644 --- a/src/config.h +++ b/src/config.h @@ -47,6 +47,7 @@ enum op { OP_MACRO2, OP_COMMAND, OP_TIMEOUT, + OP_OVERLOAD_DELAYED, /* Experimental */ OP_SCROLL_TOGGLE_ON, diff --git a/src/keyboard.c b/src/keyboard.c index 546e985..f0bedeb 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -662,6 +662,37 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, } } + break; + case OP_OVERLOAD_DELAYED: //At the moment this is just a copy of overload + dbg("overload_delayed"); + idx = d->args[0].idx; + action = &kbd->config.descriptors[d->args[1].idx]; + + if (pressed) { + kbd->overload_start_time = time; + activate_layer(kbd, code, idx); + update_mods(kbd, -1, 0); + } else { + deactivate_layer(kbd, idx); + update_mods(kbd, -1, 0); + + if (kbd->last_pressed_code == code && + (!kbd->config.overload_tap_timeout || + ((time - kbd->overload_start_time) < kbd->config.overload_tap_timeout))) { + if (action->op == OP_MACRO) { + /* + * Macro release relies on event logic, so we can't just synthesize a + * descriptor release. + */ + struct macro *macro = &kbd->config.macros[action->args[0].idx]; + execute_macro(kbd, dl, macro); + } else { + process_descriptor(kbd, code, action, dl, 1, time); + process_descriptor(kbd, code, action, dl, 0, time); + } + } + } + break; case OP_ONESHOTM: case OP_ONESHOT: