Skip to content

feat(behaviors): Swapper implementation#1366

Closed
nickconway wants to merge 6 commits into
zmkfirmware:mainfrom
nickconway:smart-interrupt
Closed

feat(behaviors): Swapper implementation#1366
nickconway wants to merge 6 commits into
zmkfirmware:mainfrom
nickconway:smart-interrupt

Conversation

@nickconway

Copy link
Copy Markdown
Contributor

Implementation of #997. Smart interrupt is probably not the name we should use, but I was out of ideas, help wanted!

@dxmh dxmh added behaviors enhancement New feature or request labels Jun 30, 2022
caksoylar added a commit to caksoylar/zmk-config that referenced this pull request Jul 20, 2022
caksoylar added a commit to caksoylar/zmk-config that referenced this pull request Jul 20, 2022
caksoylar added a commit to caksoylar/zmk-config that referenced this pull request Jul 20, 2022
caksoylar added a commit to caksoylar/zmk-config that referenced this pull request Jul 20, 2022
@caksoylar

Copy link
Copy Markdown
Contributor

I have been testing the window swapper implementation as in the example for the last day and it is working well so far. It neatly fixes #997 using a combination of first and second approaches proposed in there.

caksoylar added a commit to caksoylar/zmk-config that referenced this pull request Jul 21, 2022

@petejohanson petejohanson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Love the idea, and the general approach.

A few thoughts on implementation details/changes added here.

As far as naming.... Let me ponder. "Smart Interrupt" certainly feels better than "Swapper", but I'm curious if anyone has any other ideas for a better name. I also think "smart" is superfluous... A lot of what ZMK does is "smart", so it feels odd to include it in the naming for just this one behavior.

  • "Three Phase Behavior"
  • *Tri-Phase Behavior"
  • "Start/Continue/End Behavior"
  • "Tri-State Behavior"

Just a few that come to mind as food for thought.

Comment thread app/dts/bindings/behaviors/zmk,behavior-smart-interrupt.yaml Outdated
Comment thread docs/docs/behaviors/smart-interrupt.md Outdated
Comment thread app/dts/bindings/behaviors/zmk,behavior-smart-interrupt.yaml Outdated
Comment thread app/src/behaviors/behavior_smart_interrupt.c Outdated
struct zmk_behavior_binding *behaviors;
int32_t shared_layers[32];
int32_t timeout_ms;
int32_t shared_key_positions[];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, could be a bitmask instead of this "sparse" array.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the discussion on discord this is a bit tricky since the keymap can be any length. I've changed it to 8-bit ints for now but will keep working on a better solution.

Comment thread app/src/behaviors/behavior_smart_interrupt.c Outdated
Comment thread app/src/behaviors/behavior_smart_interrupt.c Outdated
Comment thread app/src/behaviors/behavior_smart_interrupt.c Outdated
Comment thread app/src/behaviors/behavior_smart_interrupt.c Outdated
Comment thread app/src/behaviors/behavior_smart_interrupt.c Outdated
@caksoylar

Copy link
Copy Markdown
Contributor

About the "tri-state" naming: It might be confusable with the "tri-layer" (lower+raise = adjust) pattern that we support with conditional layers.

caksoylar added a commit to caksoylar/zmk-config that referenced this pull request Jul 31, 2022
@nickconway

Copy link
Copy Markdown
Contributor Author

About the "tri-state" naming: It might be confusable with the "tri-layer" (lower+raise = adjust) pattern that we support with conditional layers.

Maybe three-phase would be better, or would 'triplex' or 'treble' work here? Start/Continue/End Behavior gets the point across, but I feel like it's a bit too specific.

@caksoylar

Copy link
Copy Markdown
Contributor

I like the "bookend"/"sandwich" suggestions from @petejohanson personally, since it is like the repeatable "continue" behavior is bookended by special start and end events. Three-phase also sounds good.

caksoylar added a commit to caksoylar/zmk-config that referenced this pull request Aug 8, 2022
caksoylar added a commit to caksoylar/zmk-config that referenced this pull request Aug 9, 2022
caksoylar added a commit to caksoylar/zmk-config that referenced this pull request Sep 1, 2022
caksoylar added a commit to caksoylar/zmk-config that referenced this pull request Sep 1, 2022

@petejohanson petejohanson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An implementation comment... And then a bump again on naming... I'm on the fence on tri-state. @nickconway I didn't see you're thought on "bookend" concept for the name?

