summaryrefslogtreecommitdiffstats
path: root/tmk_core/common/action.c
diff options
context:
space:
mode:
authorJoe Wasson <jwasson+github@gmail.com>2016-07-27 08:43:02 -0700
committerJoe Wasson <jwasson+github@gmail.com>2016-08-20 17:46:53 -0700
commitdd378601608849679ead6e2cccb74f7f29c131dc (patch)
treeb8142400df6c9611a9b3e50aba2c78be1fb7db4e /tmk_core/common/action.c
parenta3f726174c0f8f358f7970767a1bf743fd9ad761 (diff)
Add one-hand support.
This adds an action, `ACTION_SWAP_HANDS`, that swaps the the keys on the keyboard across a keymap-defined hemisphere in order to support one-hand typing without requiring a separate one-handed layer. See updated `doc/keymap.md` for more information.
Diffstat (limited to 'tmk_core/common/action.c')
-rw-r--r--tmk_core/common/action.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index be6dea2b79..0413b1a997 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -41,6 +41,12 @@ void action_exec(keyevent_t event)
dprint("EVENT: "); debug_event(event); dprintln();
}
+#ifdef ONEHAND_ENABLE
+ if (!IS_NOEVENT(event)) {
+ process_hand_swap(&event);
+ }
+#endif
+
keyrecord_t record = { .event = event };
#ifndef NO_ACTION_TAPPING
@@ -53,6 +59,26 @@ void action_exec(keyevent_t event)
#endif
}
+#ifdef ONEHAND_ENABLE
+bool swap_hands = false;
+
+void process_hand_swap(keyevent_t *event) {
+ static swap_state_row_t swap_state[MATRIX_ROWS];
+
+ keypos_t pos = event->key;
+ swap_state_row_t col_bit = (swap_state_row_t)1<<pos.col;
+ bool do_swap = event->pressed ? swap_hands :
+ swap_state[pos.row] & (col_bit);
+
+ if (do_swap) {
+ event->key = hand_swap_config[pos.row][pos.col];
+ swap_state[pos.row] |= col_bit;
+ } else {
+ swap_state[pos.row] &= ~(col_bit);
+ }
+}
+#endif
+
#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
bool disable_action_cache = false;
@@ -439,6 +465,13 @@ void process_action(keyrecord_t *record, action_t action)
break;
#endif
case ACT_COMMAND:
+ switch (action.command.id) {
+#ifdef ONEHAND_ENABLE
+ case CMD_SWAP_HANDS:
+ swap_hands = event.pressed;
+ break;
+#endif
+ }
break;
#ifndef NO_ACTION_FUNCTION
case ACT_FUNCTION: