aboutsummaryrefslogtreecommitdiff
path: root/waffle/tapping.c
blob: c0538ae4e7b816b9f32bebbee76122418bf3bf9a (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2022 jack (@waffle87)
// SPDX-License-Identifier: GPL-2.0-or-later
#include "waffle.h"
#include "secrets.h"
#ifdef RANDWORD
#include "users/ridingqwerty/dict.h"
uint16_t word;
#endif

#define INTERCEPT_MOD_TAP(mod, keycode)             \
case mod(keycode):                                  \
  if (record->tap.count && record->event.pressed) { \
    tap_code16(keycode);                            \
    return false;                                   \
  }                                                 \
  break;                                            \

uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) {
  switch (keycode) {
    case LWRSPC:
    case ESCLWR:
      return TAPPING_TERM - 20;
    case LINKS:
    case PNP:
    case TD(QUOT_DQUO):
    case TD(EM_DASH):
    case TD(CBRKT):
    case TD(BRKT):
    case TD(BSLS_PIPE):
      return TAPPING_TERM + 60;
    default:
      return TAPPING_TERM;
  }
}

void td_reset(tap_dance_state_t *state, void *user_data) {
  clear_keyboard();
  layer_clear();
}

void qmk_dance(tap_dance_state_t *state, void *user_data) {
  if (state->count == 1) {
    tap_code16(C(KC_T));
    send_string(qmkstr);
    tap_code(KC_ENT);
  } else {
    tap_code16(C(KC_T));
    send_string(confstr);
    tap_code(KC_ENT);
  }
}

void dash_dance(tap_dance_state_t *state, void *user_data) {
  if (state->count == 1)
    tap_code(KC_MINS);
#ifdef UNICODE_COMMON_ENABLE
  else
    register_unicode(0x2014); //—
#endif
}

void curly_bracket_dance(tap_dance_state_t *state, void *user_data) {
  if (state->count == 1)
    tap_code16(KC_LCBR);
  else
    tap_code16(KC_RCBR);
}

void bracket_dance(tap_dance_state_t *state, void *user_data) {
  if (state->count == 1)
    tap_code(KC_LBRC);
  else
    tap_code(KC_RBRC);
}

void bsls_pipe_dance(tap_dance_state_t *state, void *user_data) {
  if (state->count == 1)
    tap_code(KC_BSLS);
  else
    tap_code16(KC_PIPE);
}

void quot_dquo_dance(tap_dance_state_t *state, void *user_data) {
   if (state->count == 1)
      tap_code(KC_QUOT);
   else
      tap_code16(KC_DQUO);
}

void zero_dance(tap_dance_state_t *state, void *user_data) {
  if (state->count == 1)
    tap_code(KC_0);
#ifdef UNICODE_COMMON_ENABLE
  else
    register_unicode(0x00B0); //°
#endif
}

void media_dance(tap_dance_state_t *state, void *user_data) {
  switch (state->count) {
    case 1:
      tap_code(KC_MPLY);
      break;
    case 2:
      tap_code(KC_MNXT);
      break;
    case 3:
      tap_code(KC_MPRV);
      break;
  }
}

void clipst_search_dance(tap_dance_state_t *state, void *user_data) {
  if (state->pressed && !state->interrupted)
    layer_on(_RAISE);
  else if (state->count == 1)
    tap_code16(C(S(KC_V)));
  else if (state->count == 2)
    tap_code16(C(S(KC_F)));
}

tap_dance_action_t tap_dance_actions[] = {
  [QMK_LINKS] = ACTION_TAP_DANCE_FN(qmk_dance),
  [EM_DASH] = ACTION_TAP_DANCE_FN(dash_dance),
  [CBRKT] = ACTION_TAP_DANCE_FN(curly_bracket_dance),
  [BRKT] = ACTION_TAP_DANCE_FN(bracket_dance),
  [BSLS_PIPE] = ACTION_TAP_DANCE_FN(bsls_pipe_dance),
  [QUOT_DQUO] = ACTION_TAP_DANCE_FN(quot_dquo_dance),
  [DEG_0] = ACTION_TAP_DANCE_FN(zero_dance),
  [PLY_NXT_PRV] = ACTION_TAP_DANCE_FN(media_dance),
  [CLIPST_RAISE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, clipst_search_dance, td_reset)
};


bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  if (!(process_record_keymap(keycode, record)
#ifdef UNICODE_COMMON_ENABLE
  && process_record_unicode(keycode, record)
#endif
  && true))
    return false;
#ifdef OLED_ENABLE
  if (record->event.pressed) {
    oled_timer_reset();
    add_keylog(keycode);
  }
#endif
  switch (keycode) {
    case UPDIR:
      if (record->event.pressed)
        SEND_STRING("../");
      break;
    INTERCEPT_MOD_TAP(LALT_T, KC_EXLM)
    INTERCEPT_MOD_TAP(LGUI_T, KC_AT)
    INTERCEPT_MOD_TAP(LCTL_T, KC_HASH)
    INTERCEPT_MOD_TAP(LSFT_T, KC_DLR)
    INTERCEPT_MOD_TAP(RSFT_T, KC_AMPR)
    INTERCEPT_MOD_TAP(RCTL_T, KC_ASTR)
    INTERCEPT_MOD_TAP(RGUI_T, KC_LPRN)
    INTERCEPT_MOD_TAP(RALT_T, KC_RPRN)
    case RWORD:
#ifdef RANDWORD
      word = rand() % NUMBER_OF_WORDS;
      if (record->event.pressed) {
        send_string(dict[word]);
        tap_code(KC_SPC);
      }
#endif
      break;
  }
  return process_record_keymap(keycode, record);
}