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

New feature: Retro Tapping per key #10622

Merged
merged 1 commit into from
Oct 23, 2020
Merged
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 @@ -135,6 +135,8 @@ If you define these options you will enable the associated feature, which may in
* `#define RETRO_TAPPING`
* tap anyway, even after TAPPING_TERM, if there was no other key interruption between press and release
* See [Retro Tapping](tap_hold.md#retro-tapping) for details
* `#define RETRO_TAPPING_PER_KEY`
* enables handling for per key `RETRO_TAPPING` settings
* `#define TAPPING_TOGGLE 2`
* how many taps before triggering the toggle
* `#define PERMISSIVE_HOLD`
Expand Down
19 changes: 19 additions & 0 deletions docs/tap_hold.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ Holding and releasing a dual function key without pressing another key will resu

For instance, holding and releasing `LT(2, KC_SPACE)` without hitting another key will result in nothing happening. With this enabled, it will send `KC_SPACE` instead.

For more granular control of this feature, you can add the following to your `config.h`:

```c
#define RETRO_TAPPING_PER_KEY
```

You can then add the following function to your keymap:

```c
bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case LT(2, KC_SPACE):
return true;
default:
return false;
}
}
```

## Why do we include the key record for the per key functions?

One thing that you may notice is that we include the key record for all of the "per key" functions, and may be wondering why we do that.
Expand Down
17 changes: 12 additions & 5 deletions tmk_core/common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

int tp_buttons;

#ifdef RETRO_TAPPING
#if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY)
int retro_tapping_counter = 0;
#endif

Expand All @@ -51,6 +51,10 @@ int retro_tapping_counter = 0;
__attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record) { return false; }
#endif

#ifdef RETRO_TAPPING_PER_KEY
__attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) { return false; }
#endif

#ifndef TAP_CODE_DELAY
# define TAP_CODE_DELAY 0
#endif
Expand All @@ -67,7 +71,7 @@ void action_exec(keyevent_t event) {
dprint("EVENT: ");
debug_event(event);
dprintln();
#ifdef RETRO_TAPPING
#if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY)
retro_tapping_counter++;
#endif
}
Expand Down Expand Up @@ -692,20 +696,23 @@ void process_action(keyrecord_t *record, action_t action) {
#endif

#ifndef NO_ACTION_TAPPING
# ifdef RETRO_TAPPING
# if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY)
if (!is_tap_action(action)) {
retro_tapping_counter = 0;
} else {
if (event.pressed) {
if (tap_count > 0) {
retro_tapping_counter = 0;
} else {
}
} else {
if (tap_count > 0) {
retro_tapping_counter = 0;
} else {
if (retro_tapping_counter == 2) {
if (
# ifdef RETRO_TAPPING_PER_KEY
get_retro_tapping(get_event_keycode(record->event, false), record) &&
# endif
retro_tapping_counter == 2) {
tap_code(action.layer_tap.code);
}
retro_tapping_counter = 0;
Expand Down