aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/common/action.c
diff options
context:
space:
mode:
authorGravatar Zsolt Parragi <zsolt.parragi@cancellar.hu>2020-05-13 23:36:55 +0200
committerGravatar GitHub <noreply@github.com>2020-05-14 07:36:55 +1000
commit805f5cb72bb04c10327b40ed0c41e3848ad9ca75 (patch)
tree249680bec133e18dd2399b80cbeb14e980f1095c /tmk_core/common/action.c
parenta8a8bf0ff3d6e1c9637079b925b30cf7eb8913fd (diff)
downloadqmk_firmware-805f5cb72bb04c10327b40ed0c41e3848ad9ca75.tar.gz
One shot support for swap hands (#8590)
This commits add the SH_OS keycode, which works similarly to one shot layers: * while pressed, the keyboard is swapped * if no keys were pressed while it was pressed, the next key press is swapped SH_OS also supports chaining with one shot layers: OSL(x) + SH_OS + key interprets the key press on the oneshot layer. The ONESHOT_TIMEOUT setting used by one shot keys and layers is also used by oneshot swap hands. In the above chaining scenario the timeout of the oneshot layer is reset when swap hands is activated. Resolves #2682
Diffstat (limited to 'tmk_core/common/action.c')
-rw-r--r--tmk_core/common/action.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index e5e9e2705..3b1268dc9 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -98,6 +98,11 @@ void action_exec(keyevent_t event) {
if (has_oneshot_mods_timed_out()) {
clear_oneshot_mods();
}
+# ifdef SWAP_HANDS_ENABLE
+ if (has_oneshot_swaphands_timed_out()) {
+ clear_oneshot_swaphands();
+ }
+# endif
# endif
#endif
@@ -165,6 +170,8 @@ void process_record_tap_hint(keyrecord_t *record) {
# ifdef SWAP_HANDS_ENABLE
case ACT_SWAP_HANDS:
switch (action.swap.code) {
+ case OP_SH_ONESHOT:
+ break;
case OP_SH_TAP_TOGGLE:
default:
swap_hands = !swap_hands;
@@ -224,7 +231,11 @@ void process_action(keyrecord_t *record, action_t action) {
#ifndef NO_ACTION_ONESHOT
bool do_release_oneshot = false;
// notice we only clear the one shot layer if the pressed key is not a modifier.
- if (is_oneshot_layer_active() && event.pressed && !IS_MOD(action.key.code)) {
+ if (is_oneshot_layer_active() && event.pressed && !IS_MOD(action.key.code)
+# ifdef SWAP_HANDS_ENABLE
+ && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT)
+# endif
+ ) {
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
do_release_oneshot = !is_oneshot_layer_active();
}
@@ -593,6 +604,14 @@ void process_action(keyrecord_t *record, action_t action) {
swap_hands = false;
}
break;
+ case OP_SH_ONESHOT:
+ if (event.pressed) {
+ set_oneshot_swaphands();
+ } else {
+ release_oneshot_swaphands();
+ }
+ break;
+
# ifndef NO_ACTION_TAPPING
case OP_SH_TAP_TOGGLE:
/* tap toggle */
@@ -681,6 +700,12 @@ void process_action(keyrecord_t *record, action_t action) {
# endif
#endif
+#ifdef SWAP_HANDS_ENABLE
+ if (event.pressed && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT)) {
+ use_oneshot_swaphands();
+ }
+#endif
+
#ifndef NO_ACTION_ONESHOT
/* Because we switch layers after a oneshot event, we need to release the
* key before we leave the layer or no key up event will be generated.