]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - tmk_core/common/action.c
Document the issue of stuck modifiers
[qmk_firmware.git] / tmk_core / common / action.c
index 1f15bd091861735b1b621510edb1e161035896ea..26a5fad7ac676cbbe4517b85ce8b4ffcf74b3f27 100644 (file)
@@ -53,6 +53,26 @@ void action_exec(keyevent_t event)
 #endif
 }
 
+/*
+ * Make sure the action triggered when the key is released is the same
+ * one as the one triggered on press. It's important for the mod keys
+ * when the layer is switched after the down event but before the up
+ * event as they may get stuck otherwise.
+ */
+action_t store_or_get_action(bool pressed, keypos_t key)
+{
+#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
+    static action_t pressed_actions[MATRIX_ROWS][MATRIX_COLS];
+
+    if (pressed) {
+        pressed_actions[key.row][key.col] = layer_switch_get_action(key);
+    }
+    return pressed_actions[key.row][key.col];
+#else
+    return layer_switch_get_action(key);
+#endif
+}
+
 void process_action(keyrecord_t *record)
 {
     keyevent_t event = record->event;
@@ -62,7 +82,7 @@ void process_action(keyrecord_t *record)
 
     if (IS_NOEVENT(event)) { return; }
 
-    action_t action = layer_switch_get_action(event.key);
+    action_t action = store_or_get_action(event.pressed, event.key);
     dprint("ACTION: "); debug_action(action);
 #ifndef NO_ACTION_LAYER
     dprint(" layer_state: "); layer_debug();
@@ -142,12 +162,15 @@ void process_action(keyrecord_t *record)
                     default:
                         if (event.pressed) {
                             if (tap_count > 0) {
+#ifndef IGNORE_MOD_TAP_INTERRUPT
                                 if (record->tap.interrupted) {
-                                    dprint("MODS_TAP: Tap: Cancel: add_mods\n");
+                                    dprint("mods_tap: tap: cancel: add_mods\n");
                                     // ad hoc: set 0 to cancel tap
                                     record->tap.count = 0;
                                     register_mods(mods);
-                                } else {
+                                } else
+#endif
+                                {
                                     dprint("MODS_TAP: Tap: register_code\n");
                                     register_code(action.key.code);
                                 }
@@ -397,7 +420,7 @@ void register_code(uint8_t code)
             set_mods(tmp_mods);
             send_keyboard_report();
             oneshot_cancel();
-        } else 
+        } else
 */
 #endif
         {