Properly integrating global quick tap as an option
This commit is contained in:
parent
ff0b1149ea
commit
17883dc0a1
2 changed files with 22 additions and 10 deletions
|
@ -20,6 +20,8 @@ properties:
|
||||||
default: -1
|
default: -1
|
||||||
quick_tap_ms: # deprecated
|
quick_tap_ms: # deprecated
|
||||||
type: int
|
type: int
|
||||||
|
global-quick-tap:
|
||||||
|
type: boolean
|
||||||
flavor:
|
flavor:
|
||||||
type: string
|
type: string
|
||||||
required: false
|
required: false
|
||||||
|
|
|
@ -57,6 +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;
|
||||||
enum flavor flavor;
|
enum flavor flavor;
|
||||||
bool retro_tap;
|
bool retro_tap;
|
||||||
int32_t hold_trigger_key_positions_len;
|
int32_t hold_trigger_key_positions_len;
|
||||||
|
@ -88,22 +89,30 @@ struct active_hold_tap active_hold_taps[ZMK_BHV_HOLD_TAP_MAX_HELD] = {};
|
||||||
// We capture most position_state_changed events and some modifiers_state_changed events.
|
// We capture most position_state_changed events and some modifiers_state_changed events.
|
||||||
const zmk_event_t *captured_events[ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS] = {};
|
const zmk_event_t *captured_events[ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS] = {};
|
||||||
|
|
||||||
// Keep track of which key was tapped most recently for 'quick_tap_ms'
|
// Keep track of which hold tap key was tapped most recently for the standard
|
||||||
struct last_tapped {
|
// 'quick_tap_ms' implementation
|
||||||
|
struct last_hold_tapped {
|
||||||
int32_t position;
|
int32_t position;
|
||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct last_tapped last_tapped;
|
struct last_hold_tapped last_hold_tapped;
|
||||||
|
|
||||||
static void store_last_tapped(int32_t position, int64_t timestamp) {
|
static void store_last_hold_tapped(struct active_hold_tap *hold_tap) {
|
||||||
last_tapped.position = position;
|
last_hold_tapped.position = hold_tap->position;
|
||||||
last_tapped.timestamp = timestamp;
|
last_hold_tapped.timestamp = hold_tap->timestamp + hold_tap->config->quick_tap_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For global quick tap we just keep track of when the last key was pressed last
|
||||||
|
int64_t last_key_tapped_timestamp;
|
||||||
|
|
||||||
static bool is_quick_tap(struct active_hold_tap *hold_tap) {
|
static bool is_quick_tap(struct active_hold_tap *hold_tap) {
|
||||||
return //last_tapped.position == hold_tap->position &&
|
if (hold_tap->config->global_quick_tap) {
|
||||||
last_tapped.timestamp + hold_tap->config->quick_tap_ms > hold_tap->timestamp;
|
return (last_key_tapped_timestamp + hold_tap->config->quick_tap_ms) > hold_tap->timestamp;
|
||||||
|
} else {
|
||||||
|
return last_hold_tapped.position == hold_tap->position &&
|
||||||
|
last_hold_tapped.timestamp > hold_tap->timestamp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int capture_event(const zmk_event_t *event) {
|
static int capture_event(const zmk_event_t *event) {
|
||||||
|
@ -362,7 +371,7 @@ static int press_binding(struct active_hold_tap *hold_tap) {
|
||||||
} else {
|
} else {
|
||||||
binding.behavior_dev = hold_tap->config->tap_behavior_dev;
|
binding.behavior_dev = hold_tap->config->tap_behavior_dev;
|
||||||
binding.param1 = hold_tap->param_tap;
|
binding.param1 = hold_tap->param_tap;
|
||||||
/* store_last_tapped(hold_tap); */
|
store_last_hold_tapped(hold_tap);
|
||||||
}
|
}
|
||||||
return behavior_keymap_binding_pressed(&binding, event);
|
return behavior_keymap_binding_pressed(&binding, event);
|
||||||
}
|
}
|
||||||
|
@ -620,7 +629,7 @@ static int keycode_state_changed_listener(const zmk_event_t *eh) {
|
||||||
struct zmk_keycode_state_changed *ev = as_zmk_keycode_state_changed(eh);
|
struct zmk_keycode_state_changed *ev = as_zmk_keycode_state_changed(eh);
|
||||||
|
|
||||||
if (ev->state && !is_mod(ev->usage_page, ev->keycode)) {
|
if (ev->state && !is_mod(ev->usage_page, ev->keycode)) {
|
||||||
store_last_tapped(0, ev->timestamp);
|
last_key_tapped_timestamp = ev->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (undecided_hold_tap == NULL) {
|
if (undecided_hold_tap == NULL) {
|
||||||
|
@ -687,6 +696,7 @@ static struct behavior_hold_tap_data behavior_hold_tap_data;
|
||||||
.hold_behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(n, bindings, 0)), \
|
.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)), \
|
.tap_behavior_dev = DT_LABEL(DT_INST_PHANDLE_BY_IDX(n, bindings, 1)), \
|
||||||
.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), \
|
||||||
.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_key_positions = DT_INST_PROP(n, hold_trigger_key_positions), \
|
.hold_trigger_key_positions = DT_INST_PROP(n, hold_trigger_key_positions), \
|
||||||
|
|
Loading…
Add table
Reference in a new issue