From 2545f15b304982ffd4dc5a7262fa8286ec9f1bb7 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 3 Aug 2022 07:41:21 -0700 Subject: [PATCH] Cleaned up tapdance code --- .../betalupi_ergodox/keymaps/default/rules.mk | 2 - .../keymaps/default/tapdance/screenshot.c | 65 ------------------- .../keymaps/default/tapdance/tapdance.c | 53 +++++++++------ .../keymaps/default/tapdance/tapdance.h | 31 +-------- .../keymaps/default/tapdance/wmlayout.c | 48 -------------- 5 files changed, 36 insertions(+), 163 deletions(-) delete mode 100644 keyboards/betalupi_ergodox/keymaps/default/tapdance/screenshot.c delete mode 100644 keyboards/betalupi_ergodox/keymaps/default/tapdance/wmlayout.c diff --git a/keyboards/betalupi_ergodox/keymaps/default/rules.mk b/keyboards/betalupi_ergodox/keymaps/default/rules.mk index a48b821..8af1119 100644 --- a/keyboards/betalupi_ergodox/keymaps/default/rules.mk +++ b/keyboards/betalupi_ergodox/keymaps/default/rules.mk @@ -4,7 +4,5 @@ LEADER_ENABLE = yes TAP_DANCE_ENABLE = yes SRC += \ - tapdance/wmlayout.c \ - tapdance/screenshot.c \ tapdance/tapdance.c \ layers/layers.c diff --git a/keyboards/betalupi_ergodox/keymaps/default/tapdance/screenshot.c b/keyboards/betalupi_ergodox/keymaps/default/tapdance/screenshot.c deleted file mode 100644 index 6cb057d..0000000 --- a/keyboards/betalupi_ergodox/keymaps/default/tapdance/screenshot.c +++ /dev/null @@ -1,65 +0,0 @@ -#include "keymap.h" -#include "tapdance.h" - -// Called on every tap -void td_screenshot_dance(qk_tap_dance_state_t *state, void *user_data) {} - -// Called when action finishes -void td_screenshot_finished(qk_tap_dance_state_t *state, void *user_data) { - dance_state[1].step = dance_step(state); - switch (dance_state[1].step) { - case SINGLE_TAP: - register_code16(KC_PRINT_SCREEN); - break; - case DOUBLE_TAP: - register_code16(LSFT(KC_PRINT_SCREEN)); - break; - } -} - -// Called when action resets -void td_screenshot_reset(qk_tap_dance_state_t *state, void *user_data) { - wait_ms(10); - switch (dance_state[1].step) { - case SINGLE_TAP: - unregister_code16(KC_PSCREEN); - break; - case DOUBLE_TAP: - unregister_code16(LSFT(KC_PSCREEN)); - break; - } - dance_state[1].step = 0; -} - - - -// Called on every tap -void td_ocr_dance(qk_tap_dance_state_t *state, void *user_data) {} - -// Called when action finishes -void td_ocr_finished(qk_tap_dance_state_t *state, void *user_data) { - dance_state[1].step = dance_step(state); - switch (dance_state[1].step) { - case SINGLE_TAP: - register_code16(LCTL(KC_PSCREEN)); - break; - case DOUBLE_TAP: - register_code16(LCTL(LSFT(KC_PSCREEN))); - break; - } -} - -// Called when action resets -void td_ocr_reset(qk_tap_dance_state_t *state, void *user_data) { - wait_ms(10); - switch (dance_state[1].step) { - case SINGLE_TAP: - unregister_code16(LCTL(KC_PRINT_SCREEN)); - break; - case DOUBLE_TAP: - unregister_code16(LCTL(LSFT(KC_PSCREEN))); - break; - } - dance_state[1].step = 0; -} - diff --git a/keyboards/betalupi_ergodox/keymaps/default/tapdance/tapdance.c b/keyboards/betalupi_ergodox/keymaps/default/tapdance/tapdance.c index 5662563..8b2b12c 100644 --- a/keyboards/betalupi_ergodox/keymaps/default/tapdance/tapdance.c +++ b/keyboards/betalupi_ergodox/keymaps/default/tapdance/tapdance.c @@ -1,29 +1,42 @@ #include "keymap.h" #include "tapdance.h" -tap dance_state[2]; - -uint8_t dance_step(qk_tap_dance_state_t *state) { +void td_screenshot(qk_tap_dance_state_t *state, void *user_data) { if (state->count == 1) { - if (state->interrupted || !state->pressed) { - return SINGLE_TAP; - } else { - return SINGLE_HOLD; - } + tap_code16(KC_PSCREEN); } else if (state->count == 2) { - if (state->interrupted) { - return DOUBLE_SINGLE_TAP; - } else if (state->pressed) { - return DOUBLE_HOLD; - } else { - return DOUBLE_TAP; - } + tap_code16(LSFT(KC_PSCREEN)); + } else if (state->count == 3) { + tap_code16(LALT(KC_PSCREEN)); + } else { + reset_tap_dance(state); } - return MORE_TAPS; } +void td_ocr(qk_tap_dance_state_t *state, void *user_data) { + if (state->count == 1) { + tap_code16(LCTL(KC_PSCREEN)); + } else if (state->count == 2) { + tap_code16(LCTL(LSFT(KC_PSCREEN))); + } else { + reset_tap_dance(state); + } +} + +void td_wmlayout(qk_tap_dance_state_t *state, void *user_data) { + if (state->count == 1) { + tap_code16(LGUI(KC_COMMA)); + } else if (state->count == 2) { + tap_code16(LGUI(KC_DOT)); + } else { + reset_tap_dance(state); + } +} + + + qk_tap_dance_action_t tap_dance_actions[] = { - [TD_WMLAYOUT] = ACTION_TAP_DANCE_FN_ADVANCED(td_wmlayout_dance, td_wmlayout_finished, td_wmlayout_reset), - [TD_SCREENSHOT] = ACTION_TAP_DANCE_FN_ADVANCED(td_screenshot_dance, td_screenshot_finished, td_screenshot_reset), - [TD_OCR] = ACTION_TAP_DANCE_FN_ADVANCED(td_ocr_dance, td_ocr_finished, td_ocr_reset), -}; \ No newline at end of file + [TD_WMLAYOUT] = ACTION_TAP_DANCE_FN(td_wmlayout), + [TD_SCREENSHOT] = ACTION_TAP_DANCE_FN(td_screenshot), + [TD_OCR] = ACTION_TAP_DANCE_FN(td_ocr), +}; diff --git a/keyboards/betalupi_ergodox/keymaps/default/tapdance/tapdance.h b/keyboards/betalupi_ergodox/keymaps/default/tapdance/tapdance.h index ae45cec..8922f76 100644 --- a/keyboards/betalupi_ergodox/keymaps/default/tapdance/tapdance.h +++ b/keyboards/betalupi_ergodox/keymaps/default/tapdance/tapdance.h @@ -7,31 +7,6 @@ enum tap_dance_codes { TD_OCR }; -enum { - SINGLE_TAP = 1, - SINGLE_HOLD, - DOUBLE_TAP, - DOUBLE_HOLD, - DOUBLE_SINGLE_TAP, - MORE_TAPS -}; - -typedef struct { - bool is_press_action; - uint8_t step; -} tap; - -extern tap dance_state[2]; - -uint8_t dance_step(qk_tap_dance_state_t *state); - -void td_wmlayout_dance(qk_tap_dance_state_t *state, void *user_data); -void td_wmlayout_finished(qk_tap_dance_state_t *state, void *user_data); -void td_wmlayout_reset(qk_tap_dance_state_t *state, void *user_data); - -void td_screenshot_dance(qk_tap_dance_state_t *state, void *user_data); -void td_screenshot_finished(qk_tap_dance_state_t *state, void *user_data); -void td_screenshot_reset(qk_tap_dance_state_t *state, void *user_data); -void td_ocr_dance(qk_tap_dance_state_t *state, void *user_data); -void td_ocr_finished(qk_tap_dance_state_t *state, void *user_data); -void td_ocr_reset(qk_tap_dance_state_t *state, void *user_data); +void td_screenshot(qk_tap_dance_state_t *state, void *user_data); +void td_ocr(qk_tap_dance_state_t *state, void *user_data); +void td_wmlayout(qk_tap_dance_state_t *state, void *user_data); \ No newline at end of file diff --git a/keyboards/betalupi_ergodox/keymaps/default/tapdance/wmlayout.c b/keyboards/betalupi_ergodox/keymaps/default/tapdance/wmlayout.c deleted file mode 100644 index 7e96e49..0000000 --- a/keyboards/betalupi_ergodox/keymaps/default/tapdance/wmlayout.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "keymap.h" -#include "tapdance.h" - -// Called on every tap -void td_wmlayout_dance(qk_tap_dance_state_t *state, void *user_data) { - if(state->count == 3) { - tap_code16(LGUI(KC_COMMA)); - tap_code16(LGUI(KC_COMMA)); - tap_code16(LGUI(KC_COMMA)); - } - if(state->count > 3) { - tap_code16(LGUI(KC_COMMA)); - } -} - -// Called when action finishes -void td_wmlayout_finished(qk_tap_dance_state_t *state, void *user_data) { - dance_state[0].step = dance_step(state); - switch (dance_state[0].step) { - case SINGLE_TAP: - register_code16(LGUI(KC_COMMA)); - break; - case DOUBLE_TAP: - register_code16(LGUI(KC_DOT)); - break; - case DOUBLE_SINGLE_TAP: - tap_code16(LGUI(KC_COMMA)); - register_code16(LGUI(KC_COMMA)); - break; - } -} - -// Called when action resets -void td_wmlayout_reset(qk_tap_dance_state_t *state, void *user_data) { - wait_ms(10); - switch (dance_state[0].step) { - case SINGLE_TAP: - unregister_code16(LGUI(KC_COMMA)); - break; - case DOUBLE_TAP: - unregister_code16(LGUI(KC_DOT)); - break; - case DOUBLE_SINGLE_TAP: - unregister_code16(LGUI(KC_COMMA)); - break; - } - dance_state[0].step = 0; -}