Skip to content

Add Feature: Retro Tapping Timeout #25138

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

Open
wants to merge 2 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
2 changes: 2 additions & 0 deletions docs/config_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ If you define these options you will enable the associated feature, which may in
* See [Retro Tapping](tap_hold#retro-tapping) for details
* `#define RETRO_TAPPING_PER_KEY`
* enables handling for per key `RETRO_TAPPING` settings
* `#define RETRO_TAPPING_TIMEOUT 500`
* how long until `RETRO_TAPPING` times out
* `#define TAPPING_TOGGLE 2`
* how many taps before triggering the toggle
* `#define PERMISSIVE_HOLD`
Expand Down
8 changes: 8 additions & 0 deletions docs/tap_hold.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,14 @@ bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) {
}
```

With RETRO_TAPPING_TIMEOUT enabled, holding a dual function key for longer than the specified timeout duration will result in no keycode being sent when the key is released.

This setting can be enabled in your `config.h` and takes an integer that is the timeout duration in milliseconds.

```c
#define RETRO_TAPPING_TIMEOUT 500
```

If the programs you use bind an action to taps of modifier keys (e.g. tapping left GUI to bring up the applications menu or tapping left Alt to focus the menu bar), you may find that using retro-tapping falsely triggers those actions. To counteract this, you can define a `DUMMY_MOD_NEUTRALIZER_KEYCODE` in `config.h` that will get sent in between the register and unregister events of a held mod-tap key. That way, the programs on your computer will no longer interpret the mod suppression induced by retro-tapping as a lone tap of a modifier key and will thus not falsely trigger the undesired action.

Naturally, for this technique to be effective, you must choose a `DUMMY_MOD_NEUTRALIZER_KEYCODE` for which no keyboard shortcuts are bound to. Recommended values are: `KC_RIGHT_CTRL` or `KC_F18`.
Expand Down
13 changes: 13 additions & 0 deletions quantum/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ uint16_t retro_tap_curr_key = 0;
uint8_t retro_tap_curr_mods = 0;
uint8_t retro_tap_next_mods = 0;
# endif
# if defined(RETRO_TAPPING_TIMEOUT) && !(defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT))
uint16_t retro_last_press_time = 0;
uint16_t retro_last_release_time = 0;
# endif
#endif

#if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
Expand Down Expand Up @@ -86,8 +90,14 @@ void action_exec(keyevent_t event) {
if (event.pressed) {
retro_tap_primed = false;
retro_tap_curr_key = event_keycode;
# if defined(RETRO_TAPPING_TIMEOUT) && !(defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT))
retro_last_press_time = timer_read();
# endif
} else if (retro_tap_curr_key == event_keycode) {
retro_tap_primed = true;
# if defined(RETRO_TAPPING_TIMEOUT) && !(defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT))
retro_last_release_time = timer_read();
# endif
}
#endif
}
Expand Down Expand Up @@ -862,6 +872,9 @@ void process_action(keyrecord_t *record, action_t action) {
if (
# ifdef RETRO_TAPPING_PER_KEY
get_retro_tapping(event_keycode, record) &&
# endif
# if defined(RETRO_TAPPING_TIMEOUT) && !(defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT))
retro_last_release_time - retro_last_press_time < RETRO_TAPPING_TIMEOUT &&
# endif
retro_tap_primed) {
# if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
Expand Down
1 change: 1 addition & 0 deletions tests/tap_hold_configurations/retro_tapping/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
#define DUMMY_MOD_NEUTRALIZER_KEYCODE KC_RIGHT_CTRL
#define MODS_TO_NEUTRALIZE \
{ MOD_BIT(KC_LEFT_GUI) }
#define RETRO_TAPPING_TIMEOUT TAPPING_TERM * 2 + 1
61 changes: 61 additions & 0 deletions tests/tap_hold_configurations/retro_tapping/test_timeout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* Copyright 2024 John Rigoni
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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

using testing::_;
using testing::InSequence;

class RetroTapTimeout : public TestFixture {};

TEST_F(RetroTapTimeout, retro_tap_timeout_left_shift) {
TestDriver driver;
InSequence s;
auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P));

set_keymap({mod_tap_hold_key});

EXPECT_REPORT(driver, (KC_LEFT_SHIFT));
EXPECT_EMPTY_REPORT(driver);
mod_tap_hold_key.press();
idle_for(RETRO_TAPPING_TIMEOUT);
mod_tap_hold_key.release();
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}

TEST_F(RetroTapTimeout, retro_tap_timeout_left_mod) {
TestDriver driver;
InSequence s;
auto mod_tap_hold_key = KeymapKey(0, 1, 0, LGUI_T(KC_P));

set_keymap({mod_tap_hold_key});

EXPECT_REPORT(driver, (KC_LEFT_GUI));
EXPECT_REPORT(driver, (KC_LGUI, DUMMY_MOD_NEUTRALIZER_KEYCODE));
EXPECT_REPORT(driver, (KC_LEFT_GUI));
EXPECT_EMPTY_REPORT(driver);
mod_tap_hold_key.press();
idle_for(RETRO_TAPPING_TIMEOUT);
mod_tap_hold_key.release();
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}