diff --git a/data/keyd-application-mapper.1.gz b/data/keyd-application-mapper.1.gz index a3e5b22..b471924 100644 Binary files a/data/keyd-application-mapper.1.gz and b/data/keyd-application-mapper.1.gz differ diff --git a/data/keyd.1.gz b/data/keyd.1.gz index fc27dd5..b10335d 100644 Binary files a/data/keyd.1.gz and b/data/keyd.1.gz differ diff --git a/docs/keyd.scdoc b/docs/keyd.scdoc index 2882520..a74917a 100644 --- a/docs/keyd.scdoc +++ b/docs/keyd.scdoc @@ -467,6 +467,10 @@ arguments. *toggle()* Permanently toggle the state of the given layer. +*toggle2(, )* + Equivalent to *toggle*, but additionally executes the supplied macro before + toggling the layer. + *overload(, )* Activates the given layer while held and executes on tap. diff --git a/src/descriptor.c b/src/descriptor.c index 9fd9636..5ccbe8c 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -36,6 +36,7 @@ static struct { { "swap2", OP_SWAP2, { ARG_LAYER, ARG_MACRO } }, { "oneshot", OP_ONESHOT, { ARG_LAYER } }, { "toggle", OP_TOGGLE, { ARG_LAYER } }, + { "toggle2", OP_TOGGLE2, { ARG_LAYER, ARG_MACRO } }, { "layer", OP_LAYER, { ARG_LAYER } }, { "overload", OP_OVERLOAD, { ARG_LAYER, ARG_DESCRIPTOR } }, { "timeout", OP_TIMEOUT, { ARG_DESCRIPTOR, ARG_TIMEOUT, ARG_DESCRIPTOR } }, diff --git a/src/descriptor.h b/src/descriptor.h index 8aa243a..89dea61 100644 --- a/src/descriptor.h +++ b/src/descriptor.h @@ -25,6 +25,7 @@ enum op { OP_LAYER, OP_OVERLOAD, OP_TOGGLE, + OP_TOGGLE2, OP_MACRO, OP_MACRO2, diff --git a/src/keyboard.c b/src/keyboard.c index be09c13..3a53caa 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -483,16 +483,26 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code, } break; + case OP_TOGGLE2: case OP_TOGGLE: idx = d->args[0].idx; if (!pressed) { + if (d->op == OP_TOGGLE2) { + macro = &kbd->config.macros[d->args[1].idx]; + execute_macro(kbd, dl, macro); + } + kbd->layer_state[idx].toggled = !kbd->layer_state[idx].toggled; if (kbd->layer_state[idx].toggled) activate_layer(kbd, code, idx); else deactivate_layer(kbd, idx); + + update_mods(kbd, -1, 0); + } else { + clear_oneshot(kbd); } break; diff --git a/t/test.conf b/t/test.conf index 527a830..ce58f33 100644 --- a/t/test.conf +++ b/t/test.conf @@ -28,6 +28,7 @@ s = layer(shift) - = toggle(dvorak) = = timeout(a, 300, b) \ = 😄 +[ = toggle2(control, macro(one)) [layout2:layout] diff --git a/t/toggle-2.t b/t/toggle-2.t new file mode 100644 index 0000000..063fb5a --- /dev/null +++ b/t/toggle-2.t @@ -0,0 +1,25 @@ +2 down +2 up +t down +t up +b down +b up +b down +b up +t down +t up +b down +b up + +shift down +shift up +a down +a up +shift down +shift up +a down +a up +shift down +shift up +b down +b up diff --git a/t/toggle2.t b/t/toggle2.t index 063fb5a..cd87b2e 100644 --- a/t/toggle2.t +++ b/t/toggle2.t @@ -1,25 +1,23 @@ -2 down -2 up -t down -t up -b down -b up -b down -b up -t down -t up -b down -b up +[ down +[ up +k down +k up +[ down +[ up -shift down -shift up -a down -a up -shift down -shift up -a down -a up -shift down -shift up -b down -b up +o down +o up +n down +n up +e down +e up +control down +k down +k up +o down +o up +n down +n up +e down +e up +control up