From ba2883fd9ab040fc670ad729e6cddd4c67c8188c Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 26 May 2017 12:03:30 +0900 Subject: [PATCH] core: Fix for stuck key problem #441 - Idea form https://github.com/qmk/qmk_firmware/pull/182 - Define NO_TRACK_KEY_PRESS to get old behaviour - This should resolve #105, #248, #397, #441 and FAQ entry: https://github.com/tmk/tmk_keyboard/wiki/FAQ-Keymap#modifierlayer-stuck --- tmk_core/README.md | 8 +++++++ tmk_core/common/action.c | 6 +++--- tmk_core/common/action.h | 2 +- tmk_core/common/action_layer.c | 36 ++++++++++++++++++++++++++------ tmk_core/common/action_layer.h | 2 +- tmk_core/common/action_tapping.c | 10 ++++----- 6 files changed, 48 insertions(+), 16 deletions(-) diff --git a/tmk_core/README.md b/tmk_core/README.md index c9c2eda4..50456880 100644 --- a/tmk_core/README.md +++ b/tmk_core/README.md @@ -7,6 +7,14 @@ Source code is available here: Updates ------- +#### 2017/05/30 +Fixed **Modifier/Layer key stuck** problem. See this wiki entry. If you need old keymap behaviour for some reason define `NO_TRACK_KEY_PRESS` in your `config.h`. + +This is virtually equivalent to QMK `PREVENT_STUCK_MODIFIERS`. + +#### 2017/01/11 +Changed action code for `ACTION_LAYER_MODS` and this may cause incompatibility with existent shared URL and downloaded firmwware of keymap editor. If you are using the action you just have to redefine it on keymap editor. Existent keymap code should not suffer. + #### 2016/06/26 Keymap framework was updated. `fn_actions[]` should be defined as `action_t` instead of `uint16_t`. And default code for keymap handling is now included in core you just need define `uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]` and `action_t fn_actions[]`. diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index ab6e9d89..05aa12ee 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -65,7 +65,7 @@ void process_action(keyrecord_t *record) if (IS_NOEVENT(event)) { return; } - action_t action = layer_switch_get_action(event.key); + action_t action = layer_switch_get_action(event); dprint("ACTION: "); debug_action(action); #ifndef NO_ACTION_LAYER dprint(" layer_state: "); layer_debug(); @@ -529,9 +529,9 @@ void clear_keyboard_but_mods(void) #endif } -bool is_tap_key(keypos_t key) +bool is_tap_key(keyevent_t event) { - action_t action = layer_switch_get_action(key); + action_t action = layer_switch_get_action(event); switch (action.kind.id) { case ACT_LMODS_TAP: diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h index 8a4736d7..993fc463 100644 --- a/tmk_core/common/action.h +++ b/tmk_core/common/action.h @@ -68,7 +68,7 @@ void unregister_mods(uint8_t mods); void clear_keyboard(void); void clear_keyboard_but_mods(void); void layer_switch(uint8_t new_layer); -bool is_tap_key(keypos_t key); +bool is_tap_key(keyevent_t event); /* debug */ void debug_event(keyevent_t event); diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index 6b5a7fd2..46401eba 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -24,7 +24,9 @@ static void default_layer_state_set(uint32_t state) default_layer_state = state; hook_default_layer_change(default_layer_state); default_layer_debug(); debug("\n"); +#ifdef NO_TRACK_KEY_PRESS clear_keyboard_but_mods(); // To avoid stuck keys +#endif } void default_layer_debug(void) @@ -66,7 +68,9 @@ static void layer_state_set(uint32_t state) layer_state = state; hook_layer_change(layer_state); layer_debug(); dprintln(); +#ifdef NO_TRACK_KEY_PRESS clear_keyboard_but_mods(); // To avoid stuck keys +#endif } void layer_clear(void) @@ -115,7 +119,8 @@ void layer_debug(void) -action_t layer_switch_get_action(keypos_t key) +/* return layer effective for key at this time */ +static uint8_t current_layer_for_key(keypos_t key) { action_t action = ACTION_TRANSPARENT; @@ -126,15 +131,34 @@ action_t layer_switch_get_action(keypos_t key) if (layers & (1UL< 1) { debug("Tapping: Start new tap with releasing last tap(>1).\n"); // unregister key @@ -196,7 +196,7 @@ bool process_tapping(keyrecord_t *keyp) tapping_key = (keyrecord_t){}; return true; } - else if (is_tap_key(event.key) && event.pressed) { + else if (is_tap_key(event) && event.pressed) { if (tapping_key.tap.count > 1) { debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); // unregister key @@ -241,7 +241,7 @@ bool process_tapping(keyrecord_t *keyp) tapping_key = *keyp; return true; } - } else if (is_tap_key(event.key)) { + } else if (is_tap_key(event)) { // Sequential tap can be interfered with other tap key. debug("Tapping: Start with interfering other tap.\n"); tapping_key = *keyp; @@ -272,7 +272,7 @@ bool process_tapping(keyrecord_t *keyp) } // not tapping state else { - if (event.pressed && is_tap_key(event.key)) { + if (event.pressed && is_tap_key(event)) { debug("Tapping: Start(Press tap key).\n"); tapping_key = *keyp; waiting_buffer_scan_tap(); -- 2.39.3