Cleaned up tapdance code
parent
7fe192e4b3
commit
2545f15b30
|
@ -4,7 +4,5 @@ LEADER_ENABLE = yes
|
||||||
TAP_DANCE_ENABLE = yes
|
TAP_DANCE_ENABLE = yes
|
||||||
|
|
||||||
SRC += \
|
SRC += \
|
||||||
tapdance/wmlayout.c \
|
|
||||||
tapdance/screenshot.c \
|
|
||||||
tapdance/tapdance.c \
|
tapdance/tapdance.c \
|
||||||
layers/layers.c
|
layers/layers.c
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,29 +1,42 @@
|
||||||
#include "keymap.h"
|
#include "keymap.h"
|
||||||
#include "tapdance.h"
|
#include "tapdance.h"
|
||||||
|
|
||||||
tap dance_state[2];
|
void td_screenshot(qk_tap_dance_state_t *state, void *user_data) {
|
||||||
|
|
||||||
uint8_t dance_step(qk_tap_dance_state_t *state) {
|
|
||||||
if (state->count == 1) {
|
if (state->count == 1) {
|
||||||
if (state->interrupted || !state->pressed) {
|
tap_code16(KC_PSCREEN);
|
||||||
return SINGLE_TAP;
|
|
||||||
} else {
|
|
||||||
return SINGLE_HOLD;
|
|
||||||
}
|
|
||||||
} else if (state->count == 2) {
|
} else if (state->count == 2) {
|
||||||
if (state->interrupted) {
|
tap_code16(LSFT(KC_PSCREEN));
|
||||||
return DOUBLE_SINGLE_TAP;
|
} else if (state->count == 3) {
|
||||||
} else if (state->pressed) {
|
tap_code16(LALT(KC_PSCREEN));
|
||||||
return DOUBLE_HOLD;
|
|
||||||
} else {
|
} else {
|
||||||
return DOUBLE_TAP;
|
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[] = {
|
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_WMLAYOUT] = ACTION_TAP_DANCE_FN(td_wmlayout),
|
||||||
[TD_SCREENSHOT] = ACTION_TAP_DANCE_FN_ADVANCED(td_screenshot_dance, td_screenshot_finished, td_screenshot_reset),
|
[TD_SCREENSHOT] = ACTION_TAP_DANCE_FN(td_screenshot),
|
||||||
[TD_OCR] = ACTION_TAP_DANCE_FN_ADVANCED(td_ocr_dance, td_ocr_finished, td_ocr_reset),
|
[TD_OCR] = ACTION_TAP_DANCE_FN(td_ocr),
|
||||||
};
|
};
|
|
@ -7,31 +7,6 @@ enum tap_dance_codes {
|
||||||
TD_OCR
|
TD_OCR
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
void td_screenshot(qk_tap_dance_state_t *state, void *user_data);
|
||||||
SINGLE_TAP = 1,
|
void td_ocr(qk_tap_dance_state_t *state, void *user_data);
|
||||||
SINGLE_HOLD,
|
void td_wmlayout(qk_tap_dance_state_t *state, void *user_data);
|
||||||
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);
|
|
|
@ -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;
|
|
||||||
}
|
|
Loading…
Reference in New Issue