]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
add an `anyway` and a `reset` callback
authorPavlos Vinieratos <pvinis@gmail.com>
Wed, 13 Jul 2016 14:47:45 +0000 (16:47 +0200)
committerPavlos Vinieratos <pvinis@gmail.com>
Fri, 15 Jul 2016 22:04:12 +0000 (00:04 +0200)
when using tap dance, we have the `regular` callback that is called on
the last tap. this commit adds an `anyway` callback that is called on
every tap, and a `reset` callback that is called on reset of the tap
dance taps.

quantum/process_keycode/process_tap_dance.c
quantum/process_keycode/process_tap_dance.h

index 186889bc29a01d3f8f92865da573662475e69fe1..40fba2a6a6e313b4babcd5c127812ec00735245e 100644 (file)
@@ -40,7 +40,24 @@ void process_tap_dance_action (uint16_t keycode)
                                     action.pair.kc1, action.pair.kc2);
     break;
   case QK_TAP_DANCE_TYPE_FN:
-    _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn);
+    _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.regular);
+    break;
+
+  default:
+    break;
+  }
+}
+
+void process_tap_dance_action_anyway (uint16_t keycode)
+{
+  uint16_t idx = keycode - QK_TAP_DANCE;
+  qk_tap_dance_action_t action;
+
+  action = tap_dance_actions[idx];
+
+  switch (action.type) {
+  case QK_TAP_DANCE_TYPE_FN:
+    _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn.anyway);
     break;
 
   default:
@@ -53,6 +70,7 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
 
   switch(keycode) {
   case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
+    process_tap_dance_action_anyway (qk_tap_dance_state.keycode);
     if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) {
       process_tap_dance_action (qk_tap_dance_state.keycode);
     } else {
@@ -68,6 +86,7 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
 
   default:
     if (qk_tap_dance_state.keycode) {
+      //process_tap_dance_action_anyway (qk_tap_dance_state.keycode);
       process_tap_dance_action (qk_tap_dance_state.keycode);
 
       reset_tap_dance (&qk_tap_dance_state);
@@ -87,6 +106,21 @@ void matrix_scan_tap_dance () {
 }
 
 void reset_tap_dance (qk_tap_dance_state_t *state) {
+  uint16_t idx = state->keycode - QK_TAP_DANCE;
+  qk_tap_dance_action_t action;
+
+  action = tap_dance_actions[idx];
+  switch (action.type) {
+  case QK_TAP_DANCE_TYPE_FN:
+    if (action.fn.reset) {
+      action.fn.reset();
+    }
+    break;
+
+  default:
+    break;
+  }
+
   state->keycode = 0;
   state->count = 0;
 }
index b9d7c7fcf452c8134f43ca8db52d11c2dae8fc20..bf925df0f6d2f95204849e5f21a88a6abadef532 100644 (file)
@@ -22,6 +22,7 @@ typedef enum
 } qk_tap_dance_type_t;
 
 typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state);
+typedef void (*qk_tap_dance_user_fn_reset_t) (void);
 
 typedef struct
 {
@@ -31,18 +32,37 @@ typedef struct
       uint16_t kc1;
       uint16_t kc2;
     } pair;
-    qk_tap_dance_user_fn_t fn;
+    struct {
+      qk_tap_dance_user_fn_t regular;
+      qk_tap_dance_user_fn_t anyway;
+      qk_tap_dance_user_fn_reset_t reset;
+    } fn;
   };
 } qk_tap_dance_action_t;
 
 #define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
-    .type = QK_TAP_DANCE_TYPE_PAIR,         \
-    .pair = { kc1, kc2 }                    \
+    .type = QK_TAP_DANCE_TYPE_PAIR, \
+    .pair = { kc1, kc2 }            \
   }
 
 #define ACTION_TAP_DANCE_FN(user_fn) { \
     .type = QK_TAP_DANCE_TYPE_FN, \
-    .fn = user_fn                 \
+    .fn = { user_fn, NULL, NULL } \
+  }
+
+#define ACTION_TAP_DANCE_FN_ANYWAY(user_fn, user_fn_anyway) { \
+    .type = QK_TAP_DANCE_TYPE_FN,           \
+    .fn = { user_fn, user_fn_anyway, NULL } \
+  }
+
+#define ACTION_TAP_DANCE_FN_RESET(user_fn, user_fn_reset) { \
+    .type = QK_TAP_DANCE_TYPE_FN,          \
+    .fn = { user_fn, NULL, user_fn_reset } \
+  }
+
+#define ACTION_TAP_DANCE_FN_ANYWAY_RESET(user_fn, user_fn_anyway, user_fn_reset) { \
+    .type = QK_TAP_DANCE_TYPE_FN,                    \
+    .fn = { user_fn, user_fn_anyway, user_fn_reset } \
   }
 
 extern const qk_tap_dance_action_t tap_dance_actions[];