feat(leader): default to timerless

This commit is contained in:
Nick Conway 2025-06-15 16:23:51 -04:00
parent ee2e6e5a4a
commit 18a636cdbf
No known key found for this signature in database
GPG Key ID: AA850592E4C1D453
7 changed files with 11 additions and 27 deletions

View File

@ -8,8 +8,6 @@ compatible: "zmk,behavior-leader-key"
include: zero_param.yaml
properties:
timerless:
type: boolean
timeout-ms:
type: int
default: 200
default: -1

View File

@ -6,5 +6,5 @@
#pragma once
void zmk_leader_activate(int32_t timeout, bool timeout_on_activation, uint32_t position);
void zmk_leader_activate(int32_t timeout, uint32_t position);
void zmk_leader_deactivate();

View File

@ -20,7 +20,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
struct behavior_leader_key_config {
int32_t timeout_ms;
bool timerless;
};
static int behavior_leader_key_init(const struct device *dev) { return 0; }
@ -30,7 +29,7 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
const struct device *dev = device_get_binding(binding->behavior_dev);
const struct behavior_leader_key_config *cfg = dev->config;
zmk_leader_activate(cfg->timeout_ms, cfg->timerless, event.position);
zmk_leader_activate(cfg->timeout_ms, event.position);
return ZMK_BEHAVIOR_OPAQUE;
}
@ -46,7 +45,7 @@ static const struct behavior_driver_api behavior_leader_key_driver_api = {
#define LEAD_INST(n) \
static struct behavior_leader_key_config behavior_leader_key_config_##n = { \
.timerless = DT_INST_PROP(n, timerless), .timeout_ms = DT_INST_PROP(n, timeout_ms)}; \
.timeout_ms = DT_INST_PROP(n, timeout_ms)}; \
BEHAVIOR_DT_INST_DEFINE(n, behavior_leader_key_init, NULL, NULL, \
&behavior_leader_key_config_##n, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_leader_key_driver_api);

View File

@ -37,7 +37,6 @@ static struct k_work_delayable release_timer;
static int64_t release_at;
// static bool timer_started;
static bool timer_cancelled;
static bool timerless;
struct leader_seq_cfg {
int32_t key_positions[CONFIG_ZMK_LEADER_MAX_KEYS_PER_SEQUENCE];
@ -234,7 +233,7 @@ static void reset_timer(int32_t timestamp) {
}
}
void zmk_leader_activate(int32_t timeout, bool _timerless, uint32_t position) {
void zmk_leader_activate(int32_t timeout, uint32_t position) {
LOG_DBG("leader key activated");
leader_status = true;
press_count = 0;
@ -243,10 +242,11 @@ void zmk_leader_activate(int32_t timeout, bool _timerless, uint32_t position) {
active_leader_position = position;
layer = zmk_keymap_highest_layer_active();
first_release = false;
timerless = _timerless;
if (!timerless) {
if (timeout_ms > 0) {
reset_timer(k_uptime_get());
}
for (int i = 0; i < CONFIG_ZMK_LEADER_MAX_KEYS_PER_SEQUENCE; i++) {
leader_pressed_keys[i] = NULL;
}
@ -328,7 +328,8 @@ static int position_state_changed_listener(const zmk_event_t *ev) {
zmk_leader_deactivate();
}
}
if (!timerless || num_comp_candidates < num_candidates) {
if (timeout_ms > 0 || num_comp_candidates < num_candidates) {
reset_timer(data->timestamp);
}
}

View File

@ -2,11 +2,6 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
&leader {
timeout-ms = <200>;
timerless;
};
/ {
leader-sequences {
compatible = "zmk,leader-sequences";

View File

@ -2,11 +2,6 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
&leader {
timeout-ms = <200>;
timerless;
};
/ {
leader-sequences {
compatible = "zmk,leader-sequences";

View File

@ -21,7 +21,7 @@ Example:
#### `timeout-ms`
Defines the amount of time to wait to trigger a completed leader sequence. Defaults to 200ms.
Defines the amount of time to wait to trigger a completed leader sequence. Defaults to no timeout and will wait indefinitely.
To change the timeout term, you can update the existing behavior:
@ -36,7 +36,3 @@ To change the timeout term, you can update the existing behavior:
};
};
```
#### `timerless`
By default, the leader key will have a timeout, and will not wait for a sequence to be completed or another key to be pressed. Specify `timerless` if you don't want a timeout.