Skip to content

Commit

Permalink
feat(combos): do not interrupt combo on active combo release
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbb committed Dec 20, 2024
1 parent 5a26255 commit 11c58a8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/src/combo.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ static bool is_key_part_of_any_combo(int32_t position) {

static int position_state_up(const zmk_event_t *ev, struct zmk_position_state_changed *data) {
// Check if the released key is part of any combo candidate or active combo
if (is_key_part_of_any_combo(data->position)) {
if (is_key_part_of_candidate(data->position)) {
int released_keys = cleanup();
if (release_combo_key(data->position, data->timestamp)) {
return ZMK_EV_EVENT_HANDLED;
Expand All @@ -521,7 +521,12 @@ static int position_state_up(const zmk_event_t *ev, struct zmk_position_state_ch
ZMK_EVENT_RAISE(dupe_ev);
return ZMK_EV_EVENT_CAPTURED;
}
} else if (is_key_part_of_active_combo(data->position)) {
if (release_combo_key(data->position, data->timestamp)) {
return ZMK_EV_EVENT_HANDLED;
}
}

release_pressed_key(data->position);
return ZMK_EV_EVENT_BUBBLE;
}
Expand Down
1 change: 1 addition & 0 deletions app/tests/combo/other-key-release-2/events.patterns
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s/.*hid_listener_keycode_//p
4 changes: 4 additions & 0 deletions app/tests/combo/other-key-release-2/keycode_events.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
57 changes: 57 additions & 0 deletions app/tests/combo/other-key-release-2/native_posix_64.keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>

/*
Combo on positions 01 and 23.

- press 2 and 3
- press 0
- release 2
- press 1
- release the rest

Both combos should actuate.
*/

/ {
combos {
compatible = "zmk,combos";

combo_a {
timeout-ms = <50>;
key-positions = <0 1>;
bindings = <&kp A>;
};

combo_b {
timeout-ms = <50>;
key-positions = <2 3>;
bindings = <&kp B>;
};
};

keymap {
compatible = "zmk,keymap";

default_layer {
bindings = <
&kp N0 &kp N1
&kp N2 &kp N3
>;
};
};
};

&kscan {
events = <
ZMK_MOCK_PRESS(1,0,10)
ZMK_MOCK_PRESS(1,1,10)
ZMK_MOCK_PRESS(0,0,10)
ZMK_MOCK_RELEASE(1,0,10)
ZMK_MOCK_PRESS(0,1,10)
ZMK_MOCK_RELEASE(1,1,0)
ZMK_MOCK_RELEASE(0,0,0)
ZMK_MOCK_RELEASE(0,1,0)
>;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00
pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00

0 comments on commit 11c58a8

Please sign in to comment.