summaryrefslogtreecommitdiffstats
path: root/tmk_core/common/action.c
diff options
context:
space:
mode:
authorJoe Wasson <jwasson+github@gmail.com>2018-03-12 18:22:49 +0100
committerJack Humbert <jack.humb@gmail.com>2018-03-16 21:33:43 +0100
commit5d771039adf23fe9cb8de5843a3d799dc73a2fc7 (patch)
tree043471b02358c3f7cbe848886fc5bcd850049fa7 /tmk_core/common/action.c
parent23ac2a02ef870dce91318a4d98e3c8ec5749bced (diff)
downloadqmk_firmware-5d771039adf23fe9cb8de5843a3d799dc73a2fc7.tar.gz
qmk_firmware-5d771039adf23fe9cb8de5843a3d799dc73a2fc7.tar.xz
Fix swap-hands tapping.
This is an inelegant hack for #2522 but makes things work. Basically we give `action.c` a chance to handle the hold event early so that we can swap the keyboard for later keys. Later, to allow the hold to happen again quickly we nuke the key record so that tapping is reset. I tried to find a cleaner way, honestly.
Diffstat (limited to 'tmk_core/common/action.c')
-rw-r--r--tmk_core/common/action.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 947e5118f..33d920554 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -93,6 +93,7 @@ void action_exec(keyevent_t event)
#ifdef SWAP_HANDS_ENABLE
bool swap_hands = false;
+bool swap_held = false;
void process_hand_swap(keyevent_t *event) {
static swap_state_row_t swap_state[MATRIX_ROWS];
@@ -132,6 +133,27 @@ bool process_record_quantum(keyrecord_t *record) {
return true;
}
+#ifndef NO_ACTION_TAPPING
+// Allows for handling tap-hold actions immediately instead of waiting for TAPPING_TERM or another keypress.
+void process_record_tap_hint(keyrecord_t *record)
+{
+ action_t action = layer_switch_get_action(record->event.key);
+
+ switch (action.kind.id) {
+#ifdef SWAP_HANDS_ENABLE
+ case ACT_SWAP_HANDS:
+ switch (action.swap.code) {
+ case OP_SH_TAP_TOGGLE:
+ default:
+ swap_hands = !swap_hands;
+ swap_held = true;
+ }
+ break;
+#endif
+ }
+}
+#endif
+
void process_record(keyrecord_t *record)
{
if (IS_NOEVENT(record->event)) { return; }
@@ -551,23 +573,37 @@ void process_action(keyrecord_t *record, action_t action)
#ifndef NO_ACTION_TAPPING
case OP_SH_TAP_TOGGLE:
/* tap toggle */
- if (tap_count > 0) {
- if (!event.pressed) {
+
+ if (event.pressed) {
+ if (swap_held) {
+ swap_held = false;
+ } else {
swap_hands = !swap_hands;
}
} else {
- swap_hands = event.pressed;
+ if (tap_count < TAPPING_TOGGLE) {
+ swap_hands = !swap_hands;
+ }
}
break;
default:
+ /* tap key */
if (tap_count > 0) {
+ if (swap_held) {
+ swap_hands = !swap_hands; // undo hold set up in _tap_hint
+ swap_held = false;
+ }
if (event.pressed) {
register_code(action.swap.code);
} else {
unregister_code(action.swap.code);
+ *record = (keyrecord_t){}; // hack: reset tap mode
}
} else {
- swap_hands = event.pressed;
+ if (swap_held && !event.pressed) {
+ swap_hands = !swap_hands; // undo hold set up in _tap_hint
+ swap_held = false;
+ }
}
#endif
}