Skip to content

Commit

Permalink
refactor(behaviors): Giving global-quick-tap its own term
Browse files Browse the repository at this point in the history
Detaching the global-quick-tap functionality from the quick-tap term.
This makes way for two improvements:

1. This functionality can be added to combos under a unified name
   'global-quick-tap-ms'.

2. This allows users to set a lower term for the 'global-quick-tap'
   (typically ~100ms), and a higher term for the regular
   quick-tap (typically ~200ms)

This deprecates the global-quick-tap option, however if it is set, the
quick-tap-ms value will be copied to global-quick-tap-ms.
  • Loading branch information
andrewjrae committed Jul 18, 2022
1 parent 3d2bd01 commit 073f73b
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 27 deletions.
5 changes: 4 additions & 1 deletion app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions app/src/behaviors/behavior_hold_tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
&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 */
ZMK_MOCK_PRESS(0,0,400)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
&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 */
ZMK_MOCK_PRESS(0,0,10)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
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 */
ZMK_MOCK_PRESS(0,0,400)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
&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 */
ZMK_MOCK_PRESS(0,0,400)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};

Expand Down

0 comments on commit 073f73b

Please sign in to comment.