-
-static void process(keyrecord_t *record);
-
-// TODO
-/* layer */
-uint8_t default_layer = 0;
-uint8_t current_layer = 0;
-
-/* tap term(ms) */
-#define TAP_TERM 200
-/* number of tap which fires toggle feature */
-#define TAP_TOGGLE 5
-
-/* This counts up when tap occurs */
-uint8_t tap_count = 0;
-keyevent_t tapping_event = {};
-keyrecord_t tapping_key = {};
-
-/* TAPPING: This indicates that whether tap or not is not decided yet. */
-// NOTE: keyevent_t.time 0 means no event.
-#define IS_TAPPING() (tapping_key.event.time != 0)
-#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_TAP_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAP_TERM)
-
-/* waiting keys buffer */
-#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 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;
- }
-
- debug("waiting_buffer_enq["); debug_dec(waiting_buffer_head); debug("] = ");
- debug_hex16(record.event.key.raw); debug("\n");
-
- waiting_buffer[waiting_buffer_head] = record;
- waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE;
- 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;
-}