-/* stores a key event of current tap. */
-static keyrecord_t tapping_key = {};
-
-#define IS_TAPPING() !IS_NOEVENT(tapping_key.event)
-#define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed)
-#define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed)
-#define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k)))
-#define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM)
-
-
-/*
- * Waiting buffer
- *
- * stores key events waiting for settling current tap.
- */
-#define WAITING_BUFFER_SIZE 8
-static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {};
-
-/* point to empty cell to enq */
-static uint8_t waiting_buffer_head = 0;
-
-/* point to the oldest data cell to deq */
-static uint8_t waiting_buffer_tail = 0;
-
-static void debug_waiting_buffer(void)
-{
- debug("{ ");
- for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
- debug("["); debug_dec(i); debug("]="); debug_record(waiting_buffer[i]); debug(" ");
- }
- debug("}\n");
-}
-static bool waiting_buffer_enq(keyrecord_t record)
-{
- if (IS_NOEVENT(record.event)) {
- return true;
- }
-
- if ((waiting_buffer_head + 1) % WAITING_BUFFER_SIZE == waiting_buffer_tail) {
- debug("waiting_buffer_enq: Over flow.\n");
- return false;
- }
-
- waiting_buffer[waiting_buffer_head] = record;
- waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE;
-
- debug("waiting_buffer_enq: "); debug_waiting_buffer();
- return true;
-}
-/*
-static keyrecord_t waiting_buffer_deq(void)
-{
- if (waiting_buffer_head == waiting_buffer_tail) {
- return (keyrecord_t){};
- }
- uint8_t last_tail = waiting_buffer_tail;
- waiting_buffer_tail = waiting_buffer_tail + 1 % WAITING_BUFFER_SIZE;
- return waiting_buffer[last_tail];
-}
-static bool waiting_buffer_is_empty(void)
-{
- return (waiting_buffer_head == waiting_buffer_tail);
-}
-*/
-static void waiting_buffer_clear(void)
-{
- waiting_buffer_head = 0;
- waiting_buffer_tail = 0;
-}
-static bool waiting_buffer_typed(keyevent_t event)
-{
- for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
- if (KEYEQ(event.key, waiting_buffer[i].event.key) && event.pressed != waiting_buffer[i].event.pressed) {
- return true;
- }
- }
- return false;
-}
-static bool waiting_buffer_has_anykey_pressed(void)
-{
- for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
- if (waiting_buffer[i].event.pressed) return true;
- }
- return false;
-}
-
-
-/* Oneshot modifier
- *
- * Problem: Want to capitalize like 'The' but the result tends to be 'THe'.
- * Solution: Oneshot modifier have its effect on only one key coming next.
- * Tap Shift, then type 't', 'h' and 'e'. Not need to hold Shift key.
- *
- * Hold: works as normal modifier.
- * Tap: one shot modifier.
- * 2 Tap: cancel one shot modifier.
- * 5-Tap: toggles enable/disable oneshot feature.
- */
-static struct {
- uint8_t mods;
- uint8_t time;
- bool ready;
- bool disabled;
-} oneshot_state;
-static void oneshot_start(uint8_t mods, uint16_t time)
-{
- oneshot_state.mods = mods;
- oneshot_state.time = time;
- oneshot_state.ready = true;
-}
-static void oneshot_cancel(void)
-{
- oneshot_state.mods = 0;
- oneshot_state.time = 0;
- oneshot_state.ready = false;
-}
-static void oneshot_toggle(void)
-{
- oneshot_state.disabled = !oneshot_state.disabled;
-}
-
-