From 2d3f879cb9c0b340857fdc9df785d1724e292141 Mon Sep 17 00:00:00 2001 From: Konstantin Vorobyev Date: Tue, 6 Feb 2024 11:03:30 +0100 Subject: [PATCH 1/2] Add layerm2() action --- docs/keyd.scdoc | 4 ++++ src/config.c | 1 + src/config.h | 1 + src/keyboard.c | 14 ++++++++++++++ 4 files changed, 20 insertions(+) diff --git a/docs/keyd.scdoc b/docs/keyd.scdoc index b641d916..eae8a87a 100644 --- a/docs/keyd.scdoc +++ b/docs/keyd.scdoc @@ -665,6 +665,10 @@ A key may optionally be bound to an _action_ which accepts zero or more argument *layerm(, )* Identical to *layer*, but executes the supplied macro before the layer change. +*layerm2(, , )* + Identical to *layer*, but executes the supplied before the layer + change and after the layer change. + *oneshotm(, )* Identical to *oneshot*, but executes the supplied macro before the layer change. diff --git a/src/config.c b/src/config.c index 44a67d37..3bc15c92 100644 --- a/src/config.c +++ b/src/config.c @@ -54,6 +54,7 @@ static struct { { "swapm", NULL, OP_SWAPM, { ARG_LAYER, ARG_MACRO } }, { "togglem", NULL, OP_TOGGLEM, { ARG_LAYER, ARG_MACRO } }, { "layerm", NULL, OP_LAYERM, { ARG_LAYER, ARG_MACRO } }, + { "layerm2", NULL, OP_LAYERM2, { ARG_LAYER, ARG_MACRO, ARG_MACRO } }, { "oneshotm", NULL, OP_ONESHOTM, { ARG_LAYER, ARG_MACRO } }, { "layer", NULL, OP_LAYER, { ARG_LAYER } }, diff --git a/src/config.h b/src/config.h index e961f5d6..374b0f73 100644 --- a/src/config.h +++ b/src/config.h @@ -30,6 +30,7 @@ enum op { OP_ONESHOT, OP_ONESHOTM, OP_LAYERM, + OP_LAYERM2, OP_SWAP, OP_SWAPM, OP_LAYER, diff --git a/src/keyboard.c b/src/keyboard.c index 581efc4c..5d29c722 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -484,6 +484,7 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, switch (d->op) { case OP_LAYERM: + case OP_LAYERM2: case OP_ONESHOTM: case OP_TOGGLEM: macro = &kbd->config.macros[d->args[1].idx]; @@ -585,6 +586,7 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, break; case OP_LAYERM: + case OP_LAYERM2: case OP_LAYER: idx = d->args[0].idx; @@ -792,6 +794,18 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, break; } + if (!pressed) { + struct macro *macro; + + switch (d->op) { + case OP_LAYERM2: + macro = &kbd->config.macros[d->args[2].idx]; + execute_macro(kbd, dl, macro); + break; + default: + break; + } + } if (pressed) kbd->last_pressed_code = code; From d38cec9a781541c70cc54528d32f3aadcf9e30db Mon Sep 17 00:00:00 2001 From: Konstantin Vorobyev Date: Sun, 18 Feb 2024 13:11:06 +0100 Subject: [PATCH 2/2] Fix mods state after release macro --- src/keyboard.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/keyboard.c b/src/keyboard.c index 5d29c722..f49bce2b 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -801,6 +801,7 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, case OP_LAYERM2: macro = &kbd->config.macros[d->args[2].idx]; execute_macro(kbd, dl, macro); + update_mods(kbd, -1, 0); break; default: break;