Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEADER_NO_TIMEOUT_N #24581

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/features/leader_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ To remove the stress this situation produces to your hands, you can disable the

Now, after you hit the leader key, you will have an infinite amount of time to start the rest of the sequence, allowing you to properly position your hands to type the rest of the sequence comfortably. This way you can configure a very short `LEADER_TIMEOUT`, but still have plenty of time to position your hands.

### Disabling Timeout for aditional keystrokes {#disabling-timeout-more-keystrokes}

Aditionally, you may want to disable the timeout for additional keystrokes after the leader key.
Add the following to your `config.h`:
```c
#define LEADER_NO_TIMEOUT_FOR_N_KEYSTOKES <Number of keystrokes including leader>
```
Use with care, since sequences shorter than LEADER_NO_TIMEOUT_FOR_N_KEYSTOKES will not timeout, and thus will not terminate unless leader_end() is called.


### Strict Key Processing {#strict-key-processing}

By default, only the "tap keycode" portions of [Mod-Taps](../mod_tap) and [Layer Taps](../feature_layers#switching-and-toggling-layers) are added to the sequence buffer. This means if you press eg. `LT(3, KC_A)` as part of a sequence, `KC_A` will be added to the buffer, rather than the entire `LT(3, KC_A)` keycode.
Expand Down
8 changes: 6 additions & 2 deletions quantum/leader.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# define LEADER_TIMEOUT 300
#endif

#if defined(LEADER_NO_TIMEOUT) && !defined(LEADER_NO_TIMEOUT_FOR_N_KEYSTOKES)
# define LEADER_NO_TIMEOUT_FOR_N_KEYSTOKES 1
#endif

// Leader key stuff
bool leading = false;
uint16_t leader_time = 0;
Expand Down Expand Up @@ -53,7 +57,7 @@ bool leader_sequence_add(uint16_t keycode) {
}

#if defined(LEADER_NO_TIMEOUT)
if (leader_sequence_size == 0) {
if (leader_sequence_size < LEADER_NO_TIMEOUT_FOR_N_KEYSTOKES) {
leader_reset_timer();
}
#endif
Expand All @@ -66,7 +70,7 @@ bool leader_sequence_add(uint16_t keycode) {

bool leader_sequence_timed_out(void) {
#if defined(LEADER_NO_TIMEOUT)
return leader_sequence_size > 0 && timer_elapsed(leader_time) > LEADER_TIMEOUT;
return leader_sequence_size >= LEADER_NO_TIMEOUT_FOR_N_KEYSTOKES && timer_elapsed(leader_time) > LEADER_TIMEOUT;
#else
return timer_elapsed(leader_time) > LEADER_TIMEOUT;
#endif
Expand Down
9 changes: 9 additions & 0 deletions tests/leader/leader_no_initial_timeout_several_keys/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2023 QMK
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "test_common.h"

#define LEADER_NO_TIMEOUT
#define LEADER_NO_TIMEOUT_FOR_N_KEYSTOKES 2
7 changes: 7 additions & 0 deletions tests/leader/leader_no_initial_timeout_several_keys/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# --------------------------------------------------------------------------------
# Keep this file, even if it is empty, as a marker that this folder contains tests
# --------------------------------------------------------------------------------

LEADER_ENABLE = yes

SRC += ../leader_sequences.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2023 QMK
// SPDX-License-Identifier: GPL-2.0-or-later

#include "keyboard_report_util.hpp"
#include "keycode.h"
#include "test_common.hpp"
#include "test_keymap_key.hpp"

using testing::_;

class Leader : public TestFixture {};

TEST_F(Leader, does_not_timeout_until_numkeypress_keys_pressed) {
TestDriver driver;

auto key_leader = KeymapKey(0, 0, 0, QK_LEADER);
auto key_a = KeymapKey(0, 1, 0, KC_A);
auto key_b = KeymapKey(0, 2, 0, KC_B);

set_keymap({key_leader, key_a, key_b});

EXPECT_EQ(leader_sequence_active(), false);

EXPECT_NO_REPORT(driver);
tap_key(key_leader);

EXPECT_EQ(leader_sequence_active(), true);

idle_for(1000);

EXPECT_EQ(leader_sequence_active(), true);
EXPECT_EQ(leader_sequence_timed_out(), false);

EXPECT_REPORT(driver, (KC_2));
EXPECT_EMPTY_REPORT(driver);
tap_key(key_a);

idle_for(1000);

EXPECT_EQ(leader_sequence_active(), true);
EXPECT_EQ(leader_sequence_timed_out(), false);

tap_key(key_b);

idle_for(300);

EXPECT_EQ(leader_sequence_active(), false);
EXPECT_EQ(leader_sequence_timed_out(), true);

EXPECT_REPORT(driver, (KC_A));
EXPECT_EMPTY_REPORT(driver);
tap_key(key_a);
}