Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix oneshot toggle logic #16630

Merged
merged 3 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions quantum/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 7 additions & 8 deletions quantum/action_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -236,7 +235,7 @@ void oneshot_disable(void) {
}

bool is_oneshot_enabled(void) {
return !keymap_config.oneshot_disable;
return keymap_config.oneshot_enable;
}

#endif
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion quantum/eeconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion quantum/eeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdbool.h>

#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

Expand Down
2 changes: 1 addition & 1 deletion quantum/keycode_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
fauxpark marked this conversation as resolved.
Show resolved Hide resolved
};
} keymap_config_t;

Expand Down