Comment thread app/src/behaviors/behavior_tri_state.c Outdated
Comment on lines +145 to +147
behavior_keymap_binding_pressed((struct zmk_behavior_binding *)&cfg->start_behavior, event);
behavior_keymap_binding_released((struct zmk_behavior_binding *)&cfg->start_behavior,
event);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we do this for hold taps right now, but any reason not to use the behavior queue here?

Comment thread app/src/behaviors/behavior_tri_state.c Outdated
event);
tri_state->first_press = false;
}
behavior_keymap_binding_pressed((struct zmk_behavior_binding *)&cfg->continue_behavior, event);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Comment thread app/src/behaviors/behavior_tri_state.c Outdated
Comment on lines +262 to +268
behavior_keymap_binding_released(
(struct zmk_behavior_binding *)&tri_state->config->continue_behavior, event);
}
behavior_keymap_binding_pressed(
(struct zmk_behavior_binding *)&tri_state->config->end_behavior, event);
behavior_keymap_binding_released(
(struct zmk_behavior_binding *)&tri_state->config->end_behavior, event);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

@petejohanson petejohanson self-assigned this Oct 8, 2022
caksoylar pushed a commit to caksoylar/zmk that referenced this pull request Oct 15, 2022
@nickconway

Copy link
Copy Markdown
Contributor Author

@petejohanson Apologies for the delay. I think the bookend name is much better. As for the behavior queue, my understanding was that the keymap_* functions would be used here since we want the action taken immediately?

caksoylar pushed a commit to caksoylar/zmk that referenced this pull request Nov 1, 2022
johnm added a commit to johnm/zmk that referenced this pull request Nov 6, 2022
caksoylar pushed a commit to caksoylar/zmk that referenced this pull request Nov 7, 2022
jdart pushed a commit to jdart/zmk that referenced this pull request Nov 18, 2022
caksoylar pushed a commit to caksoylar/zmk that referenced this pull request Nov 27, 2022
caksoylar pushed a commit to caksoylar/zmk that referenced this pull request Dec 5, 2022
caksoylar pushed a commit to caksoylar/zmk that referenced this pull request Dec 11, 2022
@davidsteinberger

Copy link
Copy Markdown

Thank you very much for all the effort. I gave it a try. Works when added directly to the keymap. When I add it via a combo though, it doesn't work. Does anybody have the same problem or a workaround?

@urob

urob commented Mar 21, 2024

Copy link
Copy Markdown
Contributor

Thank you very much for all the effort. I gave it a try. Works when added directly to the keymap. When I add it via a combo though, it doesn't work. Does anybody have the same problem or a workaround?

You have to include the combo locations in the ignore-positions. See #1366 (comment)

@davidsteinberger

davidsteinberger commented Mar 21, 2024

Copy link
Copy Markdown

@urob thank you very much!!! I just noticed my mistake. For others that want to use it with zmk-nodefree-config, here's how it works.

ZMK_COMBO(sw_app, &swapper, 21 22 23, ALL, 100)
// Alt+Tab swapper, requires PR #1366
ZMK_BEHAVIOR(swapper, tri_state,
    bindings = <&kt LGUI>, <&kp TAB>, <&kt LGUI>;
    timeout-ms = <500>;
    ignored-key-positions = <21 22 23>;
)

@nickconway nickconway requested a review from a team as a code owner April 15, 2024 21:14
allymparker added a commit to allymparker/zmk that referenced this pull request May 30, 2024
j-w-e added a commit to j-w-e/zmk that referenced this pull request Jun 5, 2024
@nickconway nickconway requested a review from a team as a code owner August 18, 2024 01:34
teskje added a commit to teskje/zmk that referenced this pull request Aug 30, 2024
dhruvinsh added a commit to dhruvinsh/zmk-tri-state that referenced this pull request Oct 18, 2024
teskje added a commit to teskje/zmk that referenced this pull request Jul 12, 2025
teskje added a commit to teskje/zmk that referenced this pull request Jul 12, 2025
@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had activity in 10 months. It will be closed in 14 days if no further activity occurs. Feel free to give a status update or re-open when it has been rebased and is ready for review (again). Thanks!

@github-actions github-actions Bot added the Stale label Apr 14, 2026
@github-actions

Copy link
Copy Markdown

This PR was closed because it had no activity for over 10 months. Feel free to give a status update or re-open when it has been rebased and is ready for review (again).

@nickconway

Copy link
Copy Markdown
Contributor Author

Reopened in #3373

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

behaviors enhancement New feature or request Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.