From e00eceb5089d50fce2e298628c5bcf6c3b0596cd Mon Sep 17 00:00:00 2001 From: Okke Formsma Date: Mon, 30 Nov 2020 22:02:57 +0100 Subject: fix(sticky keys): fix tapping-sticky-keys bug. Sticky keys should be cleared when they were tapped in rapid succession before the timer runs out. --- app/src/behaviors/behavior_sticky_key.c | 10 +++++--- .../sticky-keys/9-sk-dn-up-dn-up/events.patterns | 1 + .../9-sk-dn-up-dn-up/keycode_events.snapshot | 4 ++++ .../9-sk-dn-up-dn-up/native_posix.keymap | 27 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 app/tests/sticky-keys/9-sk-dn-up-dn-up/events.patterns create mode 100644 app/tests/sticky-keys/9-sk-dn-up-dn-up/keycode_events.snapshot create mode 100644 app/tests/sticky-keys/9-sk-dn-up-dn-up/native_posix.keymap (limited to 'app') diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index 7a7f136..3ea5868 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -127,9 +127,13 @@ static int on_sticky_key_binding_pressed(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event) { struct device *dev = device_get_binding(binding->behavior_dev); const struct behavior_sticky_key_config *cfg = dev->config_info; - - struct active_sticky_key *sticky_key = - store_sticky_key(event.position, binding->param1, binding->param2, cfg); + struct active_sticky_key *sticky_key; + sticky_key = find_sticky_key(event.position); + if (sticky_key != NULL) { + stop_timer(sticky_key); + release_sticky_key_behavior(sticky_key, event.timestamp); + } + sticky_key = store_sticky_key(event.position, binding->param1, binding->param2, cfg); if (sticky_key == NULL) { LOG_ERR("unable to store sticky key, did you press more than %d sticky_key?", ZMK_BHV_STICKY_KEY_MAX_HELD); diff --git a/app/tests/sticky-keys/9-sk-dn-up-dn-up/events.patterns b/app/tests/sticky-keys/9-sk-dn-up-dn-up/events.patterns new file mode 100644 index 0000000..833100f --- /dev/null +++ b/app/tests/sticky-keys/9-sk-dn-up-dn-up/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode_//p \ No newline at end of file diff --git a/app/tests/sticky-keys/9-sk-dn-up-dn-up/keycode_events.snapshot b/app/tests/sticky-keys/9-sk-dn-up-dn-up/keycode_events.snapshot new file mode 100644 index 0000000..bfe7f61 --- /dev/null +++ b/app/tests/sticky-keys/9-sk-dn-up-dn-up/keycode_events.snapshot @@ -0,0 +1,4 @@ +pressed: usage_page 0x07 keycode 0xe1 mods 0x00 +released: usage_page 0x07 keycode 0xe1 mods 0x00 +pressed: usage_page 0x07 keycode 0xe1 mods 0x00 +released: usage_page 0x07 keycode 0xe1 mods 0x00 diff --git a/app/tests/sticky-keys/9-sk-dn-up-dn-up/native_posix.keymap b/app/tests/sticky-keys/9-sk-dn-up-dn-up/native_posix.keymap new file mode 100644 index 0000000..2fcc3ff --- /dev/null +++ b/app/tests/sticky-keys/9-sk-dn-up-dn-up/native_posix.keymap @@ -0,0 +1,27 @@ +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &sk LEFT_SHIFT &none + &none &none + >; + }; + }; +}; + +&kscan { + events = < + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,10) + /* the sticky key is pressed again, so the previous one must be cancelled */ + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,1200) + >; +}; \ No newline at end of file -- cgit v1.2.3