summaryrefslogtreecommitdiff
path: root/aktersnurra/tap_dance.c
blob: 265ef0d4781ce7f89aa917b1c89ae3873f115124 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "tap_dance.h"

static td_state_t td_state;

int cur_dance(qk_tap_dance_state_t *state) {
  if (state->count == 1) {
    if (state->interrupted || !state->pressed) {
      return SINGLE_TAP;
    } else {
      return SINGLE_HOLD;
    }
  }
  if (state->count == 2) {
    return DOUBLE_SINGLE_TAP;
  } else {
    return 3;
  }
}

void raise_finished(qk_tap_dance_state_t *state, void *user_data) {
  td_state = cur_dance(state);
  switch (td_state) {
  case SINGLE_TAP:
    register_code16(KC_BSPC);
    break;
  case SINGLE_HOLD:
    layer_on(_RAISE);
    break;
  case DOUBLE_SINGLE_TAP:
    tap_code16(KC_BSPC);
    register_code16(KC_BSPC);
  }
}

void raise_reset(qk_tap_dance_state_t *state, void *user_data) {
  switch (td_state) {
  case SINGLE_TAP:
    unregister_code16(KC_BSPC);
    break;
  case SINGLE_HOLD:
    layer_off(_RAISE);
    break;
  case DOUBLE_SINGLE_TAP:
    unregister_code16(KC_BSPC);
  }
}

void lower_finished(qk_tap_dance_state_t *state, void *user_data) {
  td_state = cur_dance(state);
  switch (td_state) {
  case SINGLE_TAP:
    register_code16(KC_SPC);
    break;
  case SINGLE_HOLD:
    layer_on(_LOWER);
    break;
  case DOUBLE_SINGLE_TAP:
    tap_code16(KC_SPC);
    register_code16(KC_SPC);
  }
}

void lower_reset(qk_tap_dance_state_t *state, void *user_data) {
  switch (td_state) {
  case SINGLE_TAP:
    unregister_code16(KC_SPC);
    break;
  case SINGLE_HOLD:
    layer_off(_LOWER);
    break;
  case DOUBLE_SINGLE_TAP:
    unregister_code16(KC_SPC);
  }
}

qk_tap_dance_action_t tap_dance_actions[] = {
    [M_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_M, KC_ESC),
    [TD_RAISE] =
        ACTION_TAP_DANCE_FN_ADVANCED(NULL, raise_finished, raise_reset),
    [TD_LOWER] =
        ACTION_TAP_DANCE_FN_ADVANCED(NULL, lower_finished, lower_reset)};