aboutsummaryrefslogtreecommitdiff
path: root/common/action_tapping.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/action_tapping.c')
-rw-r--r--common/action_tapping.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/common/action_tapping.c b/common/action_tapping.c
index a6292535e..826c23309 100644
--- a/common/action_tapping.c
+++ b/common/action_tapping.c
@@ -1,7 +1,9 @@
1#include <stdint.h> 1#include <stdint.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#include "action.h" 3#include "action.h"
4#include "action_layer.h"
4#include "action_tapping.h" 5#include "action_tapping.h"
6#include "keycode.h"
5#include "timer.h" 7#include "timer.h"
6 8
7#ifdef DEBUG_ACTION 9#ifdef DEBUG_ACTION
@@ -27,9 +29,7 @@ static uint8_t waiting_buffer_tail = 0;
27static bool process_tapping(keyrecord_t *record); 29static bool process_tapping(keyrecord_t *record);
28static bool waiting_buffer_enq(keyrecord_t record); 30static bool waiting_buffer_enq(keyrecord_t record);
29static void waiting_buffer_clear(void); 31static void waiting_buffer_clear(void);
30#if TAPPING_TERM >= 500
31static bool waiting_buffer_typed(keyevent_t event); 32static bool waiting_buffer_typed(keyevent_t event);
32#endif
33static bool waiting_buffer_has_anykey_pressed(void); 33static bool waiting_buffer_has_anykey_pressed(void);
34static void waiting_buffer_scan_tap(void); 34static void waiting_buffer_scan_tap(void);
35static void debug_tapping_key(void); 35static void debug_tapping_key(void);
@@ -97,18 +97,43 @@ bool process_tapping(keyrecord_t *keyp)
97 return false; 97 return false;
98 } 98 }
99#if TAPPING_TERM >= 500 99#if TAPPING_TERM >= 500
100 /* This can settle mod/fn state fast but may prevent from typing fast. */ 100 /* Process a key typed within TAPPING_TERM
101 else if (!event.pressed && waiting_buffer_typed(event)) { 101 * This can register the key before settlement of tapping,
102 // other key typed. not tap. 102 * useful for long TAPPING_TERM but may prevent fast typing.
103 */
104 else if (IS_RELEASED(event) && waiting_buffer_typed(event)) {
103 debug("Tapping: End. No tap. Interfered by typing key\n"); 105 debug("Tapping: End. No tap. Interfered by typing key\n");
104 process_action(&tapping_key); 106 process_action(&tapping_key);
105 tapping_key = (keyrecord_t){}; 107 tapping_key = (keyrecord_t){};
106 debug_tapping_key(); 108 debug_tapping_key();
107
108 // enqueue 109 // enqueue
109 return false; 110 return false;
110 } 111 }
111#endif 112#endif
113 /* Process release event of a key pressed before tapping starts
114 * Without this unexpected repeating will occur with having fast repeating setting
115 * https://github.com/tmk/tmk_keyboard/issues/60
116 */
117 else if (IS_RELEASED(event) && !waiting_buffer_typed(event)) {
118 // Modifier should be retained till end of this tapping.
119 action_t action = layer_switch_get_action(event.key);
120 switch (action.kind.id) {
121 case ACT_LMODS:
122 case ACT_RMODS:
123 if (action.key.mods && !action.key.code) return false;
124 if (IS_MOD(action.key.code)) return false;
125 break;
126 case ACT_LMODS_TAP:
127 case ACT_RMODS_TAP:
128 if (action.key.mods && keyp->tap.count == 0) return false;
129 if (IS_MOD(action.key.code)) return false;
130 break;
131 }
132 // Release of key should be process immediately.
133 debug("Tapping: release event of a key pressed before tapping\n");
134 process_action(keyp);
135 return true;
136 }
112 else { 137 else {
113 // set interrupted flag when other key preesed during tapping 138 // set interrupted flag when other key preesed during tapping
114 if (event.pressed) { 139 if (event.pressed) {
@@ -289,7 +314,6 @@ void waiting_buffer_clear(void)
289 waiting_buffer_tail = 0; 314 waiting_buffer_tail = 0;
290} 315}
291 316
292#if TAPPING_TERM >= 500
293bool waiting_buffer_typed(keyevent_t event) 317bool waiting_buffer_typed(keyevent_t event)
294{ 318{
295 for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { 319 for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
@@ -299,7 +323,6 @@ bool waiting_buffer_typed(keyevent_t event)
299 } 323 }
300 return false; 324 return false;
301} 325}
302#endif
303 326
304bool waiting_buffer_has_anykey_pressed(void) 327bool waiting_buffer_has_anykey_pressed(void)
305{ 328{