aboutsummaryrefslogtreecommitdiff
path: root/qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.c
diff options
context:
space:
mode:
Diffstat (limited to 'qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.c')
-rw-r--r--qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.c b/qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.c
new file mode 100644
index 0000000..d5e0838
--- /dev/null
+++ b/qmk/keyboards/sofle_choc/keymaps/custom/enter_dance.c
@@ -0,0 +1,60 @@
+#include QMK_KEYBOARD_H
+#include "quad_tapdance.h"
+#include "enter_dance.h"
+
+static td_tap_t enter_tap_state = {
+ .state = TD_NONE
+};
+
+static bool inhibit_mod = 0;
+
+void enter_dance_process_record(uint16_t keycode, keyrecord_t *record) {
+ if (enter_tap_state.state == TD_SINGLE_HOLD && record->event.pressed) {
+ inhibit_mod = 1;
+ }
+ return;
+}
+
+void enter_finished(tap_dance_state_t *state, void *user_data) {
+ enter_tap_state.state = cur_dance(state);
+ switch (enter_tap_state.state) {
+ case TD_SINGLE_HOLD:
+ if (get_oneshot_mods() & MOD_MASK_ALT) {
+ del_oneshot_mods(MOD_MASK_ALT);
+ //clear_oneshot_mods();
+ inhibit_mod = 1;
+ }
+ register_code(KC_RIGHT_ALT);
+ break;
+ default: break;
+ }
+}
+
+void enter_released(tap_dance_state_t *state, void *user_data) {
+ if (state->finished && state->count > 1)
+ // Exit prevently, we are sure in the next conditions we don’t fall in
+ // this case.
+ return;
+ else if (!state->finished) {
+ tap_code16(KC_ENTER);
+ reset_tap_dance(state);
+ } else if (!state->interrupted) {
+ // Final case, the key was keeped pressed without any other action
+ // in this case, active the one shot key for right alt
+ if (get_oneshot_mods() & MOD_MASK_ALT) {
+ del_oneshot_mods(MOD_MASK_ALT);
+ //clear_oneshot_mods();
+ } else if (!inhibit_mod) {
+ set_oneshot_mods(MOD_BIT(KC_RIGHT_ALT));
+ }
+ }
+ inhibit_mod = 0;
+}
+
+void enter_reset(tap_dance_state_t *state, void *user_data) {
+ switch (enter_tap_state.state) {
+ case TD_SINGLE_HOLD: unregister_code(KC_RIGHT_ALT); break;
+ default: break;
+ }
+ enter_tap_state.state = TD_NONE;
+}