From 091d716a24e853cecc7452c3a4b7c0e408cdd8d3 Mon Sep 17 00:00:00 2001 From: Bastian Winkler Date: Tue, 22 Sep 2020 23:34:07 +0200 Subject: [PATCH] action: Add IGNORE_LAYER_TAP_INTERRUPT --- docs/config_options.md | 3 +++ docs/tap_hold.md | 26 ++++++++++++++++++++++++++ tmk_core/common/action.c | 18 ++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/docs/config_options.md b/docs/config_options.md index f9b1cc657870..0a0f4393e31d 100644 --- a/docs/config_options.md +++ b/docs/config_options.md @@ -147,6 +147,9 @@ If you define these options you will enable the associated feature, which may in * See [Ignore Mod Tap Interrupt](tap_hold.md#ignore-mod-tap-interrupt) for details * `#define IGNORE_MOD_TAP_INTERRUPT_PER_KEY` * enables handling for per key `IGNORE_MOD_TAP_INTERRUPT` settings +* `#define IGNORE_LAYER_TAP_INTERRUPT` + * Like `IGNORE_MOD_TAP_INTERRUPT`, but for layer tapping. + * See [Ignore Layer Tap Interrupt](tap_hold.md#ignore-mod-tap-interrupt) for details * `#define TAPPING_FORCE_HOLD` * makes it possible to use a dual role key as modifier shortly after having been tapped * See [Tapping Force Hold](tap_hold.md#tapping-force-hold) diff --git a/docs/tap_hold.md b/docs/tap_hold.md index 589ec3181609..b9e43f7cdd69 100644 --- a/docs/tap_hold.md +++ b/docs/tap_hold.md @@ -124,6 +124,32 @@ bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record) { } ``` +The described functionality only works for mod taps. To get the same results for layer taps, add this to your `config.h`: + +```c +#define IGNORE_LAYER_TAP_INTERRUPT +``` + +In case you also enabled `IGNORE_MOD_TAP_INTERRUPT_PER_KEY`, you can reuse this function to control layer taps: + +```c +bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case SFT_T(KC_SPC): + return true; + case LT(_FN, KC_F): + // interrupt causes 'f' + return true; + case LT(_RAISE, KC_BSPC): + // interrupt causes layer switch + return false; + default: + return false; + } +} +``` + + ## Tapping Force Hold To enable `tapping force hold`, add the following to your `config.h`: diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index ee9aa0df77db..a20e2cb5ce99 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -562,8 +562,22 @@ void process_action(keyrecord_t *record, action_t action) { /* tap key */ if (event.pressed) { if (tap_count > 0) { - dprint("KEYMAP_TAP_KEY: Tap: register_code\n"); - register_code(action.layer_tap.code); +# ifdef IGNORE_LAYER_TAP_INTERRUPT + if ( +# ifdef IGNORE_MOD_TAP_INTERRUPT_PER_KEY + !get_ignore_mod_tap_interrupt(get_event_keycode(record->event, false), record) && +# endif + record->tap.interrupted) { + dprint("layer_tap: tap: cancel: layer_on\n"); + // ad hoc: set 0 to cancel tap + record->tap.count = 0; + layer_on(action.layer_tap.val); + } else +# endif + { + dprint("KEYMAP_TAP_KEY: Tap: register_code\n"); + register_code(action.layer_tap.code); + } } else { dprint("KEYMAP_TAP_KEY: No tap: On on press\n"); layer_on(action.layer_tap.val);