refactor(behaviors): Giving global-quick-tap its own term
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.
This commit is contained in:
parent
aa4cb143bf
commit
2f6abff3bc
11 changed files with 24 additions and 16 deletions
|
@ -20,8 +20,11 @@ properties:
|
||||||
default: -1
|
default: -1
|
||||||
quick_tap_ms: # deprecated
|
quick_tap_ms: # deprecated
|
||||||
type: int
|
type: int
|
||||||
global-quick-tap:
|
global-quick-tap: # deprecated
|
||||||
type: boolean
|
type: boolean
|
||||||
|
global-quick-tap-ms:
|
||||||
|
type: int
|
||||||
|
default: -1
|
||||||
flavor:
|
flavor:
|
||||||
type: string
|
type: string
|
||||||
required: false
|
required: false
|
||||||
|
|
|
@ -57,7 +57,7 @@ struct behavior_hold_tap_config {
|
||||||
char *hold_behavior_dev;
|
char *hold_behavior_dev;
|
||||||
char *tap_behavior_dev;
|
char *tap_behavior_dev;
|
||||||
int quick_tap_ms;
|
int quick_tap_ms;
|
||||||
bool global_quick_tap;
|
int global_quick_tap_ms;
|
||||||
enum flavor flavor;
|
enum flavor flavor;
|
||||||
bool retro_tap;
|
bool retro_tap;
|
||||||
bool hold_trigger_on_release;
|
bool hold_trigger_on_release;
|
||||||
|
@ -97,7 +97,9 @@ struct last_tapped {
|
||||||
int64_t timestamp;
|
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) {
|
static void store_last_tapped(int64_t timestamp) {
|
||||||
if (timestamp > last_tapped.timestamp) {
|
if (timestamp > last_tapped.timestamp) {
|
||||||
|
@ -112,10 +114,11 @@ static void store_last_hold_tapped(struct active_hold_tap *hold_tap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_quick_tap(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) {
|
if ((last_tapped.timestamp + hold_tap->config->global_quick_tap_ms) > hold_tap->timestamp) {
|
||||||
return (last_tapped.timestamp + hold_tap->config->quick_tap_ms) > hold_tap->timestamp;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return (last_tapped.position == hold_tap->position) &&
|
||||||
|
(last_tapped.timestamp + hold_tap->config->quick_tap_ms) > hold_tap->timestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,7 +706,9 @@ static int behavior_hold_tap_init(const struct device *dev) {
|
||||||
.hold_behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(n, bindings, 0), label), \
|
.hold_behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(n, bindings, 0), label), \
|
||||||
.tap_behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(n, bindings, 1), label), \
|
.tap_behavior_dev = DT_PROP(DT_INST_PHANDLE_BY_IDX(n, bindings, 1), label), \
|
||||||
.quick_tap_ms = DT_INST_PROP(n, quick_tap_ms), \
|
.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), \
|
.flavor = DT_ENUM_IDX(DT_DRV_INST(n), flavor), \
|
||||||
.retro_tap = DT_INST_PROP(n, retro_tap), \
|
.retro_tap = DT_INST_PROP(n, retro_tap), \
|
||||||
.hold_trigger_on_release = DT_INST_PROP(n, hold_trigger_on_release), \
|
.hold_trigger_on_release = DT_INST_PROP(n, hold_trigger_on_release), \
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
events = <
|
events = <
|
||||||
/* tap */
|
/* tap */
|
||||||
ZMK_MOCK_PRESS(0,0,10)
|
ZMK_MOCK_PRESS(0,0,10)
|
||||||
ZMK_MOCK_RELEASE(0,0,10)
|
ZMK_MOCK_RELEASE(0,0,250)
|
||||||
/* normal quick tap */
|
/* normal quick tap */
|
||||||
ZMK_MOCK_PRESS(0,0,400)
|
ZMK_MOCK_PRESS(0,0,400)
|
||||||
ZMK_MOCK_RELEASE(0,0,400)
|
ZMK_MOCK_RELEASE(0,0,400)
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
flavor = "balanced";
|
flavor = "balanced";
|
||||||
tapping-term-ms = <300>;
|
tapping-term-ms = <300>;
|
||||||
quick-tap-ms = <300>;
|
quick-tap-ms = <300>;
|
||||||
|
global-quick-tap-ms = <100>;
|
||||||
bindings = <&kp>, <&kp>;
|
bindings = <&kp>, <&kp>;
|
||||||
global-quick-tap;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
events = <
|
events = <
|
||||||
/* tap */
|
/* tap */
|
||||||
ZMK_MOCK_PRESS(0,0,10)
|
ZMK_MOCK_PRESS(0,0,10)
|
||||||
ZMK_MOCK_RELEASE(0,0,10)
|
ZMK_MOCK_RELEASE(0,0,250)
|
||||||
/* normal quick tap */
|
/* normal quick tap */
|
||||||
ZMK_MOCK_PRESS(0,0,400)
|
ZMK_MOCK_PRESS(0,0,400)
|
||||||
ZMK_MOCK_RELEASE(0,0,400)
|
ZMK_MOCK_RELEASE(0,0,400)
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
flavor = "hold-preferred";
|
flavor = "hold-preferred";
|
||||||
tapping-term-ms = <300>;
|
tapping-term-ms = <300>;
|
||||||
quick-tap-ms = <300>;
|
quick-tap-ms = <300>;
|
||||||
|
global-quick-tap-ms = <100>;
|
||||||
bindings = <&kp>, <&kp>;
|
bindings = <&kp>, <&kp>;
|
||||||
global-quick-tap;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
events = <
|
events = <
|
||||||
/* tap */
|
/* tap */
|
||||||
ZMK_MOCK_PRESS(0,0,10)
|
ZMK_MOCK_PRESS(0,0,10)
|
||||||
ZMK_MOCK_RELEASE(0,0,10)
|
ZMK_MOCK_RELEASE(0,0,250)
|
||||||
/* normal quick tap */
|
/* normal quick tap */
|
||||||
ZMK_MOCK_PRESS(0,0,400)
|
ZMK_MOCK_PRESS(0,0,400)
|
||||||
ZMK_MOCK_RELEASE(0,0,400)
|
ZMK_MOCK_RELEASE(0,0,400)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
&kscan {
|
&kscan {
|
||||||
events = <
|
events = <
|
||||||
/* hold the first mod tap */
|
/* hold the first mod tap */
|
||||||
ZMK_MOCK_PRESS(0,0,400)
|
ZMK_MOCK_PRESS(0,0,10)
|
||||||
/* hold the second mod tap */
|
/* hold the second mod tap */
|
||||||
ZMK_MOCK_PRESS(0,1,400)
|
ZMK_MOCK_PRESS(0,1,400)
|
||||||
/* press the normal key */
|
/* press the normal key */
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
flavor = "tap-preferred";
|
flavor = "tap-preferred";
|
||||||
tapping-term-ms = <300>;
|
tapping-term-ms = <300>;
|
||||||
quick-tap-ms = <300>;
|
quick-tap-ms = <300>;
|
||||||
|
global-quick-tap-ms = <100>;
|
||||||
bindings = <&kp>, <&kp>;
|
bindings = <&kp>, <&kp>;
|
||||||
global-quick-tap;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
events = <
|
events = <
|
||||||
/* tap */
|
/* tap */
|
||||||
ZMK_MOCK_PRESS(0,0,10)
|
ZMK_MOCK_PRESS(0,0,10)
|
||||||
ZMK_MOCK_RELEASE(0,0,10)
|
ZMK_MOCK_RELEASE(0,0,250)
|
||||||
/* normal quick tap */
|
/* normal quick tap */
|
||||||
ZMK_MOCK_PRESS(0,0,400)
|
ZMK_MOCK_PRESS(0,0,400)
|
||||||
ZMK_MOCK_RELEASE(0,0,400)
|
ZMK_MOCK_RELEASE(0,0,400)
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
flavor = "tap-unless-interrupted";
|
flavor = "tap-unless-interrupted";
|
||||||
tapping-term-ms = <300>;
|
tapping-term-ms = <300>;
|
||||||
quick-tap-ms = <300>;
|
quick-tap-ms = <300>;
|
||||||
|
global-quick-tap-ms = <100>;
|
||||||
bindings = <&kp>, <&kp>;
|
bindings = <&kp>, <&kp>;
|
||||||
global-quick-tap;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue