Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add layerm2() action #662

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/keyd.scdoc
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ A key may optionally be bound to an _action_ which accepts zero or more argument
*layerm(<layer>, <macro>)*
Identical to *layer*, but executes the supplied macro before the layer change.

*layerm2(<layer>, <macro 1>, <macro 2>)*
Identical to *layer*, but executes the supplied <macro 1> before the layer
change and <macro 2> after the layer change.

*oneshotm(<layer>, <macro>)*
Identical to *oneshot*, but executes the supplied macro before the layer change.

Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum op {
OP_ONESHOT,
OP_ONESHOTM,
OP_LAYERM,
OP_LAYERM2,
OP_SWAP,
OP_SWAPM,
OP_LAYER,
Expand Down
15 changes: 15 additions & 0 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -792,6 +794,19 @@ 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);
update_mods(kbd, -1, 0);
break;
default:
break;
}
}

if (pressed)
kbd->last_pressed_code = code;
Expand Down