diff --git a/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml b/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml index e4cfaeab5d4..7be1d881b56 100644 --- a/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml +++ b/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml @@ -20,8 +20,11 @@ properties: default: -1 quick_tap_ms: # deprecated type: int - global-quick-tap: + global-quick-tap: # deprecated type: boolean + global-quick-tap-ms: + type: int + default: -1 flavor: type: string required: false diff --git a/app/src/behaviors/behavior_hold_tap.c b/app/src/behaviors/behavior_hold_tap.c index 413806b467f..0dcd356f8b7 100644 --- a/app/src/behaviors/behavior_hold_tap.c +++ b/app/src/behaviors/behavior_hold_tap.c @@ -57,7 +57,7 @@ struct behavior_hold_tap_config { char *hold_behavior_dev; char *tap_behavior_dev; int quick_tap_ms; - bool global_quick_tap; + int global_quick_tap_ms; enum flavor flavor; bool retro_tap; int32_t hold_trigger_key_positions_len; @@ -96,7 +96,9 @@ struct last_tapped { int64_t timestamp; }; -struct last_tapped last_tapped = {INT32_MIN, INT64_MIN}; +// Set time stamp to large negative number initially for test suites, but not +// int64 min since it will overflow if -1 is added +struct last_tapped last_tapped = {INT32_MIN, INT32_MIN}; static void store_last_tapped(int64_t timestamp) { if (timestamp > last_tapped.timestamp) { @@ -111,10 +113,11 @@ static void store_last_hold_tapped(struct active_hold_tap *hold_tap) { } static bool is_quick_tap(struct active_hold_tap *hold_tap) { - if (hold_tap->config->global_quick_tap || last_tapped.position == hold_tap->position) { - return (last_tapped.timestamp + hold_tap->config->quick_tap_ms) > hold_tap->timestamp; + if ((last_tapped.timestamp + hold_tap->config->global_quick_tap_ms) > hold_tap->timestamp) { + return true; } else { - return false; + return (last_tapped.position == hold_tap->position) && + (last_tapped.timestamp + hold_tap->config->quick_tap_ms) > hold_tap->timestamp; } } @@ -696,7 +699,9 @@ static int behavior_hold_tap_init(const struct device *dev) { .hold_behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(n, bindings, 0)), \ .tap_behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(n, bindings, 1)), \ .quick_tap_ms = DT_INST_PROP(n, quick_tap_ms), \ - .global_quick_tap = DT_INST_PROP(n, global_quick_tap), \ + .global_quick_tap_ms = DT_INST_PROP(n, global_quick_tap) \ + ? DT_INST_PROP(n, quick_tap_ms) \ + : DT_INST_PROP(n, global_quick_tap_ms), \ .flavor = DT_ENUM_IDX(DT_DRV_INST(n), flavor), \ .retro_tap = DT_INST_PROP(n, retro_tap), \ .hold_trigger_key_positions = DT_INST_PROP(n, hold_trigger_key_positions), \ diff --git a/app/tests/hold-tap/balanced/8-global-quick-tap/1-basic/native_posix_64.keymap b/app/tests/hold-tap/balanced/8-global-quick-tap/1-basic/native_posix_64.keymap index 930760553ab..4e49be7a42c 100644 --- a/app/tests/hold-tap/balanced/8-global-quick-tap/1-basic/native_posix_64.keymap +++ b/app/tests/hold-tap/balanced/8-global-quick-tap/1-basic/native_posix_64.keymap @@ -6,9 +6,9 @@ &kscan { events = < /* tap */ - ZMK_MOCK_PRESS(0,0,10) - ZMK_MOCK_RELEASE(0,0,10) - /* normal quick tap */ + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,250) + /* quick tap */ ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_RELEASE(0,0,400) /* hold */ @@ -16,7 +16,7 @@ ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_RELEASE(1,0,10) ZMK_MOCK_RELEASE(0,0,400) - /* global quick tap */ + /* min prior term */ ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_RELEASE(1,0,10) diff --git a/app/tests/hold-tap/balanced/8-global-quick-tap/behavior_keymap.dtsi b/app/tests/hold-tap/balanced/8-global-quick-tap/behavior_keymap.dtsi index 0966ce0d83c..efe07f63737 100644 --- a/app/tests/hold-tap/balanced/8-global-quick-tap/behavior_keymap.dtsi +++ b/app/tests/hold-tap/balanced/8-global-quick-tap/behavior_keymap.dtsi @@ -11,8 +11,8 @@ flavor = "balanced"; tapping-term-ms = <300>; quick-tap-ms = <300>; + global-quick-tap-ms = <100>; bindings = <&kp>, <&kp>; - global-quick-tap; }; }; diff --git a/app/tests/hold-tap/hold-preferred/8-global-quick-tap/1-basic/native_posix_64.keymap b/app/tests/hold-tap/hold-preferred/8-global-quick-tap/1-basic/native_posix_64.keymap index ee0d5e80a66..1a92b46d385 100644 --- a/app/tests/hold-tap/hold-preferred/8-global-quick-tap/1-basic/native_posix_64.keymap +++ b/app/tests/hold-tap/hold-preferred/8-global-quick-tap/1-basic/native_posix_64.keymap @@ -6,9 +6,9 @@ &kscan { events = < /* tap */ - ZMK_MOCK_PRESS(0,0,10) - ZMK_MOCK_RELEASE(0,0,10) - /* normal quick tap */ + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,250) + /* quick tap */ ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_RELEASE(0,0,400) /* hold */ @@ -16,7 +16,7 @@ ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_RELEASE(1,0,10) ZMK_MOCK_RELEASE(0,0,400) - /* global quick tap */ + /* min prior term */ ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_RELEASE(1,0,10) diff --git a/app/tests/hold-tap/hold-preferred/8-global-quick-tap/behavior_keymap.dtsi b/app/tests/hold-tap/hold-preferred/8-global-quick-tap/behavior_keymap.dtsi index fee3361e4b4..c1ba198c91d 100644 --- a/app/tests/hold-tap/hold-preferred/8-global-quick-tap/behavior_keymap.dtsi +++ b/app/tests/hold-tap/hold-preferred/8-global-quick-tap/behavior_keymap.dtsi @@ -11,8 +11,8 @@ flavor = "hold-preferred"; tapping-term-ms = <300>; quick-tap-ms = <300>; + global-quick-tap-ms = <100>; bindings = <&kp>, <&kp>; - global-quick-tap; }; }; diff --git a/app/tests/hold-tap/tap-preferred/8-global-quick-tap/1-basic/native_posix_64.keymap b/app/tests/hold-tap/tap-preferred/8-global-quick-tap/1-basic/native_posix_64.keymap index 930760553ab..85c36a7d0ac 100644 --- a/app/tests/hold-tap/tap-preferred/8-global-quick-tap/1-basic/native_posix_64.keymap +++ b/app/tests/hold-tap/tap-preferred/8-global-quick-tap/1-basic/native_posix_64.keymap @@ -7,8 +7,8 @@ events = < /* tap */ ZMK_MOCK_PRESS(0,0,10) - ZMK_MOCK_RELEASE(0,0,10) - /* normal quick tap */ + ZMK_MOCK_RELEASE(0,0,250) + /* quick tap */ ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_RELEASE(0,0,400) /* hold */ @@ -16,7 +16,7 @@ ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_RELEASE(1,0,10) ZMK_MOCK_RELEASE(0,0,400) - /* global quick tap */ + /* min prior term */ ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_RELEASE(1,0,10) diff --git a/app/tests/hold-tap/tap-preferred/8-global-quick-tap/2-double-hold/native_posix_64.keymap b/app/tests/hold-tap/tap-preferred/8-global-quick-tap/2-double-hold/native_posix_64.keymap index 37c37f55630..f64e7d8aebc 100644 --- a/app/tests/hold-tap/tap-preferred/8-global-quick-tap/2-double-hold/native_posix_64.keymap +++ b/app/tests/hold-tap/tap-preferred/8-global-quick-tap/2-double-hold/native_posix_64.keymap @@ -6,7 +6,7 @@ &kscan { events = < /* hold the first mod tap */ - ZMK_MOCK_PRESS(0,0,400) + ZMK_MOCK_PRESS(0,0,10) /* hold the second mod tap */ ZMK_MOCK_PRESS(0,1,400) /* press the normal key */ diff --git a/app/tests/hold-tap/tap-preferred/8-global-quick-tap/behavior_keymap.dtsi b/app/tests/hold-tap/tap-preferred/8-global-quick-tap/behavior_keymap.dtsi index 4771ab75895..975976639ae 100644 --- a/app/tests/hold-tap/tap-preferred/8-global-quick-tap/behavior_keymap.dtsi +++ b/app/tests/hold-tap/tap-preferred/8-global-quick-tap/behavior_keymap.dtsi @@ -11,8 +11,8 @@ flavor = "tap-preferred"; tapping-term-ms = <300>; quick-tap-ms = <300>; + global-quick-tap-ms = <100>; bindings = <&kp>, <&kp>; - global-quick-tap; }; }; diff --git a/app/tests/hold-tap/tap-unless-interrupted/6-global-quick-tap/1-basic/native_posix_64.keymap b/app/tests/hold-tap/tap-unless-interrupted/6-global-quick-tap/1-basic/native_posix_64.keymap index 930760553ab..4e49be7a42c 100644 --- a/app/tests/hold-tap/tap-unless-interrupted/6-global-quick-tap/1-basic/native_posix_64.keymap +++ b/app/tests/hold-tap/tap-unless-interrupted/6-global-quick-tap/1-basic/native_posix_64.keymap @@ -6,9 +6,9 @@ &kscan { events = < /* tap */ - ZMK_MOCK_PRESS(0,0,10) - ZMK_MOCK_RELEASE(0,0,10) - /* normal quick tap */ + ZMK_MOCK_PRESS(0,0,10) + ZMK_MOCK_RELEASE(0,0,250) + /* quick tap */ ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_RELEASE(0,0,400) /* hold */ @@ -16,7 +16,7 @@ ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_RELEASE(1,0,10) ZMK_MOCK_RELEASE(0,0,400) - /* global quick tap */ + /* min prior term */ ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_RELEASE(1,0,10) diff --git a/app/tests/hold-tap/tap-unless-interrupted/6-global-quick-tap/behavior_keymap.dtsi b/app/tests/hold-tap/tap-unless-interrupted/6-global-quick-tap/behavior_keymap.dtsi index 6ca7ac72702..d3c1d5f3035 100644 --- a/app/tests/hold-tap/tap-unless-interrupted/6-global-quick-tap/behavior_keymap.dtsi +++ b/app/tests/hold-tap/tap-unless-interrupted/6-global-quick-tap/behavior_keymap.dtsi @@ -11,8 +11,8 @@ flavor = "tap-unless-interrupted"; tapping-term-ms = <300>; quick-tap-ms = <300>; + global-quick-tap-ms = <100>; bindings = <&kp>, <&kp>; - global-quick-tap; }; };