Fix oneshot toggle logic (#16630)

* Fix oneshot toggle logic

* Enable oneshots by default

* Decrement eeconfig magic number due to eeconfig changes
This commit is contained in:
Drashna Jaelre 2022-03-13 18:11:42 -07:00 committed by GitHub
parent 42d084d1c0
commit b8574efcd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 16 deletions

View file

@ -101,7 +101,7 @@ 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 (keymap_config.oneshot_enable) {
# 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);
@ -258,7 +258,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 && !keymap_config.oneshot_disable) { if (is_oneshot_layer_active() && record->event.pressed && keymap_config.oneshot_enable) {
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
} }
#endif #endif
@ -323,7 +323,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) { && keymap_config.oneshot_enable) {
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();
} }
@ -367,7 +367,7 @@ 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 (keymap_config.oneshot_disable) { if (!keymap_config.oneshot_enable) {
if (event.pressed) { if (event.pressed) {
if (mods) { if (mods) {
if (IS_MOD(action.key.code) || action.key.code == KC_NO) { 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 # ifndef NO_ACTION_ONESHOT
case OP_ONESHOT: case OP_ONESHOT:
// Oneshot modifier // Oneshot modifier
if (keymap_config.oneshot_disable) { if (!keymap_config.oneshot_enable) {
if (event.pressed) { if (event.pressed) {
layer_on(action.layer_tap.val); layer_on(action.layer_tap.val);
} else { } else {

View file

@ -155,7 +155,7 @@ void clear_oneshot_swaphands(void) {
* FIXME: needs doc * FIXME: needs doc
*/ */
void set_oneshot_layer(uint8_t layer, uint8_t state) { 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; oneshot_layer_data = layer << 3 | state;
layer_on(layer); layer_on(layer);
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) # 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) { 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_enable) {
layer_off(get_oneshot_layer()); layer_off(get_oneshot_layer());
reset_oneshot_layer(); reset_oneshot_layer();
} }
@ -202,9 +202,8 @@ bool is_oneshot_layer_active(void) {
* FIXME: needs doc * FIXME: needs doc
*/ */
void oneshot_set(bool active) { void oneshot_set(bool active) {
const bool disable = !active; if (keymap_config.oneshot_enable != active) {
if (keymap_config.oneshot_disable != disable) { keymap_config.oneshot_enable = active;
keymap_config.oneshot_disable = disable;
eeconfig_update_keymap(keymap_config.raw); eeconfig_update_keymap(keymap_config.raw);
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
dprintf("Oneshot: active: %d\n", active); dprintf("Oneshot: active: %d\n", active);
@ -216,7 +215,7 @@ void oneshot_set(bool active) {
* FIXME: needs doc * FIXME: needs doc
*/ */
void oneshot_toggle(void) { void oneshot_toggle(void) {
oneshot_set(!keymap_config.oneshot_disable); oneshot_set(!keymap_config.oneshot_enable);
} }
/** \brief enable oneshot /** \brief enable oneshot
@ -236,7 +235,7 @@ void oneshot_disable(void) {
} }
bool is_oneshot_enabled(void) { bool is_oneshot_enabled(void) {
return !keymap_config.oneshot_disable; return keymap_config.oneshot_enable;
} }
#endif #endif
@ -414,7 +413,7 @@ void del_oneshot_mods(uint8_t mods) {
* FIXME: needs doc * FIXME: needs doc
*/ */
void set_oneshot_mods(uint8_t mods) { void set_oneshot_mods(uint8_t mods) {
if (!keymap_config.oneshot_disable) { if (keymap_config.oneshot_enable) {
if (oneshot_mods != mods) { if (oneshot_mods != mods) {
# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
oneshot_time = timer_read(); oneshot_time = timer_read();

View file

@ -46,7 +46,7 @@ void eeconfig_init_quantum(void) {
eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
default_layer_state = 0; default_layer_state = 0;
eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 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_MOUSEKEY_ACCEL, 0);
eeprom_update_byte(EECONFIG_BACKLIGHT, 0); eeprom_update_byte(EECONFIG_BACKLIGHT, 0);
eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default

View file

@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdbool.h> #include <stdbool.h>
#ifndef EECONFIG_MAGIC_NUMBER #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 #endif
#define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF #define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF

View file

@ -37,7 +37,7 @@ typedef union {
bool nkro : 1; bool nkro : 1;
bool swap_lctl_lgui : 1; bool swap_lctl_lgui : 1;
bool swap_rctl_rgui : 1; bool swap_rctl_rgui : 1;
bool oneshot_disable : 1; bool oneshot_enable : 1;
}; };
} keymap_config_t; } keymap_config_t;