Split tapdance code
parent
5a545a83e6
commit
43103a889a
|
@ -1,5 +1,6 @@
|
|||
#include "keymap.h"
|
||||
#include "layers.h"
|
||||
#include "tapdance.h"
|
||||
|
||||
|
||||
// Define custom keys
|
||||
|
@ -17,7 +18,7 @@ enum custom_keycodes {
|
|||
};
|
||||
|
||||
enum tap_dance_codes {
|
||||
DANCE_0,
|
||||
TD_WMLAYOUT,
|
||||
};
|
||||
|
||||
|
||||
|
@ -257,91 +258,7 @@ uint32_t layer_state_set_user(uint32_t state) {
|
|||
return state;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
bool is_press_action;
|
||||
uint8_t step;
|
||||
} tap;
|
||||
|
||||
enum {
|
||||
SINGLE_TAP = 1,
|
||||
SINGLE_HOLD,
|
||||
DOUBLE_TAP,
|
||||
DOUBLE_HOLD,
|
||||
DOUBLE_SINGLE_TAP,
|
||||
MORE_TAPS
|
||||
};
|
||||
|
||||
static tap dance_state[1];
|
||||
|
||||
uint8_t dance_step(qk_tap_dance_state_t *state);
|
||||
|
||||
uint8_t dance_step(qk_tap_dance_state_t *state) {
|
||||
if (state->count == 1) {
|
||||
if (state->interrupted || !state->pressed) {
|
||||
return SINGLE_TAP;
|
||||
} else {
|
||||
return SINGLE_HOLD;
|
||||
}
|
||||
} else if (state->count == 2) {
|
||||
if (state->interrupted) {
|
||||
return DOUBLE_SINGLE_TAP;
|
||||
} else if (state->pressed) {
|
||||
return DOUBLE_HOLD;
|
||||
} else {
|
||||
return DOUBLE_TAP;
|
||||
}
|
||||
}
|
||||
return MORE_TAPS;
|
||||
}
|
||||
|
||||
|
||||
void on_dance_0(qk_tap_dance_state_t *state, void *user_data);
|
||||
void dance_0_finished(qk_tap_dance_state_t *state, void *user_data);
|
||||
void dance_0_reset(qk_tap_dance_state_t *state, void *user_data);
|
||||
|
||||
void on_dance_0(qk_tap_dance_state_t *state, void *user_data) {
|
||||
if(state->count == 3) {
|
||||
tap_code16(LGUI(KC_L));
|
||||
tap_code16(LGUI(KC_L));
|
||||
tap_code16(LGUI(KC_L));
|
||||
}
|
||||
if(state->count > 3) {
|
||||
tap_code16(LGUI(KC_L));
|
||||
}
|
||||
}
|
||||
|
||||
void dance_0_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_L));
|
||||
break;
|
||||
case DOUBLE_TAP:
|
||||
register_code16(LGUI(KC_K));
|
||||
break;
|
||||
case DOUBLE_SINGLE_TAP:
|
||||
tap_code16(LGUI(KC_L));
|
||||
register_code16(LGUI(KC_L));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dance_0_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_L));
|
||||
break;
|
||||
case DOUBLE_TAP:
|
||||
unregister_code16(LGUI(KC_K));
|
||||
break;
|
||||
case DOUBLE_SINGLE_TAP:
|
||||
unregister_code16(LGUI(KC_L));
|
||||
break;
|
||||
}
|
||||
dance_state[0].step = 0;
|
||||
}
|
||||
|
||||
qk_tap_dance_action_t tap_dance_actions[] = {
|
||||
[DANCE_0] = ACTION_TAP_DANCE_FN_ADVANCED(on_dance_0, dance_0_finished, dance_0_reset),
|
||||
[TD_WMLAYOUT] = ACTION_TAP_DANCE_FN_ADVANCED(td_wmlayout_dance, td_wmlayout_finished, td_wmlayout_reset),
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
OSL(LAYER_DESKTOP_IDX), OSL(LAYER_FKEYS_IDX), KC_LALT, KC_LSHIFT, MO(LAYER_ARROWS_IDX),\
|
||||
\
|
||||
KC_PSCREEN, LT(LAYER_KEYBOARD_IDX,KC_NO),\
|
||||
TD(DANCE_0),\
|
||||
TD(TD_WMLAYOUT),\
|
||||
KC_SPACE, KC_BSPACE, LCTL(KC_BSPACE),\
|
||||
\
|
||||
\
|
||||
|
|
|
@ -4,4 +4,7 @@ LTO_ENABLE = yes
|
|||
CONSOLE_ENABLE = no
|
||||
COMMAND_ENABLE = no
|
||||
TAP_DANCE_ENABLE = yes
|
||||
SRC = matrix.c
|
||||
SRC = \
|
||||
matrix.c \
|
||||
tapdance/wmlayout.c \
|
||||
tapdance/tapdance.c
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
#include "keymap.h"
|
||||
|
||||
|
||||
enum {
|
||||
SINGLE_TAP = 1,
|
||||
SINGLE_HOLD,
|
||||
DOUBLE_TAP,
|
||||
DOUBLE_HOLD,
|
||||
DOUBLE_SINGLE_TAP,
|
||||
MORE_TAPS
|
||||
};
|
||||
|
||||
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);
|
|
@ -0,0 +1,21 @@
|
|||
#include "keymap.h"
|
||||
#include "tapdance.h"
|
||||
|
||||
uint8_t dance_step(qk_tap_dance_state_t *state) {
|
||||
if (state->count == 1) {
|
||||
if (state->interrupted || !state->pressed) {
|
||||
return SINGLE_TAP;
|
||||
} else {
|
||||
return SINGLE_HOLD;
|
||||
}
|
||||
} else if (state->count == 2) {
|
||||
if (state->interrupted) {
|
||||
return DOUBLE_SINGLE_TAP;
|
||||
} else if (state->pressed) {
|
||||
return DOUBLE_HOLD;
|
||||
} else {
|
||||
return DOUBLE_TAP;
|
||||
}
|
||||
}
|
||||
return MORE_TAPS;
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#include "keymap.h"
|
||||
#include "tapdance.h"
|
||||
|
||||
typedef struct {
|
||||
bool is_press_action;
|
||||
uint8_t step;
|
||||
} tap;
|
||||
|
||||
static tap dance_state[1];
|
||||
|
||||
void td_wmlayout_dance(qk_tap_dance_state_t *state, void *user_data) {
|
||||
if(state->count == 3) {
|
||||
tap_code16(LGUI(KC_L));
|
||||
tap_code16(LGUI(KC_L));
|
||||
tap_code16(LGUI(KC_L));
|
||||
}
|
||||
if(state->count > 3) {
|
||||
tap_code16(LGUI(KC_L));
|
||||
}
|
||||
}
|
||||
|
||||
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_L));
|
||||
break;
|
||||
case DOUBLE_TAP:
|
||||
register_code16(LGUI(KC_K));
|
||||
break;
|
||||
case DOUBLE_SINGLE_TAP:
|
||||
tap_code16(LGUI(KC_L));
|
||||
register_code16(LGUI(KC_L));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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_L));
|
||||
break;
|
||||
case DOUBLE_TAP:
|
||||
unregister_code16(LGUI(KC_K));
|
||||
break;
|
||||
case DOUBLE_SINGLE_TAP:
|
||||
unregister_code16(LGUI(KC_L));
|
||||
break;
|
||||
}
|
||||
dance_state[0].step = 0;
|
||||
}
|
Loading…
Reference in New Issue