Fix issues with Oneshot disabling (#14934)

master
Drashna Jaelre 2021-11-01 09:41:24 -07:00 committed by GitHub
parent f7e94f6624
commit 2980c63d3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 105 additions and 66 deletions

View File

@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "action_util.h" #include "action_util.h"
#include "action.h" #include "action.h"
#include "wait.h" #include "wait.h"
#include "keycode_config.h"
#ifdef BACKLIGHT_ENABLE #ifdef BACKLIGHT_ENABLE
# include "backlight.h" # include "backlight.h"
@ -87,19 +88,21 @@ void action_exec(keyevent_t event) {
keyrecord_t record = {.event = event}; keyrecord_t record = {.event = event};
#ifndef NO_ACTION_ONESHOT #ifndef NO_ACTION_ONESHOT
if (!keymap_config.oneshot_disable) {
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
if (has_oneshot_layer_timed_out()) { if (has_oneshot_layer_timed_out()) {
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
} }
if (has_oneshot_mods_timed_out()) { if (has_oneshot_mods_timed_out()) {
clear_oneshot_mods(); clear_oneshot_mods();
} }
# ifdef SWAP_HANDS_ENABLE # ifdef SWAP_HANDS_ENABLE
if (has_oneshot_swaphands_timed_out()) { if (has_oneshot_swaphands_timed_out()) {
clear_oneshot_swaphands(); clear_oneshot_swaphands();
} }
# endif # endif
# endif # endif
}
#endif #endif
#ifndef NO_ACTION_TAPPING #ifndef NO_ACTION_TAPPING
@ -195,7 +198,7 @@ void process_record(keyrecord_t *record) {
if (!process_record_quantum(record)) { if (!process_record_quantum(record)) {
#ifndef NO_ACTION_ONESHOT #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); clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
} }
#endif #endif
@ -260,7 +263,7 @@ void process_action(keyrecord_t *record, action_t action) {
# ifdef SWAP_HANDS_ENABLE # ifdef SWAP_HANDS_ENABLE
&& !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT) && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT)
# endif # endif
) { && !keymap_config.oneshot_disable) {
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
do_release_oneshot = !is_oneshot_layer_active(); do_release_oneshot = !is_oneshot_layer_active();
} }
@ -304,41 +307,68 @@ void process_action(keyrecord_t *record, action_t action) {
# ifndef NO_ACTION_ONESHOT # ifndef NO_ACTION_ONESHOT
case MODS_ONESHOT: case MODS_ONESHOT:
// Oneshot modifier // Oneshot modifier
if (event.pressed) { if (keymap_config.oneshot_disable) {
if (tap_count == 0) { if (event.pressed) {
dprint("MODS_TAP: Oneshot: 0\n"); if (mods) {
register_mods(mods | get_oneshot_mods()); if (IS_MOD(action.key.code) || action.key.code == KC_NO) {
} else if (tap_count == 1) { // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless.
dprint("MODS_TAP: Oneshot: start\n"); // This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT).
set_oneshot_mods(mods | get_oneshot_mods()); // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO).
# if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 add_mods(mods);
} else if (tap_count == ONESHOT_TAP_TOGGLE) { } else {
dprint("MODS_TAP: Toggling oneshot"); add_weak_mods(mods);
clear_oneshot_mods(); }
set_oneshot_locked_mods(mods); send_keyboard_report();
register_mods(mods); }
# endif register_code(action.key.code);
} else { } 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 { } else {
if (tap_count == 0) { if (event.pressed) {
clear_oneshot_mods(); if (tap_count == 0) {
unregister_mods(mods); dprint("MODS_TAP: Oneshot: 0\n");
} else if (tap_count == 1) { register_mods(mods | get_oneshot_mods());
// Retain 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 defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
if (mods & get_mods()) { } else if (tap_count == ONESHOT_TAP_TOGGLE) {
clear_oneshot_locked_mods(); dprint("MODS_TAP: Toggling oneshot");
clear_oneshot_mods();
set_oneshot_locked_mods(mods);
register_mods(mods);
# endif
} else {
register_mods(mods | get_oneshot_mods());
}
} else {
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(); clear_oneshot_mods();
unregister_mods(mods); unregister_mods(mods);
} }
} else if (tap_count == ONESHOT_TAP_TOGGLE) {
// Toggle Oneshot Layer
# endif
} else {
clear_oneshot_mods();
unregister_mods(mods);
} }
} }
break; break;
@ -523,39 +553,47 @@ void process_action(keyrecord_t *record, action_t action) {
# ifndef NO_ACTION_ONESHOT # ifndef NO_ACTION_ONESHOT
case OP_ONESHOT: case OP_ONESHOT:
// Oneshot modifier // Oneshot modifier
# if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 if (keymap_config.oneshot_disable) {
do_release_oneshot = false; if (event.pressed) {
if (event.pressed) { layer_on(action.layer_tap.val);
del_mods(get_oneshot_locked_mods()); } else {
if (get_oneshot_layer_state() == ONESHOT_TOGGLED) {
reset_oneshot_layer();
layer_off(action.layer_tap.val); layer_off(action.layer_tap.val);
break; }
} else if (tap_count < ONESHOT_TAP_TOGGLE) { } else {
# 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 {
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); layer_on(action.layer_tap.val);
set_oneshot_layer(action.layer_tap.val, ONESHOT_START); set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
}
} 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);
} else { } else {
clear_oneshot_layer_state(ONESHOT_PRESSED); clear_oneshot_layer_state(ONESHOT_PRESSED);
if (tap_count > 1) {
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_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);
}
}
# endif # endif
}
break; break;
# endif # endif
default: default:

View File

@ -170,7 +170,7 @@ void reset_oneshot_layer(void) {
void clear_oneshot_layer_state(oneshot_fullfillment_t state) { void clear_oneshot_layer_state(oneshot_fullfillment_t state) {
uint8_t start_state = oneshot_layer_data; uint8_t start_state = oneshot_layer_data;
oneshot_layer_data &= ~state; 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()); layer_off(get_oneshot_layer());
reset_oneshot_layer(); reset_oneshot_layer();
} }
@ -189,6 +189,7 @@ void oneshot_set(bool active) {
if (keymap_config.oneshot_disable != active) { if (keymap_config.oneshot_disable != active) {
keymap_config.oneshot_disable = active; keymap_config.oneshot_disable = active;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(keymap_config.raw);
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
dprintf("Oneshot: active: %d\n", active); dprintf("Oneshot: active: %d\n", active);
} }
} }