From b8574efcd67a394c423ac29ce280ee09517a1aee Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sun, 13 Mar 2022 18:11:42 -0700 Subject: [PATCH] Fix oneshot toggle logic (#16630) * Fix oneshot toggle logic * Enable oneshots by default * Decrement eeconfig magic number due to eeconfig changes --- quantum/action.c | 10 +++++----- quantum/action_util.c | 15 +++++++-------- quantum/eeconfig.c | 2 +- quantum/eeconfig.h | 2 +- quantum/keycode_config.h | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/quantum/action.c b/quantum/action.c index 60301fa6065..ef059f0e2a9 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -101,7 +101,7 @@ void action_exec(keyevent_t event) { keyrecord_t record = {.event = event}; #ifndef NO_ACTION_ONESHOT - if (!keymap_config.oneshot_disable) { + if (keymap_config.oneshot_enable) { # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) if (has_oneshot_layer_timed_out()) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); @@ -258,7 +258,7 @@ void process_record(keyrecord_t *record) { if (!process_record_quantum(record)) { #ifndef NO_ACTION_ONESHOT - if (is_oneshot_layer_active() && record->event.pressed && !keymap_config.oneshot_disable) { + if (is_oneshot_layer_active() && record->event.pressed && keymap_config.oneshot_enable) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); } #endif @@ -323,7 +323,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_enable) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); do_release_oneshot = !is_oneshot_layer_active(); } @@ -367,7 +367,7 @@ void process_action(keyrecord_t *record, action_t action) { # ifndef NO_ACTION_ONESHOT case MODS_ONESHOT: // Oneshot modifier - if (keymap_config.oneshot_disable) { + if (!keymap_config.oneshot_enable) { if (event.pressed) { if (mods) { if (IS_MOD(action.key.code) || action.key.code == KC_NO) { @@ -613,7 +613,7 @@ void process_action(keyrecord_t *record, action_t action) { # ifndef NO_ACTION_ONESHOT case OP_ONESHOT: // Oneshot modifier - if (keymap_config.oneshot_disable) { + if (!keymap_config.oneshot_enable) { if (event.pressed) { layer_on(action.layer_tap.val); } else { diff --git a/quantum/action_util.c b/quantum/action_util.c index cf81370d4a8..738410a4ace 100644 --- a/quantum/action_util.c +++ b/quantum/action_util.c @@ -155,7 +155,7 @@ void clear_oneshot_swaphands(void) { * FIXME: needs doc */ void set_oneshot_layer(uint8_t layer, uint8_t state) { - if (!keymap_config.oneshot_disable) { + if (keymap_config.oneshot_enable) { oneshot_layer_data = layer << 3 | state; layer_on(layer); # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) @@ -184,7 +184,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_enable) { layer_off(get_oneshot_layer()); reset_oneshot_layer(); } @@ -202,9 +202,8 @@ bool is_oneshot_layer_active(void) { * FIXME: needs doc */ void oneshot_set(bool active) { - const bool disable = !active; - if (keymap_config.oneshot_disable != disable) { - keymap_config.oneshot_disable = disable; + if (keymap_config.oneshot_enable != active) { + keymap_config.oneshot_enable = active; eeconfig_update_keymap(keymap_config.raw); clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); dprintf("Oneshot: active: %d\n", active); @@ -216,7 +215,7 @@ void oneshot_set(bool active) { * FIXME: needs doc */ void oneshot_toggle(void) { - oneshot_set(!keymap_config.oneshot_disable); + oneshot_set(!keymap_config.oneshot_enable); } /** \brief enable oneshot @@ -236,7 +235,7 @@ void oneshot_disable(void) { } bool is_oneshot_enabled(void) { - return !keymap_config.oneshot_disable; + return keymap_config.oneshot_enable; } #endif @@ -414,7 +413,7 @@ void del_oneshot_mods(uint8_t mods) { * FIXME: needs doc */ void set_oneshot_mods(uint8_t mods) { - if (!keymap_config.oneshot_disable) { + if (keymap_config.oneshot_enable) { if (oneshot_mods != mods) { # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) oneshot_time = timer_read(); diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c index 14cd5887f44..0ff9996ca41 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c @@ -46,7 +46,7 @@ void eeconfig_init_quantum(void) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); default_layer_state = 0; eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0); - eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0); + eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0x4); eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0); eeprom_update_byte(EECONFIG_BACKLIGHT, 0); eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default diff --git a/quantum/eeconfig.h b/quantum/eeconfig.h index f3cd1867ab4..565a0dbe5b9 100644 --- a/quantum/eeconfig.h +++ b/quantum/eeconfig.h @@ -21,7 +21,7 @@ along with this program. If not, see . #include #ifndef EECONFIG_MAGIC_NUMBER -# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE9 // When changing, decrement this value to avoid future re-init issues +# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE8 // When changing, decrement this value to avoid future re-init issues #endif #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h index d7e334fdc8f..a2cb025ed2d 100644 --- a/quantum/keycode_config.h +++ b/quantum/keycode_config.h @@ -37,7 +37,7 @@ typedef union { bool nkro : 1; bool swap_lctl_lgui : 1; bool swap_rctl_rgui : 1; - bool oneshot_disable : 1; + bool oneshot_enable : 1; }; } keymap_config_t;