summaryrefslogtreecommitdiffstats
path: root/users/xulkal/custom_tap_dance.c
blob: bcbfb577bb8d32ebe7adbfaf533e835403153bb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "custom_tap_dance.h"
#include "custom_keycodes.h"

#ifdef TAP_DANCE_ENABLE

//Tap Dance Definitions
qk_tap_dance_action_t tap_dance_actions[] = {
  [COMM_QUOT]  = ACTION_TAP_DANCE_DOUBLE(KC_COMM, KC_QUOT),
  [BACKSPACE] = ACTION_TAP_DANCE_DOUBLE (KC_BACKSPACE, LCTL(KC_BACKSPACE)),
  [DELETE] = ACTION_TAP_DANCE_DOUBLE (KC_DELETE, LCTL(KC_DELETE))
};

#else

static uint16_t td_keycode;
static uint16_t td_timer;

const uint16_t PROGMEM td_keymaps[TD_MAX - TD_MIN][2] = {
    [TD_COMM - TD_MIN]  = { KC_COMM, KC_QUOT },
    [TD_BSPC - TD_MIN]  = { KC_BACKSPACE, LCTL(KC_BACKSPACE) },
    [TD_DEL - TD_MIN]  = { KC_DELETE, LCTL(KC_DELETE) }
};

static void run_custom_tap_dance(uint8_t i)
{
    tap_code16(pgm_read_word(&td_keymaps[td_keycode - TD_MIN][i]));
    td_keycode = KC_TRANSPARENT;
    td_timer = timer_read() + TAPPING_TERM;
}

bool process_custom_tap_dance(uint16_t keycode, keyrecord_t *record)
{
    if (TD_MIN <= keycode && keycode < TD_MAX)
    {
        if (record->event.pressed)
        {
            if (td_keycode != keycode || timer_expired(td_timer))
            {
                td_keycode = keycode;
                td_timer = timer_read() + TAPPING_TERM;
            }
            else
                run_custom_tap_dance(1);
        }
        return false;
    }

    if (td_keycode != KC_TRANSPARENT)
        run_custom_tap_dance(0);
    return true;
}

void matrix_scan_user(void)
{
    if (td_keycode != KC_TRANSPARENT && timer_expired(td_timer))
        run_custom_tap_dance(0);
}

#endif