From bb80f9c174954b478b8ea0abacbb86ed6dbec15f Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Sat, 23 Oct 2021 22:49:12 -0700 Subject: [PATCH 1/3] Fix issues with Oneshot disabling --- quantum/action.c | 148 ++++++++++++------- quantum/action_util.c | 3 +- quantum/process_keycode/process_auto_shift.c | 3 - 3 files changed, 96 insertions(+), 58 deletions(-) diff --git a/quantum/action.c b/quantum/action.c index 95f39d23d450..92ca28c0cef8 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -28,6 +28,8 @@ along with this program. If not, see . #include "action.h" #include "wait.h" +#include "keycode_config.h" + #ifdef BACKLIGHT_ENABLE # include "backlight.h" #endif @@ -87,6 +89,7 @@ void action_exec(keyevent_t event) { keyrecord_t record = {.event = event}; #ifndef NO_ACTION_ONESHOT + if (!keymap_config.oneshot_disable) { # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) if (has_oneshot_layer_timed_out()) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); @@ -100,6 +103,7 @@ void action_exec(keyevent_t event) { } # endif # endif + } #endif #ifndef NO_ACTION_TAPPING @@ -195,7 +199,7 @@ void process_record(keyrecord_t *record) { if (!process_record_quantum(record)) { #ifndef NO_ACTION_ONESHOT - if (is_oneshot_layer_active() && record->event.pressed) { + if (is_oneshot_layer_active() && record->event.pressed && !keymap_config.oneshot_disable) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); } #endif @@ -260,6 +264,7 @@ void process_action(keyrecord_t *record, action_t action) { # ifdef SWAP_HANDS_ENABLE && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT) # endif + && !keymap_config.oneshot_disable ) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); do_release_oneshot = !is_oneshot_layer_active(); @@ -304,41 +309,68 @@ void process_action(keyrecord_t *record, action_t action) { # ifndef NO_ACTION_ONESHOT case MODS_ONESHOT: // Oneshot modifier - if (event.pressed) { - if (tap_count == 0) { - dprint("MODS_TAP: Oneshot: 0\n"); - register_mods(mods | get_oneshot_mods()); - } else if (tap_count == 1) { - dprint("MODS_TAP: Oneshot: start\n"); - set_oneshot_mods(mods | get_oneshot_mods()); -# if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 - } else if (tap_count == ONESHOT_TAP_TOGGLE) { - dprint("MODS_TAP: Toggling oneshot"); - clear_oneshot_mods(); - set_oneshot_locked_mods(mods); - register_mods(mods); -# endif + if (keymap_config.oneshot_disable) { + if (event.pressed) { + if (mods) { + if (IS_MOD(action.key.code) || action.key.code == KC_NO) { + // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless. + // This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT). + // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO). + add_mods(mods); + } else { + add_weak_mods(mods); + } + send_keyboard_report(); + } + register_code(action.key.code); } else { - register_mods(mods | get_oneshot_mods()); + unregister_code(action.key.code); + if (mods) { + if (IS_MOD(action.key.code) || action.key.code == KC_NO) { + del_mods(mods); + } else { + del_weak_mods(mods); + } + send_keyboard_report(); + } } } else { - if (tap_count == 0) { - clear_oneshot_mods(); - unregister_mods(mods); - } else if (tap_count == 1) { - // Retain Oneshot mods + if (event.pressed) { + if (tap_count == 0) { + dprint("MODS_TAP: Oneshot: 0\n"); + register_mods(mods | get_oneshot_mods()); + } else if (tap_count == 1) { + dprint("MODS_TAP: Oneshot: start\n"); + set_oneshot_mods(mods | get_oneshot_mods()); # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 - if (mods & get_mods()) { - clear_oneshot_locked_mods(); + } else if (tap_count == ONESHOT_TAP_TOGGLE) { + dprint("MODS_TAP: Toggling oneshot"); clear_oneshot_mods(); - unregister_mods(mods); - } - } else if (tap_count == ONESHOT_TAP_TOGGLE) { - // Toggle Oneshot Layer + set_oneshot_locked_mods(mods); + register_mods(mods); # endif + } else { + register_mods(mods | get_oneshot_mods()); + } } else { - clear_oneshot_mods(); - unregister_mods(mods); + if (tap_count == 0) { + clear_oneshot_mods(); + unregister_mods(mods); + } else if (tap_count == 1) { + // Retain Oneshot mods +# if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 + if (mods & get_mods()) { + clear_oneshot_locked_mods(); + clear_oneshot_mods(); + unregister_mods(mods); + } + } else if (tap_count == ONESHOT_TAP_TOGGLE) { + // Toggle Oneshot Layer +# endif + } else { + clear_oneshot_mods(); + unregister_mods(mods); + } } } break; @@ -523,39 +555,47 @@ void process_action(keyrecord_t *record, action_t action) { # ifndef NO_ACTION_ONESHOT case OP_ONESHOT: // Oneshot modifier -# if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 - do_release_oneshot = false; - if (event.pressed) { - del_mods(get_oneshot_locked_mods()); - if (get_oneshot_layer_state() == ONESHOT_TOGGLED) { - reset_oneshot_layer(); - layer_off(action.layer_tap.val); - break; - } else if (tap_count < ONESHOT_TAP_TOGGLE) { + if (keymap_config.oneshot_disable) { + if (event.pressed) { layer_on(action.layer_tap.val); - set_oneshot_layer(action.layer_tap.val, ONESHOT_START); + } else { + layer_off(action.layer_tap.val); } } else { - add_mods(get_oneshot_locked_mods()); - if (tap_count >= ONESHOT_TAP_TOGGLE) { - reset_oneshot_layer(); - clear_oneshot_locked_mods(); - set_oneshot_layer(action.layer_tap.val, ONESHOT_TOGGLED); +# if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 + do_release_oneshot = false; + if (event.pressed) { + del_mods(get_oneshot_locked_mods()); + if (get_oneshot_layer_state() == ONESHOT_TOGGLED) { + reset_oneshot_layer(); + layer_off(action.layer_tap.val); + break; + } else if (tap_count < ONESHOT_TAP_TOGGLE) { + layer_on(action.layer_tap.val); + set_oneshot_layer(action.layer_tap.val, ONESHOT_START); + } } else { - clear_oneshot_layer_state(ONESHOT_PRESSED); + add_mods(get_oneshot_locked_mods()); + if (tap_count >= ONESHOT_TAP_TOGGLE) { + reset_oneshot_layer(); + clear_oneshot_locked_mods(); + set_oneshot_layer(action.layer_tap.val, ONESHOT_TOGGLED); + } else { + clear_oneshot_layer_state(ONESHOT_PRESSED); + } } - } # else - if (event.pressed) { - layer_on(action.layer_tap.val); - set_oneshot_layer(action.layer_tap.val, ONESHOT_START); - } else { - clear_oneshot_layer_state(ONESHOT_PRESSED); - if (tap_count > 1) { - clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); + if (event.pressed) { + layer_on(action.layer_tap.val); + set_oneshot_layer(action.layer_tap.val, ONESHOT_START); + } else { + clear_oneshot_layer_state(ONESHOT_PRESSED); + if (tap_count > 1) { + clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); + } } - } # endif + } break; # endif default: diff --git a/quantum/action_util.c b/quantum/action_util.c index 9a85bd504069..78e02aec185f 100644 --- a/quantum/action_util.c +++ b/quantum/action_util.c @@ -170,7 +170,7 @@ void reset_oneshot_layer(void) { void clear_oneshot_layer_state(oneshot_fullfillment_t state) { uint8_t start_state = oneshot_layer_data; oneshot_layer_data &= ~state; - if ((!get_oneshot_layer_state() && start_state != oneshot_layer_data) || keymap_config.oneshot_disable) { + if ((!get_oneshot_layer_state() && start_state != oneshot_layer_data) && !keymap_config.oneshot_disable) { layer_off(get_oneshot_layer()); reset_oneshot_layer(); } @@ -189,6 +189,7 @@ void oneshot_set(bool active) { if (keymap_config.oneshot_disable != active) { keymap_config.oneshot_disable = active; eeconfig_update_keymap(keymap_config.raw); + clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); dprintf("Oneshot: active: %d\n", active); } } diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index 51b0efdb47c1..032db74fea20 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -76,9 +76,6 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record) autoshift_time = now; autoshift_flags.in_progress = true; -# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) - clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); -# endif return false; } From 10d6515ed9edae4a94886e4c622203ee8ea98e58 Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Sun, 24 Oct 2021 11:04:40 -0700 Subject: [PATCH 2/3] fix formatting --- quantum/action.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/quantum/action.c b/quantum/action.c index 92ca28c0cef8..b3794dadbe88 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -91,16 +91,16 @@ void action_exec(keyevent_t event) { #ifndef NO_ACTION_ONESHOT if (!keymap_config.oneshot_disable) { # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) - if (has_oneshot_layer_timed_out()) { - clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); - } - if (has_oneshot_mods_timed_out()) { - clear_oneshot_mods(); - } + if (has_oneshot_layer_timed_out()) { + clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); + } + if (has_oneshot_mods_timed_out()) { + clear_oneshot_mods(); + } # ifdef SWAP_HANDS_ENABLE - if (has_oneshot_swaphands_timed_out()) { - clear_oneshot_swaphands(); - } + if (has_oneshot_swaphands_timed_out()) { + clear_oneshot_swaphands(); + } # endif # endif } @@ -264,8 +264,7 @@ void process_action(keyrecord_t *record, action_t action) { # ifdef SWAP_HANDS_ENABLE && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT) # endif - && !keymap_config.oneshot_disable - ) { + && !keymap_config.oneshot_disable) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); do_release_oneshot = !is_oneshot_layer_active(); } From 006284fc154d5ea14260f7871c434f0e8eb7866a Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Mon, 1 Nov 2021 09:39:38 -0700 Subject: [PATCH 3/3] Minor cleanup --- quantum/action.c | 1 - quantum/process_keycode/process_auto_shift.c | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/quantum/action.c b/quantum/action.c index b3794dadbe88..8c34b84ef1ec 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -27,7 +27,6 @@ along with this program. If not, see . #include "action_util.h" #include "action.h" #include "wait.h" - #include "keycode_config.h" #ifdef BACKLIGHT_ENABLE diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index 032db74fea20..51b0efdb47c1 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -76,6 +76,9 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record) autoshift_time = now; autoshift_flags.in_progress = true; +# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING) + clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); +# endif return false; }